diff --git a/middleware/auth_test.go b/middleware/auth_test.go index f52e1779..9516709d 100644 --- a/middleware/auth_test.go +++ b/middleware/auth_test.go @@ -14,7 +14,7 @@ func TestBasicAuth(t *testing.T) { e := echo.New() rq := test.NewRequest(echo.GET, "/", nil) rs := test.NewResponseRecorder() - c := echo.NewContext(rq, rs, e) + c := e.NewContext(rq, rs) f := func(u, p string) bool { if u == "joe" && p == "secret" { return true diff --git a/middleware/compress_test.go b/middleware/compress_test.go index b40fc09d..c46d33d5 100644 --- a/middleware/compress_test.go +++ b/middleware/compress_test.go @@ -15,8 +15,8 @@ import ( func TestGzip(t *testing.T) { e := echo.New() rq := test.NewRequest(echo.GET, "/", nil) - rec := test.NewResponseRecorder() - c := echo.NewContext(rq, rec, e) + rc := test.NewResponseRecorder() + c := e.NewContext(rq, rc) // Skip if no Accept-Encoding header h := Gzip()(func(c echo.Context) error { @@ -24,18 +24,18 @@ func TestGzip(t *testing.T) { return nil }) h(c) - assert.Equal(t, "test", rec.Body.String()) + assert.Equal(t, "test", rc.Body.String()) rq = test.NewRequest(echo.GET, "/", nil) rq.Header().Set(echo.HeaderAcceptEncoding, "gzip") - rec = test.NewResponseRecorder() - c = echo.NewContext(rq, rec, e) + rc = test.NewResponseRecorder() + c = e.NewContext(rq, rc) // Gzip h(c) - assert.Equal(t, "gzip", rec.Header().Get(echo.HeaderContentEncoding)) - assert.Contains(t, rec.Header().Get(echo.HeaderContentType), echo.MIMETextPlain) - r, err := gzip.NewReader(rec.Body) + assert.Equal(t, "gzip", rc.Header().Get(echo.HeaderContentEncoding)) + assert.Contains(t, rc.Header().Get(echo.HeaderContentType), echo.MIMETextPlain) + r, err := gzip.NewReader(rc.Body) defer r.Close() if assert.NoError(t, err) { buf := new(bytes.Buffer) @@ -47,16 +47,16 @@ func TestGzip(t *testing.T) { func TestGzipNoContent(t *testing.T) { e := echo.New() rq := test.NewRequest(echo.GET, "/", nil) - rec := test.NewResponseRecorder() - c := echo.NewContext(rq, rec, e) + rc := test.NewResponseRecorder() + c := e.NewContext(rq, rc) 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) + assert.Empty(t, rc.Header().Get(echo.HeaderContentEncoding)) + assert.Empty(t, rc.Header().Get(echo.HeaderContentType)) + b, err := ioutil.ReadAll(rc.Body) if assert.NoError(t, err) { assert.Equal(t, 0, len(b)) } diff --git a/middleware/cors_test.go b/middleware/cors_test.go index 89351488..8ecdf57f 100644 --- a/middleware/cors_test.go +++ b/middleware/cors_test.go @@ -13,7 +13,7 @@ func TestCORS(t *testing.T) { e := echo.New() rq := test.NewRequest(echo.GET, "/", nil) rc := test.NewResponseRecorder() - c := echo.NewContext(rq, rc, e) + c := e.NewContext(rq, rc) cors := CORSWithConfig(CORSConfig{ AllowCredentials: true, }) @@ -28,7 +28,7 @@ func TestCORS(t *testing.T) { // Wildcard origin rq = test.NewRequest(echo.GET, "/", nil) rc = test.NewResponseRecorder() - c = echo.NewContext(rq, rc, e) + c = e.NewContext(rq, rc) rq.Header().Set(echo.HeaderOrigin, "localhost") h(c) assert.Equal(t, "*", rc.Header().Get(echo.HeaderAccessControlAllowOrigin)) @@ -36,7 +36,7 @@ func TestCORS(t *testing.T) { // Simple request rq = test.NewRequest(echo.GET, "/", nil) rc = test.NewResponseRecorder() - c = echo.NewContext(rq, rc, e) + c = e.NewContext(rq, rc) rq.Header().Set(echo.HeaderOrigin, "localhost") cors = CORSWithConfig(CORSConfig{ AllowOrigins: []string{"localhost"}, @@ -52,7 +52,7 @@ func TestCORS(t *testing.T) { // Preflight request rq = test.NewRequest(echo.OPTIONS, "/", nil) rc = test.NewResponseRecorder() - c = echo.NewContext(rq, rc, e) + c = e.NewContext(rq, rc) rq.Header().Set(echo.HeaderOrigin, "localhost") rq.Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSON) h(c) diff --git a/middleware/logger_test.go b/middleware/logger_test.go index d28b9aed..7e017264 100644 --- a/middleware/logger_test.go +++ b/middleware/logger_test.go @@ -15,8 +15,8 @@ func TestLogger(t *testing.T) { // Note: Just for the test coverage, not a real test. e := echo.New() rq := test.NewRequest(echo.GET, "/", nil) - rec := test.NewResponseRecorder() - c := echo.NewContext(rq, rec, e) + rc := test.NewResponseRecorder() + c := e.NewContext(rq, rc) h := Logger()(func(c echo.Context) error { return c.String(http.StatusOK, "test") }) @@ -25,16 +25,16 @@ func TestLogger(t *testing.T) { h(c) // Status 3xx - rec = test.NewResponseRecorder() - c = echo.NewContext(rq, rec, e) + rc = test.NewResponseRecorder() + c = e.NewContext(rq, rc) h = Logger()(func(c echo.Context) error { return c.String(http.StatusTemporaryRedirect, "test") }) h(c) // Status 4xx - rec = test.NewResponseRecorder() - c = echo.NewContext(rq, rec, e) + rc = test.NewResponseRecorder() + c = e.NewContext(rq, rc) h = Logger()(func(c echo.Context) error { return c.String(http.StatusNotFound, "test") }) @@ -42,8 +42,8 @@ func TestLogger(t *testing.T) { // Status 5xx with empty path rq = test.NewRequest(echo.GET, "", nil) - rec = test.NewResponseRecorder() - c = echo.NewContext(rq, rec, e) + rc = test.NewResponseRecorder() + c = e.NewContext(rq, rc) h = Logger()(func(c echo.Context) error { return errors.New("error") }) @@ -53,8 +53,8 @@ func TestLogger(t *testing.T) { func TestLoggerIPAddress(t *testing.T) { e := echo.New() rq := test.NewRequest(echo.GET, "/", nil) - rec := test.NewResponseRecorder() - c := echo.NewContext(rq, rec, e) + rc := test.NewResponseRecorder() + c := e.NewContext(rq, rc) buf := new(bytes.Buffer) e.Logger().SetOutput(buf) ip := "127.0.0.1" diff --git a/middleware/recover_test.go b/middleware/recover_test.go index 67041fd4..c7f8c855 100644 --- a/middleware/recover_test.go +++ b/middleware/recover_test.go @@ -15,12 +15,12 @@ func TestRecover(t *testing.T) { buf := new(bytes.Buffer) e.SetLogOutput(buf) rq := test.NewRequest(echo.GET, "/", nil) - rec := test.NewResponseRecorder() - c := echo.NewContext(rq, rec, e) + rc := test.NewResponseRecorder() + c := e.NewContext(rq, rc) h := Recover()(echo.HandlerFunc(func(c echo.Context) error { panic("test") })) h(c) - assert.Equal(t, http.StatusInternalServerError, rec.Status()) + assert.Equal(t, http.StatusInternalServerError, rc.Status()) assert.Contains(t, buf.String(), "PANIC RECOVER") } diff --git a/middleware/slash_test.go b/middleware/slash_test.go index c009abaa..e7215323 100644 --- a/middleware/slash_test.go +++ b/middleware/slash_test.go @@ -13,7 +13,7 @@ func TestAddTrailingSlash(t *testing.T) { e := echo.New() rq := test.NewRequest(echo.GET, "/add-slash", nil) rc := test.NewResponseRecorder() - c := echo.NewContext(rq, rc, e) + c := e.NewContext(rq, rc) h := AddTrailingSlash()(func(c echo.Context) error { return nil }) @@ -24,7 +24,7 @@ func TestAddTrailingSlash(t *testing.T) { // With config rq = test.NewRequest(echo.GET, "/add-slash?key=value", nil) rc = test.NewResponseRecorder() - c = echo.NewContext(rq, rc, e) + c = e.NewContext(rq, rc) h = AddTrailingSlashWithConfig(TrailingSlashConfig{ RedirectCode: http.StatusMovedPermanently, })(func(c echo.Context) error { @@ -39,7 +39,7 @@ func TestRemoveTrailingSlash(t *testing.T) { e := echo.New() rq := test.NewRequest(echo.GET, "/remove-slash/", nil) rc := test.NewResponseRecorder() - c := echo.NewContext(rq, rc, e) + c := e.NewContext(rq, rc) h := RemoveTrailingSlash()(func(c echo.Context) error { return nil }) @@ -50,7 +50,7 @@ func TestRemoveTrailingSlash(t *testing.T) { // With config rq = test.NewRequest(echo.GET, "/remove-slash/?key=value", nil) rc = test.NewResponseRecorder() - c = echo.NewContext(rq, rc, e) + c = e.NewContext(rq, rc) h = RemoveTrailingSlashWithConfig(TrailingSlashConfig{ RedirectCode: http.StatusMovedPermanently, })(func(c echo.Context) error {