github.com/artisanhe/tools@v1.0.1-0.20210607022958-19a8fef2eb04/courier/transport_grpc/msgpack_codec_test.go (about) 1 package transport_grpc 2 3 import ( 4 "testing" 5 6 "github.com/davecgh/go-spew/spew" 7 "github.com/stretchr/testify/assert" 8 ) 9 10 type Body struct { 11 } 12 13 type WithID struct { 14 ID string `json:"id" in:"path"` 15 } 16 17 type Item2 struct { 18 WithID 19 } 20 21 type Item struct { 22 WithID 23 Ping string `json:"ping" in:"query"` 24 Path string 25 } 26 27 type ItemReq struct { 28 ID string `json:"id" in:"path"` 29 Ping []byte `json:"ping" in:"query"` 30 } 31 32 func TestMsg(t *testing.T) { 33 tt := assert.New(t) 34 35 codec := MsgPackCodec{} 36 item := ItemReq{} 37 item.ID = "13123.123" 38 item.Ping = []byte("ping") 39 40 bytes, err := codec.Marshal(item) 41 spew.Dump(bytes) 42 tt.Nil(err) 43 44 { 45 withID := WithID{} 46 err := codec.Unmarshal(bytes, &withID) 47 tt.Nil(err) 48 spew.Dump(withID) 49 } 50 51 { 52 item := &Item{} 53 err := codec.Unmarshal(bytes, &item) 54 tt.Nil(err) 55 spew.Dump(item) 56 } 57 }