render_msgpack_test.go
This file
Path
render/render_msgpack_test.go
43 lines · 977 bytes · Go
Last changed by
chore: support min go version 1.18 (#3511)thinkeroubefore adoption1e1f0b1
History of this fileTake it
1// Copyright 2014 Manu Martinez-Almeida. 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 render89import (10 "bytes"11 "net/http/httptest"12 "testing"1314 "github.com/stretchr/testify/assert"15 "github.com/ugorji/go/codec"16)1718// TODO unit tests19// test errors2021func TestRenderMsgPack(t *testing.T) {22 w := httptest.NewRecorder()23 data := map[string]any{24 "foo": "bar",25 }2627 (MsgPack{data}).WriteContentType(w)28 assert.Equal(t, "application/msgpack; charset=utf-8", w.Header().Get("Content-Type"))2930 err := (MsgPack{data}).Render(w)3132 assert.NoError(t, err)3334 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)3940 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}