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

More coverage and better response adapter for standard/response

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana
2016-06-06 22:27:36 -07:00
parent 8fbe719636
commit c654c422c4
7 changed files with 139 additions and 47 deletions

View File

@ -3,7 +3,6 @@ package middleware
import (
"bytes"
"compress/gzip"
"io/ioutil"
"net/http"
"testing"
@ -52,13 +51,10 @@ func TestGzipNoContent(t *testing.T) {
h := Gzip()(func(c echo.Context) error {
return c.NoContent(http.StatusOK)
})
h(c)
assert.Empty(t, rec.Header().Get(echo.HeaderContentEncoding))
assert.Empty(t, rec.Header().Get(echo.HeaderContentType))
b, err := ioutil.ReadAll(rec.Body)
if assert.NoError(t, err) {
assert.Equal(t, 0, len(b))
if assert.NoError(t, h(c)) {
assert.Empty(t, rec.Header().Get(echo.HeaderContentEncoding))
assert.Empty(t, rec.Header().Get(echo.HeaderContentType))
assert.Equal(t, 0, len(rec.Body.Bytes()))
}
}
@ -71,10 +67,6 @@ func TestGzipErrorReturned(t *testing.T) {
req := test.NewRequest(echo.GET, "/", nil)
rec := test.NewResponseRecorder()
e.ServeHTTP(req, rec)
assert.Empty(t, rec.Header().Get(echo.HeaderContentEncoding))
b, err := ioutil.ReadAll(rec.Body)
if assert.NoError(t, err) {
assert.Equal(t, "error", string(b))
}
assert.Equal(t, "error", rec.Body.String())
}