...
1
2
3
4
5
6
7 package render
8
9 import (
10 "bytes"
11 "net/http/httptest"
12 "testing"
13
14 "github.com/stretchr/testify/assert"
15 "github.com/ugorji/go/codec"
16 )
17
18
19
20
21 func TestRenderMsgPack(t *testing.T) {
22 w := httptest.NewRecorder()
23 data := map[string]any{
24 "foo": "bar",
25 }
26
27 (MsgPack{data}).WriteContentType(w)
28 assert.Equal(t, "application/msgpack; charset=utf-8", w.Header().Get("Content-Type"))
29
30 err := (MsgPack{data}).Render(w)
31
32 assert.NoError(t, err)
33
34 h := new(codec.MsgpackHandle)
35 assert.NotNil(t, h)
36 buf := bytes.NewBuffer([]byte{})
37 assert.NotNil(t, buf)
38 err = codec.NewEncoder(buf, h).Encode(data)
39
40 assert.NoError(t, err)
41 assert.Equal(t, w.Body.String(), buf.String())
42 assert.Equal(t, "application/msgpack; charset=utf-8", w.Header().Get("Content-Type"))
43 }
44
View as plain text