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