(t *testing.T, e env)
| 182 | } |
| 183 | |
| 184 | func testPickExtraMetadata(t *testing.T, e env) { |
| 185 | te := newTest(t, e) |
| 186 | b := &testBalancer{} |
| 187 | balancer.Register(b) |
| 188 | const ( |
| 189 | testUserAgent = "test-user-agent" |
| 190 | testSubContentType = "proto" |
| 191 | ) |
| 192 | |
| 193 | te.customDialOptions = []grpc.DialOption{ |
| 194 | grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"loadBalancingConfig": [{"%s":{}}]}`, testBalancerName)), |
| 195 | grpc.WithUserAgent(testUserAgent), |
| 196 | } |
| 197 | te.startServer(&testServer{security: e.security}) |
| 198 | defer te.tearDown() |
| 199 | |
| 200 | // Trigger the extra-metadata-adding code path. |
| 201 | defer func(old string) { internal.GRPCResolverSchemeExtraMetadata = old }(internal.GRPCResolverSchemeExtraMetadata) |
| 202 | internal.GRPCResolverSchemeExtraMetadata = "passthrough" |
| 203 | |
| 204 | cc := te.clientConn() |
| 205 | tc := testgrpc.NewTestServiceClient(cc) |
| 206 | |
| 207 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 208 | defer cancel() |
| 209 | if _, err := tc.EmptyCall(ctx, &testpb.Empty{}, grpc.WaitForReady(true)); err != nil { |
| 210 | t.Fatalf("TestService/EmptyCall(_, _) = _, %v, want _, %v", err, nil) |
| 211 | } |
| 212 | if _, err := tc.EmptyCall(ctx, &testpb.Empty{}, grpc.CallContentSubtype(testSubContentType)); err != nil { |
| 213 | t.Fatalf("TestService/EmptyCall(_, _) = _, %v, want _, %v", err, nil) |
| 214 | } |
| 215 | |
| 216 | want := []metadata.MD{ |
| 217 | // First RPC doesn't have sub-content-type. |
| 218 | {"content-type": []string{"application/grpc"}}, |
| 219 | // Second RPC has sub-content-type "proto". |
| 220 | {"content-type": []string{"application/grpc+proto"}}, |
| 221 | } |
| 222 | if diff := cmp.Diff(want, b.pickExtraMDs); diff != "" { |
| 223 | t.Fatalf("unexpected diff in metadata (-want, +got): %s", diff) |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | func (s) TestDoneInfo(t *testing.T) { |
| 228 | for _, e := range listTestEnv() { |
no test coverage detected