MCPcopy
hub / github.com/gin-gonic/gin / TestWriteMsgPack

Function TestWriteMsgPack

render/render_msgpack_test.go:41–61  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

39}
40
41func TestWriteMsgPack(t *testing.T) {
42 w := httptest.NewRecorder()
43 data := map[string]any{
44 "foo": "bar",
45 "num": 42,
46 }
47
48 err := WriteMsgPack(w, data)
49 require.NoError(t, err)
50
51 assert.Equal(t, "application/msgpack; charset=utf-8", w.Header().Get("Content-Type"))
52
53 var decoded map[string]any
54 var mh codec.MsgpackHandle
55 mh.RawToString = true
56 err = codec.NewDecoderBytes(w.Body.Bytes(), &mh).Decode(&decoded)
57 require.NoError(t, err)
58 assert.Len(t, decoded, 2)
59 assert.Equal(t, "bar", decoded["foo"])
60 assert.EqualValues(t, 42, decoded["num"])
61}
62
63type failWriter struct {
64 *httptest.ResponseRecorder

Callers

nothing calls this directly

Calls 4

WriteMsgPackFunction · 0.85
DecodeMethod · 0.65
GetMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected