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

Method TestAcceptCompressorsCallOption

test/compressor_test.go:538–587  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

536}
537
538func (s) TestAcceptCompressorsCallOption(t *testing.T) {
539 tests := []struct {
540 name string
541 callOption grpc.CallOption
542 wantHeader string
543 }{
544 {
545 name: "with AcceptCompressors",
546 callOption: experimental.AcceptCompressors("gzip"),
547 wantHeader: "gzip",
548 },
549 {
550 name: "without AcceptCompressors uses default",
551 callOption: nil,
552 wantHeader: grpcutil.RegisteredCompressors(),
553 },
554 }
555
556 for _, tt := range tests {
557 t.Run(tt.name, func(t *testing.T) {
558 ss := &stubserver.StubServer{
559 EmptyCallF: func(ctx context.Context, _ *testpb.Empty) (*testpb.Empty, error) {
560 md, _ := metadata.FromIncomingContext(ctx)
561 header := md.Get("grpc-accept-encoding")
562
563 if len(header) != 1 || header[0] != tt.wantHeader {
564 t.Errorf("unexpected grpc-accept-encoding header: got %v, want %v", header, tt.wantHeader)
565 }
566 return &testpb.Empty{}, nil
567 },
568 }
569 if err := ss.Start(nil); err != nil {
570 t.Fatalf("failed to start server: %v", err)
571 }
572 defer ss.Stop()
573
574 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
575 defer cancel()
576
577 opts := []grpc.CallOption{}
578 if tt.callOption != nil {
579 opts = append(opts, tt.callOption)
580 }
581
582 if _, err := ss.Client.EmptyCall(ctx, &testpb.Empty{}, opts...); err != nil {
583 t.Fatalf("EmptyCall failed: %v", err)
584 }
585 })
586 }
587}
588
589func (s) TestCompressorRegister(t *testing.T) {
590 for _, e := range listTestEnv() {

Callers

nothing calls this directly

Calls 9

StartMethod · 0.95
StopMethod · 0.95
AcceptCompressorsFunction · 0.92
RegisteredCompressorsFunction · 0.92
FromIncomingContextFunction · 0.92
GetMethod · 0.65
ErrorfMethod · 0.65
FatalfMethod · 0.65
EmptyCallMethod · 0.65

Tested by

no test coverage detected