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

Function testPerRPCCredentialsViaDialOptionsAndCallOptions

test/creds_test.go:375–409  ·  view source on GitHub ↗
(t *testing.T, e env)

Source from the content-addressed store, hash-verified

373}
374
375func testPerRPCCredentialsViaDialOptionsAndCallOptions(t *testing.T, e env) {
376 te := newTest(t, e)
377 te.perRPCCreds = testPerRPCCredentials{authdata: authdata}
378 // When credentials are provided via both dial options and call options,
379 // we apply both sets.
380 te.tapHandle = func(ctx context.Context, _ *tap.Info) (context.Context, error) {
381 md, ok := metadata.FromIncomingContext(ctx)
382 if !ok {
383 return ctx, fmt.Errorf("couldn't find metadata in context")
384 }
385 for k, vwant := range authdata {
386 vgot, ok := md[k]
387 if !ok {
388 return ctx, fmt.Errorf("couldn't find metadata for key %v", k)
389 }
390 if len(vgot) != 2 {
391 return ctx, fmt.Errorf("len of value for key %v was %v, want 2", k, len(vgot))
392 }
393 if vgot[0] != vwant || vgot[1] != vwant {
394 return ctx, fmt.Errorf("value for %v was %v, want [%v, %v]", k, vgot, vwant, vwant)
395 }
396 }
397 return ctx, nil
398 }
399 te.startServer(&testServer{security: e.security})
400 defer te.tearDown()
401
402 cc := te.clientConn()
403 tc := testgrpc.NewTestServiceClient(cc)
404 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
405 defer cancel()
406 if _, err := tc.EmptyCall(ctx, &testpb.Empty{}, grpc.PerRPCCredentials(testPerRPCCredentials{authdata: authdata})); err != nil {
407 t.Fatalf("Test failed. Reason: %v", err)
408 }
409}
410
411const testAuthority = "test.auth.ori.ty"
412

Calls 9

EmptyCallMethod · 0.95
FromIncomingContextFunction · 0.92
PerRPCCredentialsFunction · 0.92
newTestFunction · 0.70
ErrorfMethod · 0.65
FatalfMethod · 0.65
startServerMethod · 0.45
tearDownMethod · 0.45
clientConnMethod · 0.45

Tested by

no test coverage detected