1
0
mirror of https://github.com/labstack/echo.git synced 2025-06-23 00:38:07 +02:00

Logging middleware fixes

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana
2016-03-21 17:27:14 -07:00
parent 703174e58f
commit a66162a3d2
16 changed files with 153 additions and 155 deletions

View File

@ -34,9 +34,9 @@ func TestContext(t *testing.T) {
invalidContent := "invalid content"
e := New()
req := test.NewRequest(POST, "/", strings.NewReader(userJSON))
rq := test.NewRequest(POST, "/", strings.NewReader(userJSON))
rec := test.NewResponseRecorder()
c := NewContext(req, rec, e)
c := NewContext(rq, rec, e)
// Request
assert.NotNil(t, c.Request())
@ -98,7 +98,7 @@ func TestContext(t *testing.T) {
// JSON
rec = test.NewResponseRecorder()
c = NewContext(req, rec, e)
c = NewContext(rq, rec, e)
err = c.JSON(http.StatusOK, user{"1", "Joe"})
if assert.NoError(t, err) {
assert.Equal(t, http.StatusOK, rec.Status())
@ -108,13 +108,13 @@ func TestContext(t *testing.T) {
// JSON (error)
rec = test.NewResponseRecorder()
c = NewContext(req, rec, e)
c = NewContext(rq, rec, e)
err = c.JSON(http.StatusOK, make(chan bool))
assert.Error(t, err)
// JSONP
rec = test.NewResponseRecorder()
c = NewContext(req, rec, e)
c = NewContext(rq, rec, e)
callback := "callback"
err = c.JSONP(http.StatusOK, callback, user{"1", "Joe"})
if assert.NoError(t, err) {
@ -125,7 +125,7 @@ func TestContext(t *testing.T) {
// XML
rec = test.NewResponseRecorder()
c = NewContext(req, rec, e)
c = NewContext(rq, rec, e)
err = c.XML(http.StatusOK, user{"1", "Joe"})
if assert.NoError(t, err) {
assert.Equal(t, http.StatusOK, rec.Status())
@ -135,13 +135,13 @@ func TestContext(t *testing.T) {
// XML (error)
rec = test.NewResponseRecorder()
c = NewContext(req, rec, e)
c = NewContext(rq, rec, e)
err = c.XML(http.StatusOK, make(chan bool))
assert.Error(t, err)
// String
rec = test.NewResponseRecorder()
c = NewContext(req, rec, e)
c = NewContext(rq, rec, e)
err = c.String(http.StatusOK, "Hello, World!")
if assert.NoError(t, err) {
assert.Equal(t, http.StatusOK, rec.Status())
@ -151,7 +151,7 @@ func TestContext(t *testing.T) {
// HTML
rec = test.NewResponseRecorder()
c = NewContext(req, rec, e)
c = NewContext(rq, rec, e)
err = c.HTML(http.StatusOK, "Hello, <strong>World!</strong>")
if assert.NoError(t, err) {
assert.Equal(t, http.StatusOK, rec.Status())
@ -161,7 +161,7 @@ func TestContext(t *testing.T) {
// Attachment
rec = test.NewResponseRecorder()
c = NewContext(req, rec, e)
c = NewContext(rq, rec, e)
file, err := os.Open("_fixture/images/walle.png")
if assert.NoError(t, err) {
err = c.Attachment(file, "walle.png")
@ -174,25 +174,25 @@ func TestContext(t *testing.T) {
// NoContent
rec = test.NewResponseRecorder()
c = NewContext(req, rec, e)
c = NewContext(rq, rec, e)
c.NoContent(http.StatusOK)
assert.Equal(t, http.StatusOK, rec.Status())
// Redirect
rec = test.NewResponseRecorder()
c = NewContext(req, rec, e)
c = NewContext(rq, rec, e)
assert.Equal(t, nil, c.Redirect(http.StatusMovedPermanently, "http://labstack.github.io/echo"))
assert.Equal(t, "http://labstack.github.io/echo", rec.Header().Get(Location))
assert.Equal(t, http.StatusMovedPermanently, rec.Status())
// Error
rec = test.NewResponseRecorder()
c = NewContext(req, rec, e)
c = NewContext(rq, rec, e)
c.Error(errors.New("error"))
assert.Equal(t, http.StatusInternalServerError, rec.Status())
// Reset
c.Object().Reset(req, test.NewResponseRecorder())
c.Object().Reset(rq, test.NewResponseRecorder())
}
func TestContextPath(t *testing.T) {
@ -214,8 +214,8 @@ func TestContextQueryParam(t *testing.T) {
q := make(url.Values)
q.Set("name", "joe")
q.Set("email", "joe@labstack.com")
req := test.NewRequest(GET, "/?"+q.Encode(), nil)
c := NewContext(req, nil, New())
rq := test.NewRequest(GET, "/?"+q.Encode(), nil)
c := NewContext(rq, nil, New())
assert.Equal(t, "joe", c.QueryParam("name"))
assert.Equal(t, "joe@labstack.com", c.QueryParam("email"))
}
@ -225,10 +225,10 @@ func TestContextFormValue(t *testing.T) {
f.Set("name", "joe")
f.Set("email", "joe@labstack.com")
req := test.NewRequest(POST, "/", strings.NewReader(f.Encode()))
req.Header().Add(ContentType, ApplicationForm)
rq := test.NewRequest(POST, "/", strings.NewReader(f.Encode()))
rq.Header().Add(ContentType, ApplicationForm)
c := NewContext(req, nil, New())
c := NewContext(rq, nil, New())
assert.Equal(t, "joe", c.FormValue("name"))
assert.Equal(t, "joe@labstack.com", c.FormValue("email"))
}