package meta_test import ( "bytes" "encoding/hex" "testing" "git.bit5.ru/backend/meta/v5" "github.com/stretchr/testify/require" ) func TestMsgpackWriter(t *testing.T) { t.Run("write struct", func(t *testing.T) { var buf bytes.Buffer wr := meta.NewMsgpackWriter(&buf) s := TestParent{ Field1: "blabla", Field2: TestFoo{ Field: 1, }, Field3: []int8{2, 4, 6}, Field4: []TestFoo{ {Field: 10}, {Field: 1024}, }, } err := s.Write(wr) require.NoError(t, err) expected := "94a6626c61626c6191019302040692910a91cd0400" actual := hex.EncodeToString(buf.Bytes()) require.EqualValues(t, expected, actual) }) t.Run("write child struct", func(t *testing.T) { var buf bytes.Buffer wr := meta.NewMsgpackWriter(&buf) s := TestChild{ Field: "qwerty", TestParent: TestParent{ Field1: "blabla", Field2: TestFoo{ Field: 1, }, Field3: []int8{2, 4, 6}, Field4: []TestFoo{ {Field: 10}, {Field: 1024}, }, }, } err := s.Write(wr) require.NoError(t, err) expected := "95a6626c61626c6191019302040692910a91cd0400a6717765727479" actual := hex.EncodeToString(buf.Bytes()) require.EqualValues(t, expected, actual) }) }