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

Function testPickExtraMetadata

test/balancer_test.go:184–225  ·  view source on GitHub ↗
(t *testing.T, e env)

Source from the content-addressed store, hash-verified

182}
183
184func 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
227func (s) TestDoneInfo(t *testing.T) {
228 for _, e := range listTestEnv() {

Callers 1

TestPickExtraMetadataMethod · 0.85

Calls 11

EmptyCallMethod · 0.95
RegisterFunction · 0.92
WithDefaultServiceConfigFunction · 0.92
WithUserAgentFunction · 0.92
WaitForReadyFunction · 0.92
CallContentSubtypeFunction · 0.92
newTestFunction · 0.70
FatalfMethod · 0.65
startServerMethod · 0.45
tearDownMethod · 0.45
clientConnMethod · 0.45

Tested by

no test coverage detected