...
1
2
3
4
5
6
7 package binding
8
9 import (
10 "bytes"
11 "testing"
12
13 "github.com/stretchr/testify/assert"
14 "github.com/stretchr/testify/require"
15 "github.com/ugorji/go/codec"
16 )
17
18 func TestMsgpackBindingBindBody(t *testing.T) {
19 type teststruct struct {
20 Foo string `msgpack:"foo"`
21 }
22 var s teststruct
23 err := msgpackBinding{}.BindBody(msgpackBody(t, teststruct{"FOO"}), &s)
24 require.NoError(t, err)
25 assert.Equal(t, "FOO", s.Foo)
26 }
27
28 func msgpackBody(t *testing.T, obj any) []byte {
29 var bs bytes.Buffer
30 h := &codec.MsgpackHandle{}
31 err := codec.NewEncoder(&bs, h).Encode(obj)
32 require.NoError(t, err)
33 return bs.Bytes()
34 }
35
View as plain text