TestColonPortAuthority does an end to end test with the target for grpc.NewClient being ":[port]". Ensures authority is "localhost:[port]".
(t *testing.T)
| 168 | // TestColonPortAuthority does an end to end test with the target for grpc.NewClient |
| 169 | // being ":[port]". Ensures authority is "localhost:[port]". |
| 170 | func (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 |
nothing calls this directly
no test coverage detected