msgpack_test.go
This file
Path
binding/msgpack_test.go
34 lines · 785 bytes · Go
Last changed by
Not known.
History of this fileTake it
1// Copyright 2019 Gin Core Team. All rights reserved.2// Use of this source code is governed by a MIT style3// license that can be found in the LICENSE file.45//go:build !nomsgpack67package binding89import (10 "bytes"11 "testing"1213 "github.com/stretchr/testify/assert"14 "github.com/stretchr/testify/require"15 "github.com/ugorji/go/codec"16)1718func TestMsgpackBindingBindBody(t *testing.T) {19 type teststruct struct {20 Foo string `msgpack:"foo"`21 }22 var s teststruct23 err := msgpackBinding{}.BindBody(msgpackBody(t, teststruct{"FOO"}), &s)24 require.NoError(t, err)25 assert.Equal(t, "FOO", s.Foo)26}2728func msgpackBody(t *testing.T, obj any) []byte {29 var bs bytes.Buffer30 h := &codec.MsgpackHandle{}31 err := codec.NewEncoder(&bs, h).Encode(obj)32 require.NoError(t, err)33 return bs.Bytes()34}