MCPcopy
hub / github.com/grpc/grpc-go / RunRegisterTests

Function RunRegisterTests

admin/test/utils.go:54–86  ·  view source on GitHub ↗

RunRegisterTests makes a client, runs the RPCs, and compares the status codes.

(t *testing.T, ec ExpectedStatusCodes)

Source from the content-addressed store, hash-verified

52// RunRegisterTests makes a client, runs the RPCs, and compares the status
53// codes.
54func RunRegisterTests(t *testing.T, ec ExpectedStatusCodes) {
55 lis, err := net.Listen("tcp", "localhost:0")
56 if err != nil {
57 t.Fatalf("cannot create listener: %v", err)
58 }
59
60 server := grpc.NewServer()
61 defer server.Stop()
62 cleanup, err := admin.Register(server)
63 if err != nil {
64 t.Fatalf("failed to register admin: %v", err)
65 }
66 defer cleanup()
67 go func() {
68 server.Serve(lis)
69 }()
70
71 conn, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
72 if err != nil {
73 t.Fatalf("grpc.NewClient(%q) = %v", lis.Addr().String(), err)
74 }
75
76 t.Run("channelz", func(t *testing.T) {
77 if err := RunChannelz(conn); status.Code(err) != ec.ChannelzCode {
78 t.Fatalf("%s RPC failed with error %v, want code %v", "channelz", err, ec.ChannelzCode)
79 }
80 })
81 t.Run("csds", func(t *testing.T) {
82 if err := RunCSDS(conn); status.Code(err) != ec.CSDSCode {
83 t.Fatalf("%s RPC failed with error %v, want code %v", "CSDS", err, ec.CSDSCode)
84 }
85 })
86}
87
88// RunChannelz makes a channelz RPC.
89func RunChannelz(conn *grpc.ClientConn) error {

Callers 2

TestRegisterNoCSDSFunction · 0.92
TestRegisterWithCSDSFunction · 0.92

Calls 13

StopMethod · 0.95
ServeMethod · 0.95
NewServerFunction · 0.92
RegisterFunction · 0.92
NewClientFunction · 0.92
WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
CodeFunction · 0.92
RunChannelzFunction · 0.85
RunCSDSFunction · 0.85
FatalfMethod · 0.65
StringMethod · 0.65

Tested by 2

TestRegisterNoCSDSFunction · 0.74
TestRegisterWithCSDSFunction · 0.74