MCPcopy
hub / github.com/micro/go-micro / TestGRPCClient

Function TestGRPCClient

client/grpc/grpc_test.go:29–112  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

27}
28
29func TestGRPCClient(t *testing.T) {
30 l, err := net.Listen("tcp", ":0")
31 if err != nil {
32 t.Fatalf("failed to listen: %v", err)
33 }
34 defer l.Close()
35
36 s := pgrpc.NewServer()
37 pb.RegisterGreeterServer(s, &greeterServer{})
38
39 go s.Serve(l)
40 defer s.Stop()
41
42 // create mock registry
43 r := registry.NewMemoryRegistry()
44
45 // register service
46 r.Register(&registry.Service{
47 Name: "helloworld",
48 Version: "test",
49 Nodes: []*registry.Node{
50 {
51 Id: "test-1",
52 Address: l.Addr().String(),
53 Metadata: map[string]string{
54 "protocol": "grpc",
55 },
56 },
57 },
58 })
59
60 // create selector
61 se := selector.NewSelector(
62 selector.Registry(r),
63 )
64
65 // create client
66 c := NewClient(
67 client.Registry(r),
68 client.Selector(se),
69 )
70
71 testMethods := []string{
72 "/helloworld.Greeter/SayHello",
73 "Greeter.SayHello",
74 }
75
76 for _, method := range testMethods {
77 req := c.NewRequest("helloworld", method, &pb.HelloRequest{
78 Name: "John",
79 })
80
81 rsp := pb.HelloReply{}
82
83 err = c.Call(context.TODO(), req, &rsp)
84 if err != nil {
85 t.Fatal(err)
86 }

Callers

nothing calls this directly

Calls 15

StopMethod · 0.95
NewRequestMethod · 0.95
CallMethod · 0.95
NewMemoryRegistryFunction · 0.92
NewSelectorFunction · 0.92
RegistryFunction · 0.92
RegistryFunction · 0.92
SelectorFunction · 0.92
ServeMethod · 0.80
FatalMethod · 0.80
NewClientFunction · 0.70
ListenMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…