github.com/johnnyeven/libtools@v0.0.0-20191126065708-61829c1adf46/courier/transport_http/websocket_test.go (about) 1 package transport_http 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/stretchr/testify/assert" 8 9 "github.com/johnnyeven/libtools/timelib" 10 ) 11 12 func TestPayloadMarshalUnMarshal(t *testing.T) { 13 tt := assert.New(t) 14 15 { 16 s := "string" 17 bytes, err := PayloadMarshal(s) 18 tt.Nil(err) 19 t.Log(bytes) 20 var s2 string 21 errForUnmarshal := PayloadUnmarshal(bytes, &s2) 22 tt.Nil(errForUnmarshal) 23 t.Log(s2) 24 tt.Equal(s2, s) 25 } 26 27 { 28 s := 1 29 bytes, err := PayloadMarshal(s) 30 tt.Nil(err) 31 t.Log(bytes) 32 var s2 int 33 errForUnmarshal := PayloadUnmarshal(bytes, &s2) 34 tt.Nil(errForUnmarshal) 35 t.Log(s2) 36 tt.Equal(s2, s) 37 } 38 39 { 40 s := true 41 bytes, err := PayloadMarshal(s) 42 tt.Nil(err) 43 t.Log(bytes) 44 var s2 bool 45 errForUnmarshal := PayloadUnmarshal(bytes, &s2) 46 tt.Nil(errForUnmarshal) 47 t.Log(s2) 48 tt.Equal(s2, s) 49 } 50 51 { 52 s := timelib.MySQLTimestamp(time.Now()) 53 bytes, err := PayloadMarshal(s) 54 tt.Nil(err) 55 t.Log(bytes) 56 var s2 timelib.MySQLTimestamp 57 errForUnmarshal := PayloadUnmarshal(bytes, &s2) 58 tt.Nil(errForUnmarshal) 59 t.Log(s2) 60 tt.Equal(s2.String(), s.String()) 61 } 62 }