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

Method TestSetSendCompressorSuccess

encoding/compressor_test.go:61–107  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

59}
60
61func (s) TestSetSendCompressorSuccess(t *testing.T) {
62 for _, tt := range []struct {
63 name string
64 desc string
65 payload *testpb.Payload
66 dialOpts []grpc.DialOption
67 resCompressor string
68 wantCompressInvokes int32
69 }{
70 {
71 name: "identity_request_and_gzip_response",
72 desc: "request is uncompressed and response is gzip compressed",
73 payload: &testpb.Payload{Body: []byte("payload")},
74 resCompressor: "gzip",
75 wantCompressInvokes: 1,
76 },
77 {
78 name: "identity_request_and_empty_response",
79 desc: "request is uncompressed and response is gzip compressed",
80 payload: nil,
81 resCompressor: "gzip",
82 wantCompressInvokes: 0,
83 },
84 {
85 name: "gzip_request_and_identity_response",
86 desc: "request is gzip compressed and response is uncompressed with identity",
87 payload: &testpb.Payload{Body: []byte("payload")},
88 resCompressor: "identity",
89 dialOpts: []grpc.DialOption{
90 // Use WithCompressor instead of UseCompressor to avoid counting
91 // the client's compressor usage.
92 grpc.WithCompressor(grpc.NewGZIPCompressor()),
93 },
94 wantCompressInvokes: 0,
95 },
96 } {
97 t.Run(tt.name, func(t *testing.T) {
98 t.Run("unary", func(t *testing.T) {
99 testUnarySetSendCompressorSuccess(t, tt.payload, tt.resCompressor, tt.wantCompressInvokes, tt.dialOpts)
100 })
101
102 t.Run("stream", func(t *testing.T) {
103 testStreamSetSendCompressorSuccess(t, tt.payload, tt.resCompressor, tt.wantCompressInvokes, tt.dialOpts)
104 })
105 })
106 }
107}
108
109func testUnarySetSendCompressorSuccess(t *testing.T, payload *testpb.Payload, resCompressor string, wantCompressInvokes int32, dialOpts []grpc.DialOption) {
110 wc := setupGzipWrapCompressor(t)

Callers

nothing calls this directly

Calls 4

WithCompressorFunction · 0.92
NewGZIPCompressorFunction · 0.92

Tested by

no test coverage detected