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

Method TestClientForwardsGrpcAcceptEncodingHeader

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

Source from the content-addressed store, hash-verified

294func (r *renameDecompressor) Type() string { return r.name }
295
296func (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
344func (s) TestUnregisteredSetSendCompressorFailure(t *testing.T) {
345 resCompressor := "snappy2"

Callers

nothing calls this directly

Calls 12

StartMethod · 0.95
StopMethod · 0.95
StartClientMethod · 0.95
NewGZIPCompressorFunction · 0.92
NewGZIPDecompressorFunction · 0.92
FromIncomingContextFunction · 0.92
ErrorfFunction · 0.92
RPCDecompressorFunction · 0.92
UseCompressorFunction · 0.92
WithCompressorFunction · 0.92
FatalfMethod · 0.65
EmptyCallMethod · 0.65

Tested by

no test coverage detected