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

Method TestNewServer_Success

xds/server_test.go:109–165  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

107}
108
109func (s) TestNewServer_Success(t *testing.T) {
110 xdsCreds, err := xds.NewServerCredentials(xds.ServerOptions{FallbackCreds: insecure.NewCredentials()})
111 if err != nil {
112 t.Fatalf("failed to create xds server credentials: %v", err)
113 }
114
115 tests := []struct {
116 desc string
117 serverOpts []grpc.ServerOption
118 wantXDSCredsInUse bool
119 }{
120 {
121 desc: "without_xds_creds",
122 serverOpts: []grpc.ServerOption{
123 grpc.Creds(insecure.NewCredentials()),
124 BootstrapContentsForTesting(generateBootstrapContents(t, uuid.NewString(), nonExistentManagementServer)),
125 },
126 },
127 {
128 desc: "with_xds_creds",
129 serverOpts: []grpc.ServerOption{
130 grpc.Creds(xdsCreds),
131 BootstrapContentsForTesting(generateBootstrapContents(t, uuid.NewString(), nonExistentManagementServer)),
132 },
133 wantXDSCredsInUse: true,
134 },
135 }
136
137 for _, test := range tests {
138 t.Run(test.desc, func(t *testing.T) {
139 // The xds package adds a couple of server options (unary and stream
140 // interceptors) to the server options passed in by the user.
141 wantServerOpts := len(test.serverOpts) + 2
142
143 origNewGRPCServer := newGRPCServer
144 newGRPCServer = func(opts ...grpc.ServerOption) grpcServer {
145 if got := len(opts); got != wantServerOpts {
146 t.Fatalf("%d ServerOptions passed to grpc.Server, want %d", got, wantServerOpts)
147 }
148 // Verify that the user passed ServerOptions are forwarded as is.
149 if !reflect.DeepEqual(opts[2:], test.serverOpts) {
150 t.Fatalf("got ServerOptions %v, want %v", opts[2:], test.serverOpts)
151 }
152 return grpc.NewServer(opts...)
153 }
154 defer func() {
155 newGRPCServer = origNewGRPCServer
156 }()
157
158 s, err := NewGRPCServer(test.serverOpts...)
159 if err != nil {
160 t.Fatalf("Failed to create an xDS enabled gRPC server: %v", err)
161 }
162 defer s.Stop()
163 })
164 }
165}
166

Callers

nothing calls this directly

Calls 9

NewServerCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
CredsFunction · 0.92
NewServerFunction · 0.92
NewGRPCServerFunction · 0.85
FatalfMethod · 0.65
StopMethod · 0.65

Tested by

no test coverage detected