(t *testing.T)
| 294 | func (r *renameDecompressor) Type() string { return r.name } |
| 295 | |
| 296 | func (s) TestClientForwardsGrpcAcceptEncodingHeader(t *testing.T) { |
| 297 | wantGrpcAcceptEncodingCh := make(chan []string, 1) |
| 298 | defer close(wantGrpcAcceptEncodingCh) |
| 299 | |
| 300 | compressor := renameCompressor{Compressor: grpc.NewGZIPCompressor(), name: "testgzip"} |
| 301 | decompressor := renameDecompressor{Decompressor: grpc.NewGZIPDecompressor(), name: "testgzip"} |
| 302 | |
| 303 | ss := &stubserver.StubServer{ |
| 304 | EmptyCallF: func(ctx context.Context, _ *testpb.Empty) (*testpb.Empty, error) { |
| 305 | md, ok := metadata.FromIncomingContext(ctx) |
| 306 | if !ok { |
| 307 | return nil, status.Errorf(codes.Internal, "no metadata in context") |
| 308 | } |
| 309 | if got, want := md["grpc-accept-encoding"], <-wantGrpcAcceptEncodingCh; !reflect.DeepEqual(got, want) { |
| 310 | return nil, status.Errorf(codes.Internal, "got grpc-accept-encoding=%q; want [%q]", got, want) |
| 311 | } |
| 312 | return &testpb.Empty{}, nil |
| 313 | }, |
| 314 | } |
| 315 | if err := ss.Start([]grpc.ServerOption{grpc.RPCDecompressor(&decompressor)}); err != nil { |
| 316 | t.Fatalf("Error starting endpoint server: %v", err) |
| 317 | } |
| 318 | defer ss.Stop() |
| 319 | |
| 320 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 321 | defer cancel() |
| 322 | |
| 323 | wantGrpcAcceptEncodingCh <- []string{"gzip"} |
| 324 | if _, err := ss.Client.EmptyCall(ctx, &testpb.Empty{}); err != nil { |
| 325 | t.Fatalf("ss.Client.EmptyCall(_, _) = _, %v; want _, nil", err) |
| 326 | } |
| 327 | |
| 328 | wantGrpcAcceptEncodingCh <- []string{"gzip"} |
| 329 | if _, err := ss.Client.EmptyCall(ctx, &testpb.Empty{}, grpc.UseCompressor("gzip")); err != nil { |
| 330 | t.Fatalf("ss.Client.EmptyCall(_, _) = _, %v; want _, nil", err) |
| 331 | } |
| 332 | |
| 333 | // Use compressor directly which is not registered via |
| 334 | // encoding.RegisterCompressor. |
| 335 | if err := ss.StartClient(grpc.WithCompressor(&compressor)); err != nil { |
| 336 | t.Fatalf("Error starting client: %v", err) |
| 337 | } |
| 338 | wantGrpcAcceptEncodingCh <- []string{"gzip,testgzip"} |
| 339 | if _, err := ss.Client.EmptyCall(ctx, &testpb.Empty{}); err != nil { |
| 340 | t.Fatalf("ss.Client.EmptyCall(_, _) = _, %v; want _, nil", err) |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | func (s) TestUnregisteredSetSendCompressorFailure(t *testing.T) { |
| 345 | resCompressor := "snappy2" |
nothing calls this directly
no test coverage detected