github.com/iotexproject/iotex-core@v1.14.1-rc1/pkg/compress/compress_test.go (about) 1 // Copyright (c) 2019 IoTeX Foundation 2 // This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability 3 // or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed. 4 // This source code is governed by Apache License 2.0 that can be found in the LICENSE file. 5 6 package compress 7 8 import ( 9 "encoding/hex" 10 "testing" 11 12 "github.com/stretchr/testify/require" 13 ) 14 15 func TestCompressDataBytes(t *testing.T) { 16 r := require.New(t) 17 18 // cannot compress nil nor decompress empty byte slice 19 _, err := Compress(nil, "") 20 r.Equal(ErrInputEmpty, err) 21 _, err = Decompress([]byte{}, Gzip) 22 r.Error(err) 23 _, err = Decompress([]byte{}, Snappy) 24 r.Error(err) 25 r.Panics(func() { Compress([]byte{}, "invalid") }) 26 r.Panics(func() { Decompress([]byte{}, "invalid") }) 27 28 zero := [32]byte{} 29 blkHash, _ := hex.DecodeString("22cd0c2d1f7d65298cec7599e2d0e3c650dd8b4ed2b1c816d909026c60d785b2") 30 compressTests := [][]byte{ 31 []byte{}, 32 []byte{1, 2, 3}, 33 zero[:], 34 blkHash, 35 []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`1234567890-=~!@#$%^&*()_+å∫ç∂´´©˙ˆˆ˚¬µ˜˜πœ®ß†¨¨∑≈¥Ω[]',./{}|:<>?"), 36 } 37 for _, ser := range compressTests { 38 for _, compress := range []string{Gzip, Snappy} { 39 v, err := Compress(ser, compress) 40 r.NoError(err) 41 42 ser1, err := Decompress(v, compress) 43 r.NoError(err) 44 r.Equal(ser, ser1) 45 } 46 } 47 }