@@ -21,15 +21,12 @@ package grpc
21
21
import (
22
22
"bytes"
23
23
"compress/gzip"
24
- "errors"
25
24
"io"
26
25
"math"
27
26
"reflect"
28
27
"testing"
29
28
30
- "github.com/google/go-cmp/cmp"
31
29
"google.golang.org/grpc/codes"
32
- "google.golang.org/grpc/encoding"
33
30
_ "google.golang.org/grpc/encoding/gzip"
34
31
protoenc "google.golang.org/grpc/encoding/proto"
35
32
"google.golang.org/grpc/internal/testutils"
@@ -314,65 +311,4 @@ func compressData(data []byte) []byte {
314
311
// inputs, buffer sizes, and error conditions, using the "gzip" compressor for testing.
315
312
316
313
func TestDecompress (t * testing.T ) {
317
- c := encoding .GetCompressor ("gzip" )
318
-
319
- compressInput := func (input []byte ) mem.BufferSlice {
320
- compressedData := compressData (input )
321
- return mem.BufferSlice {mem .NewBuffer (& compressedData , nil )}
322
- }
323
-
324
- tests := []struct {
325
- name string
326
- compressor encoding.Compressor
327
- input []byte
328
- maxReceiveMessageSize int
329
- want []byte
330
- error error
331
- }{
332
- {
333
- name : "Decompresses successfully with sufficient buffer size" ,
334
- compressor : c ,
335
- input : []byte ("decompressed data" ),
336
- maxReceiveMessageSize : 50 ,
337
- want : []byte ("decompressed data" ),
338
- error : nil ,
339
- },
340
- {
341
- name : "failure, empty receive message" ,
342
- compressor : c ,
343
- input : []byte {},
344
- maxReceiveMessageSize : 10 ,
345
- want : nil ,
346
- error : nil ,
347
- },
348
- {
349
- name : "overflow failure, receive message exceeds maxReceiveMessageSize" ,
350
- compressor : c ,
351
- input : []byte ("small message" ),
352
- maxReceiveMessageSize : 5 ,
353
- want : nil ,
354
- error : errors .New ("overflow: received message size is larger than the allowed maxReceiveMessageSize (5 bytes)" ),
355
- },
356
- }
357
-
358
- for _ , tt := range tests {
359
- t .Run (tt .name , func (t * testing.T ) {
360
- compressedMsg := compressInput (tt .input )
361
- output , numSliceInBuf , err := decompress (tt .compressor , compressedMsg , tt .maxReceiveMessageSize , mem .DefaultBufferPool ())
362
- var wantMsg mem.BufferSlice
363
- if tt .want != nil {
364
- wantMsg = mem.BufferSlice {mem .NewBuffer (& tt .want , nil )}
365
- }
366
- if tt .error != nil && err == nil {
367
- t .Fatalf ("decompress() error, got err=%v, want err=%v" , err , tt .error )
368
- }
369
- if tt .error == nil && numSliceInBuf != wantMsg .Len () {
370
- t .Fatalf ("decompress() number of slices mismatch, got = %d, want = %d" , numSliceInBuf , wantMsg .Len ())
371
- }
372
- if diff := cmp .Diff (wantMsg .Materialize (), output .Materialize ()); diff != "" {
373
- t .Fatalf ("Mismatch in output:\n %s" , diff )
374
- }
375
-
376
- })
377
- }
378
314
}
0 commit comments