mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-22 17:42:14 +08:00
remove dead code in RenderPool.get(...) method and add context.MsgPack(...) test case
This commit is contained in:
parent
6cd65eebdb
commit
077b98e736
@ -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()
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user