github.com/vicanso/pike@v1.0.1-0.20210630235453-9099e041f6ec/compress/gzip_test.go (about) 1 package compress 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestDoGzip(t *testing.T) { 10 assert := assert.New(t) 11 // 压缩级别超出则与默认压缩级别一样 12 tests := []struct { 13 data []byte 14 level int 15 resultSize int 16 }{ 17 { 18 data: compressTestData, 19 level: 0, 20 resultSize: 660, 21 }, 22 { 23 data: compressTestData, 24 level: 0, 25 resultSize: 660, 26 }, 27 { 28 data: compressTestData, 29 level: 0, 30 resultSize: 660, 31 }, 32 } 33 for _, tt := range tests { 34 data, err := doGzip(tt.data, tt.level) 35 assert.Nil(err) 36 assert.NotEqual(tt.data, data) 37 assert.Equal(tt.resultSize, len(data)) 38 } 39 } 40 41 func TestDoGunzip(t *testing.T) { 42 assert := assert.New(t) 43 tests := []struct { 44 data []byte 45 }{ 46 { 47 data: compressTestData, 48 }, 49 } 50 for _, tt := range tests { 51 data, err := doGzip(tt.data, 0) 52 assert.Nil(err) 53 assert.NotEmpty(tt.data, data) 54 assert.NotNil(data) 55 data, err = doGunzip(data) 56 assert.Nil(err) 57 assert.Equal(tt.data, data) 58 } 59 }