github.com/sandwich-go/boost@v1.3.29/xencoding/compressor/compressor_test.go (about) 1 package compressor 2 3 import ( 4 "context" 5 "github.com/sandwich-go/boost/xrand" 6 . "github.com/smartystreets/goconvey/convey" 7 "testing" 8 ) 9 10 func getTestFrames() [][]byte { 11 return [][]byte{ 12 nil, 13 []byte(""), 14 []byte("time.Duration,[]time.Duration,map[string]*Redis此类的非基础类型的slice或者map都需要辅助指明类型"), 15 []byte(xrand.String(100)), 16 } 17 } 18 19 func TestCompressor(t *testing.T) { 20 Convey("compress", t, func() { 21 c := NewCodec(SnappyType + 1) 22 _, err := c.Marshal(context.Background(), "") 23 So(err, ShouldEqual, errCodecNoFound) 24 25 c = NewCodec(SnappyType) 26 _, err = c.Marshal(context.Background(), "") 27 So(err, ShouldEqual, errCodecMarshalParam) 28 29 for i := NoneType; i <= SnappyType; i++ { 30 c = NewCodec(i) 31 for _, frame := range getTestFrames() { 32 mf, err0 := c.Marshal(context.Background(), frame) 33 So(err0, ShouldBeNil) 34 35 var uf []byte 36 err = c.Unmarshal(context.Background(), mf, &uf) 37 So(err, ShouldBeNil) 38 39 So(frame, ShouldResemble, uf) 40 } 41 } 42 }) 43 }