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

Function DoCustomMetadata

interop/test_utils.go:516–575  ·  view source on GitHub ↗

DoCustomMetadata checks that metadata is echoed back to the client.

(ctx context.Context, tc testgrpc.TestServiceClient, args ...grpc.CallOption)

Source from the content-addressed store, hash-verified

514
515// DoCustomMetadata checks that metadata is echoed back to the client.
516func DoCustomMetadata(ctx context.Context, tc testgrpc.TestServiceClient, args ...grpc.CallOption) {
517 // Testing with UnaryCall.
518 pl := ClientNewPayload(testpb.PayloadType_COMPRESSABLE, 1)
519 req := &testpb.SimpleRequest{
520 ResponseType: testpb.PayloadType_COMPRESSABLE,
521 ResponseSize: int32(1),
522 Payload: pl,
523 }
524 ctx = metadata.NewOutgoingContext(ctx, customMetadata)
525 var header, trailer metadata.MD
526 args = append(args, grpc.Header(&header), grpc.Trailer(&trailer))
527 reply, err := tc.UnaryCall(
528 ctx,
529 req,
530 args...,
531 )
532 if err != nil {
533 logger.Fatal("/TestService/UnaryCall RPC failed: ", err)
534 }
535 t := reply.GetPayload().GetType()
536 s := len(reply.GetPayload().GetBody())
537 if t != testpb.PayloadType_COMPRESSABLE || s != 1 {
538 logger.Fatalf("Got the reply with type %d len %d; want %d, %d", t, s, testpb.PayloadType_COMPRESSABLE, 1)
539 }
540 validateMetadata(header, trailer)
541
542 // Testing with FullDuplex.
543 stream, err := tc.FullDuplexCall(ctx, args...)
544 if err != nil {
545 logger.Fatalf("%v.FullDuplexCall(_) = _, %v, want <nil>", tc, err)
546 }
547 respParam := []*testpb.ResponseParameters{
548 {
549 Size: 1,
550 },
551 }
552 streamReq := &testpb.StreamingOutputCallRequest{
553 ResponseType: testpb.PayloadType_COMPRESSABLE,
554 ResponseParameters: respParam,
555 Payload: pl,
556 }
557 if err := stream.Send(streamReq); err != nil {
558 logger.Fatalf("%v has error %v while sending %v", stream, err, streamReq)
559 }
560 streamHeader, err := stream.Header()
561 if err != nil {
562 logger.Fatalf("%v.Header() = %v", stream, err)
563 }
564 if _, err := stream.Recv(); err != nil {
565 logger.Fatalf("%v.Recv() = %v", stream, err)
566 }
567 if err := stream.CloseSend(); err != nil {
568 logger.Fatalf("%v.CloseSend() = %v, want <nil>", stream, err)
569 }
570 if _, err := stream.Recv(); err != io.EOF {
571 logger.Fatalf("%v failed to complete the custom metadata test: %v", stream, err)
572 }
573 streamTrailer := stream.Trailer()

Callers 3

mainFunction · 0.92
mainFunction · 0.92
performRPCsFunction · 0.92

Calls 15

NewOutgoingContextFunction · 0.92
HeaderFunction · 0.92
TrailerFunction · 0.92
ClientNewPayloadFunction · 0.85
validateMetadataFunction · 0.85
UnaryCallMethod · 0.65
FatalMethod · 0.65
FatalfMethod · 0.65
FullDuplexCallMethod · 0.65
SendMethod · 0.65
HeaderMethod · 0.65
RecvMethod · 0.65

Tested by

no test coverage detected