(t *testing.T)
| 39 | } |
| 40 | |
| 41 | func 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 | |
| 63 | type failWriter struct { |
| 64 | *httptest.ResponseRecorder |
nothing calls this directly
no test coverage detected