From 077b98e73604cbb29e4868020dc32e29491efdbe Mon Sep 17 00:00:00 2001 From: Michael Li Date: Sun, 30 Dec 2018 02:23:06 +0800 Subject: [PATCH] remove dead code in RenderPool.get(...) method and add context.MsgPack(...) test case --- context_test.go | 20 ++++++++++++++++++++ render/render.go | 3 --- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/context_test.go b/context_test.go index 836b3ecb..18986823 100644 --- a/context_test.go +++ b/context_test.go @@ -8,6 +8,7 @@ import ( "bytes" "errors" "fmt" + "github.com/ugorji/go/codec" "html/template" "io" "mime/multipart" @@ -840,6 +841,25 @@ func TestContextRenderXML(t *testing.T) { assert.Equal(t, "application/xml; charset=utf-8", w.Header().Get("Content-Type")) } +func TestContextRenderMsgPack(t *testing.T) { + w := httptest.NewRecorder() + c, _ := CreateTestContext(w) + data := H{"foo": "bar"} + + c.MsgPack(http.StatusCreated, H{"foo": "bar"}) + + 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) + assert.Equal(t, http.StatusCreated, w.Code) + assert.Equal(t, w.Body.String(), string(buf.Bytes())) + assert.Equal(t, "application/msgpack; charset=utf-8", w.Header().Get("Content-Type")) +} + // Tests that no XML is rendered if code is 204 func TestContextRenderNoContentXML(t *testing.T) { w := httptest.NewRecorder() diff --git a/render/render.go b/render/render.go index eb626a83..6ea6ff55 100644 --- a/render/render.go +++ b/render/render.go @@ -69,9 +69,6 @@ func (p *RenderPool) get(name int) RenderRecycler { pool, _ = p.renderPools[EmptyRenderType] render, _ = pool.Get().(RenderRecycler) } - if render == nil { - render = &EmptyRender{} - } return render }