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

Method TestColonPortAuthority

test/authority_test.go:170–205  ·  view source on GitHub ↗

TestColonPortAuthority does an end to end test with the target for grpc.NewClient being ":[port]". Ensures authority is "localhost:[port]".

(t *testing.T)

Source from the content-addressed store, hash-verified

168// TestColonPortAuthority does an end to end test with the target for grpc.NewClient
169// being ":[port]". Ensures authority is "localhost:[port]".
170func (s) TestColonPortAuthority(t *testing.T) {
171 expectedAuthority := ""
172 var authorityMu sync.Mutex
173 ss := &stubserver.StubServer{
174 EmptyCallF: func(ctx context.Context, _ *testpb.Empty) (*testpb.Empty, error) {
175 authorityMu.Lock()
176 defer authorityMu.Unlock()
177 return authorityChecker(ctx, expectedAuthority)
178 },
179 Network: "tcp",
180 }
181 if err := ss.Start(nil); err != nil {
182 t.Fatalf("Error starting endpoint server: %v", err)
183 }
184 defer ss.Stop()
185 _, port, err := net.SplitHostPort(ss.Address)
186 if err != nil {
187 t.Fatalf("Failed splitting host from post: %v", err)
188 }
189 authorityMu.Lock()
190 expectedAuthority = "localhost:" + port
191 authorityMu.Unlock()
192 // ss.Start dials the server, but we explicitly test with ":[port]"
193 // as the target.
194 cc, err := grpc.NewClient(":"+port, grpc.WithTransportCredentials(insecure.NewCredentials()))
195 if err != nil {
196 t.Fatalf("grpc.NewClient(%q) = %v", ss.Target, err)
197 }
198 defer cc.Close()
199 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
200 defer cancel()
201 _, err = testgrpc.NewTestServiceClient(cc).EmptyCall(ctx, &testpb.Empty{})
202 if err != nil {
203 t.Errorf("us.client.EmptyCall(_, _) = _, %v; want _, nil", err)
204 }
205}
206
207// TestAuthorityReplacedWithResolverAddress tests the scenario where the resolver
208// returned address contains a ServerName override. The test verifies that the

Callers

nothing calls this directly

Calls 12

StartMethod · 0.95
StopMethod · 0.95
NewClientFunction · 0.92
WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
authorityCheckerFunction · 0.70
FatalfMethod · 0.65
CloseMethod · 0.65
EmptyCallMethod · 0.65
ErrorfMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected