mirror of
https://github.com/labstack/echo.git
synced 2025-09-16 09:16:29 +02:00
Closes #918, docs updated for testing handler
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
@@ -385,7 +385,7 @@ func (c *context) String(code int, s string) (err error) {
|
||||
}
|
||||
|
||||
func (c *context) JSON(code int, i interface{}) (err error) {
|
||||
_, pretty := c.request.URL.Query()["pretty"]
|
||||
_, pretty := c.QueryParams()["pretty"]
|
||||
if c.echo.Debug || pretty {
|
||||
return c.JSONPretty(code, i, " ")
|
||||
}
|
||||
@@ -430,7 +430,7 @@ func (c *context) JSONPBlob(code int, callback string, b []byte) (err error) {
|
||||
}
|
||||
|
||||
func (c *context) XML(code int, i interface{}) (err error) {
|
||||
_, pretty := c.request.URL.Query()["pretty"]
|
||||
_, pretty := c.QueryParams()["pretty"]
|
||||
if c.echo.Debug || pretty {
|
||||
return c.XMLPretty(code, i, " ")
|
||||
}
|
||||
|
@@ -92,8 +92,7 @@ var (
|
||||
func TestCreateUser(t *testing.T) {
|
||||
// Setup
|
||||
e := echo.New()
|
||||
req, err := http.NewRequest(echo.POST, "/users", strings.NewReader(userJSON))
|
||||
if assert.NoError(t, err) {
|
||||
req := httptest.NewRequest(echo.POST, "/", strings.NewReader(userJSON))
|
||||
req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)
|
||||
rec := httptest.NewRecorder()
|
||||
c := e.NewContext(req, rec)
|
||||
@@ -104,13 +103,12 @@ func TestCreateUser(t *testing.T) {
|
||||
assert.Equal(t, http.StatusCreated, rec.Code)
|
||||
assert.Equal(t, userJSON, rec.Body.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetUser(t *testing.T) {
|
||||
// Setup
|
||||
e := echo.New()
|
||||
req := new(http.Request)
|
||||
req := httptest.NewRequest(echo.GET, "/", nil)
|
||||
rec := httptest.NewRecorder()
|
||||
c := e.NewContext(req, rec)
|
||||
c.SetPath("/users/:email")
|
||||
|
Reference in New Issue
Block a user