2020-01-07 03:31:10 +00:00
|
|
|
// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2021-03-27 01:09:44 +00:00
|
|
|
//go:build !nomsgpack
|
2020-01-07 03:31:10 +00:00
|
|
|
// +build !nomsgpack
|
|
|
|
|
|
|
|
package render
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"net/http/httptest"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/ugorji/go/codec"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TODO unit tests
|
|
|
|
// test errors
|
|
|
|
|
|
|
|
func TestRenderMsgPack(t *testing.T) {
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
data := map[string]interface{}{
|
|
|
|
"foo": "bar",
|
|
|
|
}
|
|
|
|
|
|
|
|
(MsgPack{data}).WriteContentType(w)
|
|
|
|
assert.Equal(t, "application/msgpack; charset=utf-8", w.Header().Get("Content-Type"))
|
|
|
|
|
|
|
|
err := (MsgPack{data}).Render(w)
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
h := new(codec.MsgpackHandle)
|
|
|
|
assert.NotNil(t, h)
|
|
|
|
buf := bytes.NewBuffer([]byte{})
|
|
|
|
assert.NotNil(t, buf)
|
|
|
|
err = codec.NewEncoder(buf, h).Encode(data)
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
2021-06-25 04:14:06 +00:00
|
|
|
assert.Equal(t, w.Body.String(), buf.String())
|
2020-01-07 03:31:10 +00:00
|
|
|
assert.Equal(t, "application/msgpack; charset=utf-8", w.Header().Get("Content-Type"))
|
|
|
|
}
|