remove dead code in RenderPool.get(...) method and add context.MsgPack(...) test case

This commit is contained in:
Michael Li 2018-12-30 02:23:06 +08:00
parent 6cd65eebdb
commit 077b98e736
2 changed files with 20 additions and 3 deletions

View File

@ -8,6 +8,7 @@ import (
"bytes" "bytes"
"errors" "errors"
"fmt" "fmt"
"github.com/ugorji/go/codec"
"html/template" "html/template"
"io" "io"
"mime/multipart" "mime/multipart"
@ -840,6 +841,25 @@ func TestContextRenderXML(t *testing.T) {
assert.Equal(t, "application/xml; charset=utf-8", w.Header().Get("Content-Type")) 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 // Tests that no XML is rendered if code is 204
func TestContextRenderNoContentXML(t *testing.T) { func TestContextRenderNoContentXML(t *testing.T) {
w := httptest.NewRecorder() w := httptest.NewRecorder()

View File

@ -69,9 +69,6 @@ func (p *RenderPool) get(name int) RenderRecycler {
pool, _ = p.renderPools[EmptyRenderType] pool, _ = p.renderPools[EmptyRenderType]
render, _ = pool.Get().(RenderRecycler) render, _ = pool.Get().(RenderRecycler)
} }
if render == nil {
render = &EmptyRender{}
}
return render return render
} }