diff --git a/.travis.yml b/.travis.yml index 80b9c0b2..689ab356 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: go go: - - 1.6 - 1.7 + - 1.8 - tip install: - go get golang.org/x/tools/cmd/cover diff --git a/bind_test.go b/bind_test.go index b83c77b6..8ba0781b 100644 --- a/bind_test.go +++ b/bind_test.go @@ -102,7 +102,7 @@ func TestBindForm(t *testing.T) { testBindOkay(t, strings.NewReader(userForm), MIMEApplicationForm) testBindError(t, nil, MIMEApplicationForm) e := New() - req, _ := http.NewRequest(POST, "/", strings.NewReader(userForm)) + req := httptest.NewRequest(POST, "/", strings.NewReader(userForm)) rec := httptest.NewRecorder() c := e.NewContext(req, rec) req.Header.Set(HeaderContentType, MIMEApplicationForm) @@ -113,7 +113,7 @@ func TestBindForm(t *testing.T) { func TestBindQueryParams(t *testing.T) { e := New() - req, _ := http.NewRequest(GET, "/?id=1&name=Jon Snow", nil) + req := httptest.NewRequest(GET, "/?id=1&name=Jon+Snow", nil) rec := httptest.NewRecorder() c := e.NewContext(req, rec) u := new(user) @@ -126,7 +126,7 @@ func TestBindQueryParams(t *testing.T) { func TestBindUnmarshalParam(t *testing.T) { e := New() - req, _ := http.NewRequest(GET, "/?ts=2016-12-06T19:09:05Z&sa=one,two,three&ta=2016-12-06T19:09:05Z&ta=2016-12-06T19:09:05Z&ST=baz", nil) + req := httptest.NewRequest(GET, "/?ts=2016-12-06T19:09:05Z&sa=one,two,three&ta=2016-12-06T19:09:05Z&ta=2016-12-06T19:09:05Z&ST=baz", nil) rec := httptest.NewRecorder() c := e.NewContext(req, rec) result := struct { @@ -148,7 +148,7 @@ func TestBindUnmarshalParam(t *testing.T) { func TestBindUnmarshalParamPtr(t *testing.T) { e := New() - req, _ := http.NewRequest(GET, "/?ts=2016-12-06T19:09:05Z", nil) + req := httptest.NewRequest(GET, "/?ts=2016-12-06T19:09:05Z", nil) rec := httptest.NewRecorder() c := e.NewContext(req, rec) result := struct { @@ -270,7 +270,7 @@ func assertBindTestStruct(t *testing.T, ts *bindTestStruct) { func testBindOkay(t *testing.T, r io.Reader, ctype string) { e := New() - req, _ := http.NewRequest(POST, "/", r) + req := httptest.NewRequest(POST, "/", r) rec := httptest.NewRecorder() c := e.NewContext(req, rec) req.Header.Set(HeaderContentType, ctype) @@ -284,7 +284,7 @@ func testBindOkay(t *testing.T, r io.Reader, ctype string) { func testBindError(t *testing.T, r io.Reader, ctype string) { e := New() - req, _ := http.NewRequest(POST, "/", r) + req := httptest.NewRequest(POST, "/", r) rec := httptest.NewRecorder() c := e.NewContext(req, rec) req.Header.Set(HeaderContentType, ctype) diff --git a/context_test.go b/context_test.go index c0068651..892b02eb 100644 --- a/context_test.go +++ b/context_test.go @@ -32,7 +32,7 @@ func (t *Template) Render(w io.Writer, name string, data interface{}, c Context) func TestContext(t *testing.T) { e := New() - req, _ := http.NewRequest(POST, "/", strings.NewReader(userJSON)) + req := httptest.NewRequest(POST, "/", strings.NewReader(userJSON)) rec := httptest.NewRecorder() c := e.NewContext(req, rec).(*context) @@ -195,7 +195,7 @@ func TestContext(t *testing.T) { func TestContextCookie(t *testing.T) { e := New() - req, _ := http.NewRequest(GET, "/", nil) + req := httptest.NewRequest(GET, "/", nil) theme := "theme=light" user := "user=Jon Snow" req.Header.Add(HeaderCookie, theme) @@ -255,7 +255,7 @@ func TestContextPath(t *testing.T) { func TestContextPathParam(t *testing.T) { e := New() - req, _ := http.NewRequest(GET, "/", nil) + req := httptest.NewRequest(GET, "/", nil) c := e.NewContext(req, nil) // ParamNames @@ -272,7 +272,7 @@ func TestContextPathParam(t *testing.T) { func TestContextPathParamNamesAlais(t *testing.T) { e := New() - req, _ := http.NewRequest(GET, "/", nil) + req := httptest.NewRequest(GET, "/", nil) c := e.NewContext(req, nil) c.SetParamNames("id,name") @@ -288,7 +288,7 @@ func TestContextFormValue(t *testing.T) { f.Set("email", "jon@labstack.com") e := New() - req, _ := http.NewRequest(POST, "/", strings.NewReader(f.Encode())) + req := httptest.NewRequest(POST, "/", strings.NewReader(f.Encode())) req.Header.Add(HeaderContentType, MIMEApplicationForm) c := e.NewContext(req, nil) @@ -310,7 +310,7 @@ func TestContextQueryParam(t *testing.T) { q := make(url.Values) q.Set("name", "Jon Snow") q.Set("email", "jon@labstack.com") - req, _ := http.NewRequest(GET, "/?"+q.Encode(), nil) + req := httptest.NewRequest(GET, "/?"+q.Encode(), nil) e := New() c := e.NewContext(req, nil) @@ -334,7 +334,7 @@ func TestContextFormFile(t *testing.T) { w.Write([]byte("test")) } mr.Close() - req, _ := http.NewRequest(POST, "/", buf) + req := httptest.NewRequest(POST, "/", buf) req.Header.Set(HeaderContentType, mr.FormDataContentType()) rec := httptest.NewRecorder() c := e.NewContext(req, rec) @@ -350,7 +350,7 @@ func TestContextMultipartForm(t *testing.T) { mw := multipart.NewWriter(buf) mw.WriteField("name", "Jon Snow") mw.Close() - req, _ := http.NewRequest(POST, "/", buf) + req := httptest.NewRequest(POST, "/", buf) req.Header.Set(HeaderContentType, mw.FormDataContentType()) rec := httptest.NewRecorder() c := e.NewContext(req, rec) @@ -362,7 +362,7 @@ func TestContextMultipartForm(t *testing.T) { func TestContextRedirect(t *testing.T) { e := New() - req, _ := http.NewRequest(GET, "/", nil) + req := httptest.NewRequest(GET, "/", nil) rec := httptest.NewRecorder() c := e.NewContext(req, rec) assert.Equal(t, nil, c.Redirect(http.StatusMovedPermanently, "http://labstack.github.io/echo")) diff --git a/echo.go b/echo.go index 55672482..ab78e361 100644 --- a/echo.go +++ b/echo.go @@ -404,7 +404,7 @@ func (e *Echo) Static(prefix, root string) { func static(i i, prefix, root string) { h := func(c Context) error { - name := filepath.Join(root, path.Clean("/"+c.Param("*"))) // `/` for security + name := filepath.Join(root, path.Clean("/"+c.Param("*"))) // "/"+ for security return c.File(name) } i.GET(prefix, h) diff --git a/echo_test.go b/echo_test.go index 03576fe7..be03c991 100644 --- a/echo_test.go +++ b/echo_test.go @@ -42,7 +42,7 @@ const userXMLPretty = ` func TestEcho(t *testing.T) { e := New() - req, _ := http.NewRequest(GET, "/", nil) + req := httptest.NewRequest(GET, "/", nil) rec := httptest.NewRecorder() c := e.NewContext(req, rec) @@ -164,7 +164,7 @@ func TestEchoHandler(t *testing.T) { func TestEchoWrapHandler(t *testing.T) { e := New() - req, _ := http.NewRequest(GET, "", nil) + req := httptest.NewRequest(GET, "/", nil) rec := httptest.NewRecorder() c := e.NewContext(req, rec) h := WrapHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -179,7 +179,7 @@ func TestEchoWrapHandler(t *testing.T) { func TestEchoWrapMiddleware(t *testing.T) { e := New() - req, _ := http.NewRequest(GET, "", nil) + req := httptest.NewRequest(GET, "/", nil) rec := httptest.NewRecorder() c := e.NewContext(req, rec) buf := new(bytes.Buffer) @@ -364,7 +364,7 @@ func TestEchoGroup(t *testing.T) { func TestEchoNotFound(t *testing.T) { e := New() - req, _ := http.NewRequest(GET, "/files", nil) + req := httptest.NewRequest(GET, "/files", nil) rec := httptest.NewRecorder() e.ServeHTTP(rec, req) assert.Equal(t, http.StatusNotFound, rec.Code) @@ -375,7 +375,7 @@ func TestEchoMethodNotAllowed(t *testing.T) { e.GET("/", func(c Context) error { return c.String(http.StatusOK, "Echo!") }) - req, _ := http.NewRequest(POST, "/", nil) + req := httptest.NewRequest(POST, "/", nil) rec := httptest.NewRecorder() e.ServeHTTP(rec, req) assert.Equal(t, http.StatusMethodNotAllowed, rec.Code) @@ -418,7 +418,7 @@ func testMethod(t *testing.T, method, path string, e *Echo) { } func request(method, path string, e *Echo) (int, string) { - req, _ := http.NewRequest(method, path, nil) + req := httptest.NewRequest(method, path, nil) rec := httptest.NewRecorder() e.ServeHTTP(rec, req) return rec.Code, rec.Body.String() diff --git a/middleware/basic_auth_test.go b/middleware/basic_auth_test.go index c4695929..127f56be 100644 --- a/middleware/basic_auth_test.go +++ b/middleware/basic_auth_test.go @@ -12,7 +12,7 @@ import ( func TestBasicAuth(t *testing.T) { e := echo.New() - req, _ := http.NewRequest(echo.GET, "/", nil) + req := httptest.NewRequest(echo.GET, "/", nil) res := httptest.NewRecorder() c := e.NewContext(req, res) f := func(u, p string, c echo.Context) bool { diff --git a/middleware/body_limit_test.go b/middleware/body_limit_test.go index 024a5615..10b889e7 100644 --- a/middleware/body_limit_test.go +++ b/middleware/body_limit_test.go @@ -14,7 +14,7 @@ import ( func TestBodyLimit(t *testing.T) { e := echo.New() hw := []byte("Hello, World!") - req, _ := http.NewRequest(echo.POST, "/", bytes.NewReader(hw)) + req := httptest.NewRequest(echo.POST, "/", bytes.NewReader(hw)) rec := httptest.NewRecorder() c := e.NewContext(req, rec) h := func(c echo.Context) error { diff --git a/middleware/compress_test.go b/middleware/compress_test.go index 41519654..9f7daf69 100644 --- a/middleware/compress_test.go +++ b/middleware/compress_test.go @@ -14,7 +14,7 @@ import ( func TestGzip(t *testing.T) { e := echo.New() - req, _ := http.NewRequest(echo.GET, "/", nil) + req := httptest.NewRequest(echo.GET, "/", nil) rec := httptest.NewRecorder() c := e.NewContext(req, rec) @@ -45,7 +45,7 @@ func TestGzip(t *testing.T) { func TestGzipNoContent(t *testing.T) { e := echo.New() - req, _ := http.NewRequest(echo.GET, "/", nil) + req := httptest.NewRequest(echo.GET, "/", nil) req.Header.Set(echo.HeaderAcceptEncoding, gzipScheme) rec := httptest.NewRecorder() c := e.NewContext(req, rec) @@ -65,7 +65,7 @@ func TestGzipErrorReturned(t *testing.T) { e.GET("/", func(c echo.Context) error { return echo.ErrNotFound }) - req, _ := http.NewRequest(echo.GET, "/", nil) + req := httptest.NewRequest(echo.GET, "/", nil) req.Header.Set(echo.HeaderAcceptEncoding, gzipScheme) rec := httptest.NewRecorder() e.ServeHTTP(rec, req) @@ -78,7 +78,7 @@ func TestGzipWithStatic(t *testing.T) { e := echo.New() e.Use(Gzip()) e.Static("/test", "../_fixture/images") - req, _ := http.NewRequest(echo.GET, "/test/walle.png", nil) + req := httptest.NewRequest(echo.GET, "/test/walle.png", nil) req.Header.Set(echo.HeaderAcceptEncoding, gzipScheme) rec := httptest.NewRecorder() e.ServeHTTP(rec, req) diff --git a/middleware/cors_test.go b/middleware/cors_test.go index 18ab93e1..4ff303cf 100644 --- a/middleware/cors_test.go +++ b/middleware/cors_test.go @@ -13,7 +13,7 @@ func TestCORS(t *testing.T) { e := echo.New() // Wildcard origin - req, _ := http.NewRequest(echo.GET, "/", nil) + req := httptest.NewRequest(echo.GET, "/", nil) rec := httptest.NewRecorder() c := e.NewContext(req, rec) h := CORS()(echo.NotFoundHandler) diff --git a/middleware/csrf_test.go b/middleware/csrf_test.go index 7f7d82ec..b3c9e04c 100644 --- a/middleware/csrf_test.go +++ b/middleware/csrf_test.go @@ -14,7 +14,7 @@ import ( func TestCSRF(t *testing.T) { e := echo.New() - req, _ := http.NewRequest(echo.GET, "/", nil) + req := httptest.NewRequest(echo.GET, "/", nil) rec := httptest.NewRecorder() c := e.NewContext(req, rec) csrf := CSRFWithConfig(CSRFConfig{ @@ -54,7 +54,7 @@ func TestCSRFTokenFromForm(t *testing.T) { f := make(url.Values) f.Set("csrf", "token") e := echo.New() - req, _ := http.NewRequest(echo.POST, "/", strings.NewReader(f.Encode())) + req := httptest.NewRequest(echo.POST, "/", strings.NewReader(f.Encode())) req.Header.Add(echo.HeaderContentType, echo.MIMEApplicationForm) c := e.NewContext(req, nil) token, err := csrfTokenFromForm("csrf")(c) @@ -69,7 +69,7 @@ func TestCSRFTokenFromQuery(t *testing.T) { q := make(url.Values) q.Set("csrf", "token") e := echo.New() - req, _ := http.NewRequest(echo.GET, "/?"+q.Encode(), nil) + req := httptest.NewRequest(echo.GET, "/?"+q.Encode(), nil) req.Header.Add(echo.HeaderContentType, echo.MIMEApplicationForm) c := e.NewContext(req, nil) token, err := csrfTokenFromQuery("csrf")(c) diff --git a/middleware/jwt_test.go b/middleware/jwt_test.go index 2d9d51d5..7a2bb8bf 100644 --- a/middleware/jwt_test.go +++ b/middleware/jwt_test.go @@ -153,7 +153,7 @@ func TestJWT(t *testing.T) { tc.reqURL = "/" } - req, _ := http.NewRequest(echo.GET, tc.reqURL, nil) + req := httptest.NewRequest(echo.GET, tc.reqURL, nil) res := httptest.NewRecorder() req.Header.Set(echo.HeaderAuthorization, tc.hdrAuth) req.Header.Set(echo.HeaderCookie, tc.hdrCookie) diff --git a/middleware/key_auth_test.go b/middleware/key_auth_test.go index a88289dd..69e62a70 100644 --- a/middleware/key_auth_test.go +++ b/middleware/key_auth_test.go @@ -11,7 +11,7 @@ import ( func TestKeyAuth(t *testing.T) { e := echo.New() - req, _ := http.NewRequest(echo.GET, "/", nil) + req := httptest.NewRequest(echo.GET, "/", nil) res := httptest.NewRecorder() c := e.NewContext(req, res) config := KeyAuthConfig{ diff --git a/middleware/logger_test.go b/middleware/logger_test.go index 5eacb51f..df6d98d6 100644 --- a/middleware/logger_test.go +++ b/middleware/logger_test.go @@ -16,7 +16,7 @@ import ( func TestLogger(t *testing.T) { // Note: Just for the test coverage, not a real test. e := echo.New() - req, _ := http.NewRequest(echo.GET, "/", nil) + req := httptest.NewRequest(echo.GET, "/", nil) rec := httptest.NewRecorder() c := e.NewContext(req, rec) h := Logger()(func(c echo.Context) error { @@ -54,7 +54,7 @@ func TestLogger(t *testing.T) { func TestLoggerIPAddress(t *testing.T) { e := echo.New() - req, _ := http.NewRequest(echo.GET, "/", nil) + req := httptest.NewRequest(echo.GET, "/", nil) rec := httptest.NewRecorder() c := e.NewContext(req, rec) buf := new(bytes.Buffer) @@ -98,7 +98,7 @@ func TestLoggerTemplate(t *testing.T) { return c.String(http.StatusOK, "Header Logged") }) - req, _ := http.NewRequest(echo.GET, "/?username=apagano-param&password=secret", nil) + req := httptest.NewRequest(echo.GET, "/?username=apagano-param&password=secret", nil) req.RequestURI = "/" req.Header.Add(echo.HeaderXRealIP, "127.0.0.1") req.Header.Add("Referer", "google.com") diff --git a/middleware/method_override_test.go b/middleware/method_override_test.go index 5b78fcb1..acbcf0ac 100644 --- a/middleware/method_override_test.go +++ b/middleware/method_override_test.go @@ -18,7 +18,7 @@ func TestMethodOverride(t *testing.T) { } // Override with http header - req, _ := http.NewRequest(echo.POST, "/", nil) + req := httptest.NewRequest(echo.POST, "/", nil) rec := httptest.NewRecorder() req.Header.Set(echo.HeaderXHTTPMethodOverride, echo.DELETE) c := e.NewContext(req, rec) diff --git a/middleware/recover_test.go b/middleware/recover_test.go index 6a46cc21..34c2bf31 100644 --- a/middleware/recover_test.go +++ b/middleware/recover_test.go @@ -14,7 +14,7 @@ func TestRecover(t *testing.T) { e := echo.New() buf := new(bytes.Buffer) e.Logger.SetOutput(buf) - req, _ := http.NewRequest(echo.GET, "/", nil) + req := httptest.NewRequest(echo.GET, "/", nil) rec := httptest.NewRecorder() c := e.NewContext(req, rec) h := Recover()(echo.HandlerFunc(func(c echo.Context) error { diff --git a/middleware/redirect_test.go b/middleware/redirect_test.go index df83b248..abc12c0f 100644 --- a/middleware/redirect_test.go +++ b/middleware/redirect_test.go @@ -14,12 +14,13 @@ func TestRedirectHTTPSRedirect(t *testing.T) { next := func(c echo.Context) (err error) { return c.NoContent(http.StatusOK) } - req, _ := http.NewRequest(echo.GET, "http://labstack.com", nil) + req := httptest.NewRequest(echo.GET, "/", nil) + req.Host = "labstack.com" res := httptest.NewRecorder() c := e.NewContext(req, res) HTTPSRedirect()(next)(c) assert.Equal(t, http.StatusMovedPermanently, res.Code) - assert.Equal(t, "https://labstack.com", res.Header().Get(echo.HeaderLocation)) + assert.Equal(t, "https://labstack.com/", res.Header().Get(echo.HeaderLocation)) } func TestRedirectHTTPSWWWRedirect(t *testing.T) { @@ -27,12 +28,13 @@ func TestRedirectHTTPSWWWRedirect(t *testing.T) { next := func(c echo.Context) (err error) { return c.NoContent(http.StatusOK) } - req, _ := http.NewRequest(echo.GET, "http://labstack.com", nil) + req := httptest.NewRequest(echo.GET, "/", nil) + req.Host = "labstack.com" res := httptest.NewRecorder() c := e.NewContext(req, res) HTTPSWWWRedirect()(next)(c) assert.Equal(t, http.StatusMovedPermanently, res.Code) - assert.Equal(t, "https://www.labstack.com", res.Header().Get(echo.HeaderLocation)) + assert.Equal(t, "https://www.labstack.com/", res.Header().Get(echo.HeaderLocation)) } func TestRedirectHTTPSNonWWWRedirect(t *testing.T) { @@ -40,12 +42,13 @@ func TestRedirectHTTPSNonWWWRedirect(t *testing.T) { next := func(c echo.Context) (err error) { return c.NoContent(http.StatusOK) } - req, _ := http.NewRequest(echo.GET, "http://www.labstack.com", nil) + req := httptest.NewRequest(echo.GET, "/", nil) + req.Host = "www.labstack.com" res := httptest.NewRecorder() c := e.NewContext(req, res) HTTPSNonWWWRedirect()(next)(c) assert.Equal(t, http.StatusMovedPermanently, res.Code) - assert.Equal(t, "https://labstack.com", res.Header().Get(echo.HeaderLocation)) + assert.Equal(t, "https://labstack.com/", res.Header().Get(echo.HeaderLocation)) } func TestRedirectWWWRedirect(t *testing.T) { @@ -53,12 +56,13 @@ func TestRedirectWWWRedirect(t *testing.T) { next := func(c echo.Context) (err error) { return c.NoContent(http.StatusOK) } - req, _ := http.NewRequest(echo.GET, "http://labstack.com", nil) + req := httptest.NewRequest(echo.GET, "/", nil) + req.Host = "labstack.com" res := httptest.NewRecorder() c := e.NewContext(req, res) WWWRedirect()(next)(c) assert.Equal(t, http.StatusMovedPermanently, res.Code) - assert.Equal(t, "http://www.labstack.com", res.Header().Get(echo.HeaderLocation)) + assert.Equal(t, "http://www.labstack.com/", res.Header().Get(echo.HeaderLocation)) } func TestRedirectNonWWWRedirect(t *testing.T) { @@ -66,10 +70,11 @@ func TestRedirectNonWWWRedirect(t *testing.T) { next := func(c echo.Context) (err error) { return c.NoContent(http.StatusOK) } - req, _ := http.NewRequest(echo.GET, "http://www.labstack.com", nil) + req := httptest.NewRequest(echo.GET, "/", nil) + req.Host = "www.labstack.com" res := httptest.NewRecorder() c := e.NewContext(req, res) NonWWWRedirect()(next)(c) assert.Equal(t, http.StatusMovedPermanently, res.Code) - assert.Equal(t, "http://labstack.com", res.Header().Get(echo.HeaderLocation)) + assert.Equal(t, "http://labstack.com/", res.Header().Get(echo.HeaderLocation)) } diff --git a/middleware/secure_test.go b/middleware/secure_test.go index d202a682..3c19c56e 100644 --- a/middleware/secure_test.go +++ b/middleware/secure_test.go @@ -11,7 +11,7 @@ import ( func TestSecure(t *testing.T) { e := echo.New() - req, _ := http.NewRequest(echo.GET, "/", nil) + req := httptest.NewRequest(echo.GET, "/", nil) rec := httptest.NewRecorder() c := e.NewContext(req, rec) h := func(c echo.Context) error { diff --git a/middleware/slash_test.go b/middleware/slash_test.go index 48a25cec..08d5f251 100644 --- a/middleware/slash_test.go +++ b/middleware/slash_test.go @@ -11,7 +11,7 @@ import ( func TestAddTrailingSlash(t *testing.T) { e := echo.New() - req, _ := http.NewRequest(echo.GET, "/add-slash", nil) + req := httptest.NewRequest(echo.GET, "/add-slash", nil) rec := httptest.NewRecorder() c := e.NewContext(req, rec) h := AddTrailingSlash()(func(c echo.Context) error { @@ -37,7 +37,7 @@ func TestAddTrailingSlash(t *testing.T) { func TestRemoveTrailingSlash(t *testing.T) { e := echo.New() - req, _ := http.NewRequest(echo.GET, "/remove-slash/", nil) + req := httptest.NewRequest(echo.GET, "/remove-slash/", nil) rec := httptest.NewRecorder() c := e.NewContext(req, rec) h := RemoveTrailingSlash()(func(c echo.Context) error { diff --git a/middleware/static_test.go b/middleware/static_test.go index 8520fe7d..8fb52d7d 100644 --- a/middleware/static_test.go +++ b/middleware/static_test.go @@ -11,11 +11,9 @@ import ( func TestStatic(t *testing.T) { e := echo.New() - // TODO: Once go1.6 is dropped, use `httptest.Request()`. - req, _ := http.NewRequest(echo.GET, "/", nil) + req := httptest.NewRequest(echo.GET, "/", nil) rec := httptest.NewRecorder() c := e.NewContext(req, rec) - c.SetParamNames("*") config := StaticConfig{ Root: "../_fixture", } @@ -27,22 +25,25 @@ func TestStatic(t *testing.T) { } // File found - h = StaticWithConfig(config)(echo.NotFoundHandler) - c.SetParamValues("/images/walle.png") + req = httptest.NewRequest(echo.GET, "/images/walle.png", nil) + rec = httptest.NewRecorder() + c = e.NewContext(req, rec) if assert.NoError(t, h(c)) { assert.Equal(t, http.StatusOK, rec.Code) assert.Equal(t, rec.Header().Get(echo.HeaderContentLength), "219885") } // File not found - c.SetParamValues("/none") - rec.Body.Reset() + req = httptest.NewRequest(echo.GET, "/none", nil) + rec = httptest.NewRecorder() + c = e.NewContext(req, rec) he := h(c).(*echo.HTTPError) assert.Equal(t, http.StatusNotFound, he.Code) // HTML5 - c.SetParamValues("/random") - rec.Body.Reset() + req = httptest.NewRequest(echo.GET, "/random", nil) + rec = httptest.NewRecorder() + c = e.NewContext(req, rec) config.HTML5 = true static := StaticWithConfig(config) h = static(echo.NotFoundHandler) @@ -52,8 +53,9 @@ func TestStatic(t *testing.T) { } // Browse - c.SetParamValues("/") - rec.Body.Reset() + req = httptest.NewRequest(echo.GET, "/", nil) + rec = httptest.NewRecorder() + c = e.NewContext(req, rec) config.Browse = true static = StaticWithConfig(config) h = static(echo.NotFoundHandler)