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

Method TestAuthorityReplacedWithResolverAddress

test/authority_test.go:211–237  ·  view source on GitHub ↗

TestAuthorityReplacedWithResolverAddress tests the scenario where the resolver returned address contains a ServerName override. The test verifies that the :authority header value sent to the server as part of the http/2 HEADERS frame is set to the value specified in the resolver returned address.

(t *testing.T)

Source from the content-addressed store, hash-verified

209// :authority header value sent to the server as part of the http/2 HEADERS frame
210// is set to the value specified in the resolver returned address.
211func (s) TestAuthorityReplacedWithResolverAddress(t *testing.T) {
212 const expectedAuthority = "test.server.name"
213
214 ss := &stubserver.StubServer{
215 EmptyCallF: func(ctx context.Context, _ *testpb.Empty) (*testpb.Empty, error) {
216 return authorityChecker(ctx, expectedAuthority)
217 },
218 }
219 if err := ss.Start(nil); err != nil {
220 t.Fatalf("Error starting endpoint server: %v", err)
221 }
222 defer ss.Stop()
223
224 r := manual.NewBuilderWithScheme("whatever")
225 r.InitialState(resolver.State{Addresses: []resolver.Address{{Addr: ss.Address, ServerName: expectedAuthority}}})
226 cc, err := grpc.NewClient(r.Scheme()+":///whatever", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(r))
227 if err != nil {
228 t.Fatalf("grpc.NewClient(%q) = %v", ss.Address, err)
229 }
230 defer cc.Close()
231
232 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
233 defer cancel()
234 if _, err = testgrpc.NewTestServiceClient(cc).EmptyCall(ctx, &testpb.Empty{}); err != nil {
235 t.Fatalf("EmptyCall() rpc failed: %v", err)
236 }
237}

Callers

nothing calls this directly

Calls 13

StartMethod · 0.95
StopMethod · 0.95
NewBuilderWithSchemeFunction · 0.92
NewClientFunction · 0.92
WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
WithResolversFunction · 0.92
InitialStateMethod · 0.80
authorityCheckerFunction · 0.70
FatalfMethod · 0.65
SchemeMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected