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

Method TestUnsupportedEncodingResponse

test/compressor_test.go:46–117  ·  view source on GitHub ↗

TestUnsupportedEncodingResponse validates gRPC status codes for different client-server compression setups ensuring the correct behavior when compression is enabled or disabled on either side.

(t *testing.T)

Source from the content-addressed store, hash-verified

44// for different client-server compression setups
45// ensuring the correct behavior when compression is enabled or disabled on either side.
46func (s) TestUnsupportedEncodingResponse(t *testing.T) {
47 tests := []struct {
48 name string
49 clientCompress bool
50 serverCompress bool
51 wantStatus codes.Code
52 }{
53 {
54 name: "client_server_compression",
55 clientCompress: true,
56 serverCompress: true,
57 wantStatus: codes.OK,
58 },
59 {
60 name: "client_compression",
61 clientCompress: true,
62 serverCompress: false,
63 wantStatus: codes.Unimplemented,
64 },
65 {
66 name: "server_compression",
67 clientCompress: false,
68 serverCompress: true,
69 wantStatus: codes.Internal,
70 },
71 }
72
73 for _, test := range tests {
74 t.Run(test.name, func(t *testing.T) {
75 ss := &stubserver.StubServer{
76 UnaryCallF: func(_ context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
77 return &testpb.SimpleResponse{Payload: in.Payload}, nil
78 },
79 }
80 sopts := []grpc.ServerOption{}
81 if test.serverCompress {
82 // Using deprecated methods to selectively apply compression
83 // only on the server side. With encoding.registerCompressor(),
84 // the compressor is applied globally, affecting client and server
85 sopts = append(sopts, grpc.RPCCompressor(newNopCompressor()), grpc.RPCDecompressor(newNopDecompressor()))
86 }
87 if err := ss.StartServer(sopts...); err != nil {
88 t.Fatalf("Error starting server: %v", err)
89 }
90 defer ss.Stop()
91
92 dopts := []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())}
93 if test.clientCompress {
94 // UseCompressor() requires the compressor to be registered
95 // using encoding.RegisterCompressor() which applies compressor globally,
96 // Hence, using deprecated WithCompressor() and WithDecompressor()
97 // to apply compression only on client.
98 dopts = append(dopts, grpc.WithCompressor(newNopCompressor()), grpc.WithDecompressor(newNopDecompressor()))
99 }
100 if err := ss.StartClient(dopts...); err != nil {
101 t.Fatalf("Error starting client: %v", err)
102 }
103

Callers

nothing calls this directly

Calls 15

StartServerMethod · 0.95
StopMethod · 0.95
StartClientMethod · 0.95
RPCCompressorFunction · 0.92
RPCDecompressorFunction · 0.92
WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
WithCompressorFunction · 0.92
WithDecompressorFunction · 0.92
CodeFunction · 0.92
newNopCompressorFunction · 0.85
newNopDecompressorFunction · 0.85

Tested by

no test coverage detected