Apply requested changes

This commit is contained in:
Filip Figiel 2018-08-20 08:50:13 +02:00
parent a84483b40f
commit fbe37a5afb
3 changed files with 7 additions and 12 deletions

View File

@ -7,6 +7,7 @@
package gin package gin
import ( import (
"net/http"
"net/http/httptest" "net/http/httptest"
"testing" "testing"
@ -19,8 +20,8 @@ import (
func TestContextRenderPureJSON(t *testing.T) { func TestContextRenderPureJSON(t *testing.T) {
w := httptest.NewRecorder() w := httptest.NewRecorder()
c, _ := CreateTestContext(w) c, _ := CreateTestContext(w)
c.PureJSON(201, H{"foo": "bar", "html": "<b>"}) c.PureJSON(http.StatusCreated, H{"foo": "bar", "html": "<b>"})
assert.Equal(t, 201, w.Code) assert.Equal(t, http.StatusCreated, w.Code)
assert.Equal(t, "{\"foo\":\"bar\",\"html\":\"<b>\"}\n", w.Body.String()) assert.Equal(t, "{\"foo\":\"bar\",\"html\":\"<b>\"}\n", w.Body.String())
assert.Equal(t, "application/json; charset=utf-8", w.HeaderMap.Get("Content-Type")) assert.Equal(t, "application/json; charset=utf-8", w.HeaderMap.Get("Content-Type"))
} }

View File

@ -575,13 +575,10 @@ func TestContextRenderJSON(t *testing.T) {
w := httptest.NewRecorder() w := httptest.NewRecorder()
c, _ := CreateTestContext(w) c, _ := CreateTestContext(w)
c.JSON(201, H{"foo": "bar", "html": "<b>"}) c.JSON(http.StatusCreated, H{"foo": "bar", "html": "<b>"})
assert.Equal(t, 201, w.Code) assert.Equal(t, http.StatusCreated, w.Code)
assert.Equal( assert.Equal(t, "{\"foo\":\"bar\",\"html\":\"\\u003cb\\u003e\"}", w.Body.String())
t,
"{\"foo\":\"bar\",\"html\":\"\\u003cb\\u003e\"}",
w.Body.String())
assert.Equal(t, "application/json; charset=utf-8", w.HeaderMap.Get("Content-Type")) assert.Equal(t, "application/json; charset=utf-8", w.HeaderMap.Get("Content-Type"))
} }

View File

@ -50,10 +50,7 @@ func TestRenderJSON(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, "{\"foo\":\"bar\"}", w.Body.String()) assert.Equal(t, "{\"foo\":\"bar\"}", w.Body.String())
assert.Equal( assert.Equal(t, "{\"foo\":\"bar\",\"html\":\"\\u003cb\\u003e\"}\n", w.Body.String())
t,
"{\"foo\":\"bar\",\"html\":\"\\u003cb\\u003e\"}\n",
w.Body.String())
assert.Equal(t, "application/json; charset=utf-8", w.Header().Get("Content-Type")) assert.Equal(t, "application/json; charset=utf-8", w.Header().Get("Content-Type"))
} }