mirror of
https://github.com/labstack/echo.git
synced 2025-06-21 00:29:32 +02:00
fixed json, xml pretty print
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
@ -73,6 +73,16 @@ func TestContext(t *testing.T) {
|
||||
assert.Equal(t, userJSON, rec.Body.String())
|
||||
}
|
||||
|
||||
// JSONPretty
|
||||
rec = httptest.NewRecorder()
|
||||
c = e.NewContext(req, rec).(*context)
|
||||
err = c.JSONPretty(http.StatusOK, user{1, "Jon Snow"}, "\t")
|
||||
if assert.NoError(t, err) {
|
||||
assert.Equal(t, http.StatusOK, rec.Code)
|
||||
assert.Equal(t, MIMEApplicationJSONCharsetUTF8, rec.Header().Get(HeaderContentType))
|
||||
assert.Equal(t, userJSONPretty, rec.Body.String())
|
||||
}
|
||||
|
||||
// JSON (error)
|
||||
rec = httptest.NewRecorder()
|
||||
c = e.NewContext(req, rec).(*context)
|
||||
@ -106,6 +116,16 @@ func TestContext(t *testing.T) {
|
||||
err = c.XML(http.StatusOK, make(chan bool))
|
||||
assert.Error(t, err)
|
||||
|
||||
// XMLPretty
|
||||
rec = httptest.NewRecorder()
|
||||
c = e.NewContext(req, rec).(*context)
|
||||
err = c.XMLPretty(http.StatusOK, user{1, "Jon Snow"}, "\t")
|
||||
if assert.NoError(t, err) {
|
||||
assert.Equal(t, http.StatusOK, rec.Code)
|
||||
assert.Equal(t, MIMEApplicationXMLCharsetUTF8, rec.Header().Get(HeaderContentType))
|
||||
assert.Equal(t, xml.Header+userXMLPretty, rec.Body.String())
|
||||
}
|
||||
|
||||
// String
|
||||
rec = httptest.NewRecorder()
|
||||
c = e.NewContext(req, rec).(*context)
|
||||
|
Reference in New Issue
Block a user