mirror of
https://github.com/labstack/echo.git
synced 2024-11-24 08:22:21 +02:00
Fixed test
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
parent
d259f88324
commit
29fd5831ff
@ -1,7 +1,7 @@
|
|||||||
language: go
|
language: go
|
||||||
go:
|
go:
|
||||||
- 1.6
|
|
||||||
- 1.7
|
- 1.7
|
||||||
|
- 1.8
|
||||||
- tip
|
- tip
|
||||||
install:
|
install:
|
||||||
- go get golang.org/x/tools/cmd/cover
|
- go get golang.org/x/tools/cmd/cover
|
||||||
|
12
bind_test.go
12
bind_test.go
@ -102,7 +102,7 @@ func TestBindForm(t *testing.T) {
|
|||||||
testBindOkay(t, strings.NewReader(userForm), MIMEApplicationForm)
|
testBindOkay(t, strings.NewReader(userForm), MIMEApplicationForm)
|
||||||
testBindError(t, nil, MIMEApplicationForm)
|
testBindError(t, nil, MIMEApplicationForm)
|
||||||
e := New()
|
e := New()
|
||||||
req, _ := http.NewRequest(POST, "/", strings.NewReader(userForm))
|
req := httptest.NewRequest(POST, "/", strings.NewReader(userForm))
|
||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
c := e.NewContext(req, rec)
|
c := e.NewContext(req, rec)
|
||||||
req.Header.Set(HeaderContentType, MIMEApplicationForm)
|
req.Header.Set(HeaderContentType, MIMEApplicationForm)
|
||||||
@ -113,7 +113,7 @@ func TestBindForm(t *testing.T) {
|
|||||||
|
|
||||||
func TestBindQueryParams(t *testing.T) {
|
func TestBindQueryParams(t *testing.T) {
|
||||||
e := New()
|
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()
|
rec := httptest.NewRecorder()
|
||||||
c := e.NewContext(req, rec)
|
c := e.NewContext(req, rec)
|
||||||
u := new(user)
|
u := new(user)
|
||||||
@ -126,7 +126,7 @@ func TestBindQueryParams(t *testing.T) {
|
|||||||
|
|
||||||
func TestBindUnmarshalParam(t *testing.T) {
|
func TestBindUnmarshalParam(t *testing.T) {
|
||||||
e := New()
|
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()
|
rec := httptest.NewRecorder()
|
||||||
c := e.NewContext(req, rec)
|
c := e.NewContext(req, rec)
|
||||||
result := struct {
|
result := struct {
|
||||||
@ -148,7 +148,7 @@ func TestBindUnmarshalParam(t *testing.T) {
|
|||||||
|
|
||||||
func TestBindUnmarshalParamPtr(t *testing.T) {
|
func TestBindUnmarshalParamPtr(t *testing.T) {
|
||||||
e := New()
|
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()
|
rec := httptest.NewRecorder()
|
||||||
c := e.NewContext(req, rec)
|
c := e.NewContext(req, rec)
|
||||||
result := struct {
|
result := struct {
|
||||||
@ -270,7 +270,7 @@ func assertBindTestStruct(t *testing.T, ts *bindTestStruct) {
|
|||||||
|
|
||||||
func testBindOkay(t *testing.T, r io.Reader, ctype string) {
|
func testBindOkay(t *testing.T, r io.Reader, ctype string) {
|
||||||
e := New()
|
e := New()
|
||||||
req, _ := http.NewRequest(POST, "/", r)
|
req := httptest.NewRequest(POST, "/", r)
|
||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
c := e.NewContext(req, rec)
|
c := e.NewContext(req, rec)
|
||||||
req.Header.Set(HeaderContentType, ctype)
|
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) {
|
func testBindError(t *testing.T, r io.Reader, ctype string) {
|
||||||
e := New()
|
e := New()
|
||||||
req, _ := http.NewRequest(POST, "/", r)
|
req := httptest.NewRequest(POST, "/", r)
|
||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
c := e.NewContext(req, rec)
|
c := e.NewContext(req, rec)
|
||||||
req.Header.Set(HeaderContentType, ctype)
|
req.Header.Set(HeaderContentType, ctype)
|
||||||
|
@ -32,7 +32,7 @@ func (t *Template) Render(w io.Writer, name string, data interface{}, c Context)
|
|||||||
|
|
||||||
func TestContext(t *testing.T) {
|
func TestContext(t *testing.T) {
|
||||||
e := New()
|
e := New()
|
||||||
req, _ := http.NewRequest(POST, "/", strings.NewReader(userJSON))
|
req := httptest.NewRequest(POST, "/", strings.NewReader(userJSON))
|
||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
c := e.NewContext(req, rec).(*context)
|
c := e.NewContext(req, rec).(*context)
|
||||||
|
|
||||||
@ -195,7 +195,7 @@ func TestContext(t *testing.T) {
|
|||||||
|
|
||||||
func TestContextCookie(t *testing.T) {
|
func TestContextCookie(t *testing.T) {
|
||||||
e := New()
|
e := New()
|
||||||
req, _ := http.NewRequest(GET, "/", nil)
|
req := httptest.NewRequest(GET, "/", nil)
|
||||||
theme := "theme=light"
|
theme := "theme=light"
|
||||||
user := "user=Jon Snow"
|
user := "user=Jon Snow"
|
||||||
req.Header.Add(HeaderCookie, theme)
|
req.Header.Add(HeaderCookie, theme)
|
||||||
@ -255,7 +255,7 @@ func TestContextPath(t *testing.T) {
|
|||||||
|
|
||||||
func TestContextPathParam(t *testing.T) {
|
func TestContextPathParam(t *testing.T) {
|
||||||
e := New()
|
e := New()
|
||||||
req, _ := http.NewRequest(GET, "/", nil)
|
req := httptest.NewRequest(GET, "/", nil)
|
||||||
c := e.NewContext(req, nil)
|
c := e.NewContext(req, nil)
|
||||||
|
|
||||||
// ParamNames
|
// ParamNames
|
||||||
@ -272,7 +272,7 @@ func TestContextPathParam(t *testing.T) {
|
|||||||
|
|
||||||
func TestContextPathParamNamesAlais(t *testing.T) {
|
func TestContextPathParamNamesAlais(t *testing.T) {
|
||||||
e := New()
|
e := New()
|
||||||
req, _ := http.NewRequest(GET, "/", nil)
|
req := httptest.NewRequest(GET, "/", nil)
|
||||||
c := e.NewContext(req, nil)
|
c := e.NewContext(req, nil)
|
||||||
|
|
||||||
c.SetParamNames("id,name")
|
c.SetParamNames("id,name")
|
||||||
@ -288,7 +288,7 @@ func TestContextFormValue(t *testing.T) {
|
|||||||
f.Set("email", "jon@labstack.com")
|
f.Set("email", "jon@labstack.com")
|
||||||
|
|
||||||
e := New()
|
e := New()
|
||||||
req, _ := http.NewRequest(POST, "/", strings.NewReader(f.Encode()))
|
req := httptest.NewRequest(POST, "/", strings.NewReader(f.Encode()))
|
||||||
req.Header.Add(HeaderContentType, MIMEApplicationForm)
|
req.Header.Add(HeaderContentType, MIMEApplicationForm)
|
||||||
c := e.NewContext(req, nil)
|
c := e.NewContext(req, nil)
|
||||||
|
|
||||||
@ -310,7 +310,7 @@ func TestContextQueryParam(t *testing.T) {
|
|||||||
q := make(url.Values)
|
q := make(url.Values)
|
||||||
q.Set("name", "Jon Snow")
|
q.Set("name", "Jon Snow")
|
||||||
q.Set("email", "jon@labstack.com")
|
q.Set("email", "jon@labstack.com")
|
||||||
req, _ := http.NewRequest(GET, "/?"+q.Encode(), nil)
|
req := httptest.NewRequest(GET, "/?"+q.Encode(), nil)
|
||||||
e := New()
|
e := New()
|
||||||
c := e.NewContext(req, nil)
|
c := e.NewContext(req, nil)
|
||||||
|
|
||||||
@ -334,7 +334,7 @@ func TestContextFormFile(t *testing.T) {
|
|||||||
w.Write([]byte("test"))
|
w.Write([]byte("test"))
|
||||||
}
|
}
|
||||||
mr.Close()
|
mr.Close()
|
||||||
req, _ := http.NewRequest(POST, "/", buf)
|
req := httptest.NewRequest(POST, "/", buf)
|
||||||
req.Header.Set(HeaderContentType, mr.FormDataContentType())
|
req.Header.Set(HeaderContentType, mr.FormDataContentType())
|
||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
c := e.NewContext(req, rec)
|
c := e.NewContext(req, rec)
|
||||||
@ -350,7 +350,7 @@ func TestContextMultipartForm(t *testing.T) {
|
|||||||
mw := multipart.NewWriter(buf)
|
mw := multipart.NewWriter(buf)
|
||||||
mw.WriteField("name", "Jon Snow")
|
mw.WriteField("name", "Jon Snow")
|
||||||
mw.Close()
|
mw.Close()
|
||||||
req, _ := http.NewRequest(POST, "/", buf)
|
req := httptest.NewRequest(POST, "/", buf)
|
||||||
req.Header.Set(HeaderContentType, mw.FormDataContentType())
|
req.Header.Set(HeaderContentType, mw.FormDataContentType())
|
||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
c := e.NewContext(req, rec)
|
c := e.NewContext(req, rec)
|
||||||
@ -362,7 +362,7 @@ func TestContextMultipartForm(t *testing.T) {
|
|||||||
|
|
||||||
func TestContextRedirect(t *testing.T) {
|
func TestContextRedirect(t *testing.T) {
|
||||||
e := New()
|
e := New()
|
||||||
req, _ := http.NewRequest(GET, "/", nil)
|
req := httptest.NewRequest(GET, "/", nil)
|
||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
c := e.NewContext(req, rec)
|
c := e.NewContext(req, rec)
|
||||||
assert.Equal(t, nil, c.Redirect(http.StatusMovedPermanently, "http://labstack.github.io/echo"))
|
assert.Equal(t, nil, c.Redirect(http.StatusMovedPermanently, "http://labstack.github.io/echo"))
|
||||||
|
2
echo.go
2
echo.go
@ -404,7 +404,7 @@ func (e *Echo) Static(prefix, root string) {
|
|||||||
|
|
||||||
func static(i i, prefix, root string) {
|
func static(i i, prefix, root string) {
|
||||||
h := func(c Context) error {
|
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)
|
return c.File(name)
|
||||||
}
|
}
|
||||||
i.GET(prefix, h)
|
i.GET(prefix, h)
|
||||||
|
12
echo_test.go
12
echo_test.go
@ -42,7 +42,7 @@ const userXMLPretty = `<user>
|
|||||||
|
|
||||||
func TestEcho(t *testing.T) {
|
func TestEcho(t *testing.T) {
|
||||||
e := New()
|
e := New()
|
||||||
req, _ := http.NewRequest(GET, "/", nil)
|
req := httptest.NewRequest(GET, "/", nil)
|
||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
c := e.NewContext(req, rec)
|
c := e.NewContext(req, rec)
|
||||||
|
|
||||||
@ -164,7 +164,7 @@ func TestEchoHandler(t *testing.T) {
|
|||||||
|
|
||||||
func TestEchoWrapHandler(t *testing.T) {
|
func TestEchoWrapHandler(t *testing.T) {
|
||||||
e := New()
|
e := New()
|
||||||
req, _ := http.NewRequest(GET, "", nil)
|
req := httptest.NewRequest(GET, "/", nil)
|
||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
c := e.NewContext(req, rec)
|
c := e.NewContext(req, rec)
|
||||||
h := WrapHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
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) {
|
func TestEchoWrapMiddleware(t *testing.T) {
|
||||||
e := New()
|
e := New()
|
||||||
req, _ := http.NewRequest(GET, "", nil)
|
req := httptest.NewRequest(GET, "/", nil)
|
||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
c := e.NewContext(req, rec)
|
c := e.NewContext(req, rec)
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
@ -364,7 +364,7 @@ func TestEchoGroup(t *testing.T) {
|
|||||||
|
|
||||||
func TestEchoNotFound(t *testing.T) {
|
func TestEchoNotFound(t *testing.T) {
|
||||||
e := New()
|
e := New()
|
||||||
req, _ := http.NewRequest(GET, "/files", nil)
|
req := httptest.NewRequest(GET, "/files", nil)
|
||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
e.ServeHTTP(rec, req)
|
e.ServeHTTP(rec, req)
|
||||||
assert.Equal(t, http.StatusNotFound, rec.Code)
|
assert.Equal(t, http.StatusNotFound, rec.Code)
|
||||||
@ -375,7 +375,7 @@ func TestEchoMethodNotAllowed(t *testing.T) {
|
|||||||
e.GET("/", func(c Context) error {
|
e.GET("/", func(c Context) error {
|
||||||
return c.String(http.StatusOK, "Echo!")
|
return c.String(http.StatusOK, "Echo!")
|
||||||
})
|
})
|
||||||
req, _ := http.NewRequest(POST, "/", nil)
|
req := httptest.NewRequest(POST, "/", nil)
|
||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
e.ServeHTTP(rec, req)
|
e.ServeHTTP(rec, req)
|
||||||
assert.Equal(t, http.StatusMethodNotAllowed, rec.Code)
|
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) {
|
func request(method, path string, e *Echo) (int, string) {
|
||||||
req, _ := http.NewRequest(method, path, nil)
|
req := httptest.NewRequest(method, path, nil)
|
||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
e.ServeHTTP(rec, req)
|
e.ServeHTTP(rec, req)
|
||||||
return rec.Code, rec.Body.String()
|
return rec.Code, rec.Body.String()
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
|
|
||||||
func TestBasicAuth(t *testing.T) {
|
func TestBasicAuth(t *testing.T) {
|
||||||
e := echo.New()
|
e := echo.New()
|
||||||
req, _ := http.NewRequest(echo.GET, "/", nil)
|
req := httptest.NewRequest(echo.GET, "/", nil)
|
||||||
res := httptest.NewRecorder()
|
res := httptest.NewRecorder()
|
||||||
c := e.NewContext(req, res)
|
c := e.NewContext(req, res)
|
||||||
f := func(u, p string, c echo.Context) bool {
|
f := func(u, p string, c echo.Context) bool {
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
func TestBodyLimit(t *testing.T) {
|
func TestBodyLimit(t *testing.T) {
|
||||||
e := echo.New()
|
e := echo.New()
|
||||||
hw := []byte("Hello, World!")
|
hw := []byte("Hello, World!")
|
||||||
req, _ := http.NewRequest(echo.POST, "/", bytes.NewReader(hw))
|
req := httptest.NewRequest(echo.POST, "/", bytes.NewReader(hw))
|
||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
c := e.NewContext(req, rec)
|
c := e.NewContext(req, rec)
|
||||||
h := func(c echo.Context) error {
|
h := func(c echo.Context) error {
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
|
|
||||||
func TestGzip(t *testing.T) {
|
func TestGzip(t *testing.T) {
|
||||||
e := echo.New()
|
e := echo.New()
|
||||||
req, _ := http.NewRequest(echo.GET, "/", nil)
|
req := httptest.NewRequest(echo.GET, "/", nil)
|
||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
c := e.NewContext(req, rec)
|
c := e.NewContext(req, rec)
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ func TestGzip(t *testing.T) {
|
|||||||
|
|
||||||
func TestGzipNoContent(t *testing.T) {
|
func TestGzipNoContent(t *testing.T) {
|
||||||
e := echo.New()
|
e := echo.New()
|
||||||
req, _ := http.NewRequest(echo.GET, "/", nil)
|
req := httptest.NewRequest(echo.GET, "/", nil)
|
||||||
req.Header.Set(echo.HeaderAcceptEncoding, gzipScheme)
|
req.Header.Set(echo.HeaderAcceptEncoding, gzipScheme)
|
||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
c := e.NewContext(req, rec)
|
c := e.NewContext(req, rec)
|
||||||
@ -65,7 +65,7 @@ func TestGzipErrorReturned(t *testing.T) {
|
|||||||
e.GET("/", func(c echo.Context) error {
|
e.GET("/", func(c echo.Context) error {
|
||||||
return echo.ErrNotFound
|
return echo.ErrNotFound
|
||||||
})
|
})
|
||||||
req, _ := http.NewRequest(echo.GET, "/", nil)
|
req := httptest.NewRequest(echo.GET, "/", nil)
|
||||||
req.Header.Set(echo.HeaderAcceptEncoding, gzipScheme)
|
req.Header.Set(echo.HeaderAcceptEncoding, gzipScheme)
|
||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
e.ServeHTTP(rec, req)
|
e.ServeHTTP(rec, req)
|
||||||
@ -78,7 +78,7 @@ func TestGzipWithStatic(t *testing.T) {
|
|||||||
e := echo.New()
|
e := echo.New()
|
||||||
e.Use(Gzip())
|
e.Use(Gzip())
|
||||||
e.Static("/test", "../_fixture/images")
|
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)
|
req.Header.Set(echo.HeaderAcceptEncoding, gzipScheme)
|
||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
e.ServeHTTP(rec, req)
|
e.ServeHTTP(rec, req)
|
||||||
|
@ -13,7 +13,7 @@ func TestCORS(t *testing.T) {
|
|||||||
e := echo.New()
|
e := echo.New()
|
||||||
|
|
||||||
// Wildcard origin
|
// Wildcard origin
|
||||||
req, _ := http.NewRequest(echo.GET, "/", nil)
|
req := httptest.NewRequest(echo.GET, "/", nil)
|
||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
c := e.NewContext(req, rec)
|
c := e.NewContext(req, rec)
|
||||||
h := CORS()(echo.NotFoundHandler)
|
h := CORS()(echo.NotFoundHandler)
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
|
|
||||||
func TestCSRF(t *testing.T) {
|
func TestCSRF(t *testing.T) {
|
||||||
e := echo.New()
|
e := echo.New()
|
||||||
req, _ := http.NewRequest(echo.GET, "/", nil)
|
req := httptest.NewRequest(echo.GET, "/", nil)
|
||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
c := e.NewContext(req, rec)
|
c := e.NewContext(req, rec)
|
||||||
csrf := CSRFWithConfig(CSRFConfig{
|
csrf := CSRFWithConfig(CSRFConfig{
|
||||||
@ -54,7 +54,7 @@ func TestCSRFTokenFromForm(t *testing.T) {
|
|||||||
f := make(url.Values)
|
f := make(url.Values)
|
||||||
f.Set("csrf", "token")
|
f.Set("csrf", "token")
|
||||||
e := echo.New()
|
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)
|
req.Header.Add(echo.HeaderContentType, echo.MIMEApplicationForm)
|
||||||
c := e.NewContext(req, nil)
|
c := e.NewContext(req, nil)
|
||||||
token, err := csrfTokenFromForm("csrf")(c)
|
token, err := csrfTokenFromForm("csrf")(c)
|
||||||
@ -69,7 +69,7 @@ func TestCSRFTokenFromQuery(t *testing.T) {
|
|||||||
q := make(url.Values)
|
q := make(url.Values)
|
||||||
q.Set("csrf", "token")
|
q.Set("csrf", "token")
|
||||||
e := echo.New()
|
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)
|
req.Header.Add(echo.HeaderContentType, echo.MIMEApplicationForm)
|
||||||
c := e.NewContext(req, nil)
|
c := e.NewContext(req, nil)
|
||||||
token, err := csrfTokenFromQuery("csrf")(c)
|
token, err := csrfTokenFromQuery("csrf")(c)
|
||||||
|
@ -153,7 +153,7 @@ func TestJWT(t *testing.T) {
|
|||||||
tc.reqURL = "/"
|
tc.reqURL = "/"
|
||||||
}
|
}
|
||||||
|
|
||||||
req, _ := http.NewRequest(echo.GET, tc.reqURL, nil)
|
req := httptest.NewRequest(echo.GET, tc.reqURL, nil)
|
||||||
res := httptest.NewRecorder()
|
res := httptest.NewRecorder()
|
||||||
req.Header.Set(echo.HeaderAuthorization, tc.hdrAuth)
|
req.Header.Set(echo.HeaderAuthorization, tc.hdrAuth)
|
||||||
req.Header.Set(echo.HeaderCookie, tc.hdrCookie)
|
req.Header.Set(echo.HeaderCookie, tc.hdrCookie)
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
|
|
||||||
func TestKeyAuth(t *testing.T) {
|
func TestKeyAuth(t *testing.T) {
|
||||||
e := echo.New()
|
e := echo.New()
|
||||||
req, _ := http.NewRequest(echo.GET, "/", nil)
|
req := httptest.NewRequest(echo.GET, "/", nil)
|
||||||
res := httptest.NewRecorder()
|
res := httptest.NewRecorder()
|
||||||
c := e.NewContext(req, res)
|
c := e.NewContext(req, res)
|
||||||
config := KeyAuthConfig{
|
config := KeyAuthConfig{
|
||||||
|
@ -16,7 +16,7 @@ import (
|
|||||||
func TestLogger(t *testing.T) {
|
func TestLogger(t *testing.T) {
|
||||||
// Note: Just for the test coverage, not a real test.
|
// Note: Just for the test coverage, not a real test.
|
||||||
e := echo.New()
|
e := echo.New()
|
||||||
req, _ := http.NewRequest(echo.GET, "/", nil)
|
req := httptest.NewRequest(echo.GET, "/", nil)
|
||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
c := e.NewContext(req, rec)
|
c := e.NewContext(req, rec)
|
||||||
h := Logger()(func(c echo.Context) error {
|
h := Logger()(func(c echo.Context) error {
|
||||||
@ -54,7 +54,7 @@ func TestLogger(t *testing.T) {
|
|||||||
|
|
||||||
func TestLoggerIPAddress(t *testing.T) {
|
func TestLoggerIPAddress(t *testing.T) {
|
||||||
e := echo.New()
|
e := echo.New()
|
||||||
req, _ := http.NewRequest(echo.GET, "/", nil)
|
req := httptest.NewRequest(echo.GET, "/", nil)
|
||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
c := e.NewContext(req, rec)
|
c := e.NewContext(req, rec)
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
@ -98,7 +98,7 @@ func TestLoggerTemplate(t *testing.T) {
|
|||||||
return c.String(http.StatusOK, "Header Logged")
|
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.RequestURI = "/"
|
||||||
req.Header.Add(echo.HeaderXRealIP, "127.0.0.1")
|
req.Header.Add(echo.HeaderXRealIP, "127.0.0.1")
|
||||||
req.Header.Add("Referer", "google.com")
|
req.Header.Add("Referer", "google.com")
|
||||||
|
@ -18,7 +18,7 @@ func TestMethodOverride(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Override with http header
|
// Override with http header
|
||||||
req, _ := http.NewRequest(echo.POST, "/", nil)
|
req := httptest.NewRequest(echo.POST, "/", nil)
|
||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
req.Header.Set(echo.HeaderXHTTPMethodOverride, echo.DELETE)
|
req.Header.Set(echo.HeaderXHTTPMethodOverride, echo.DELETE)
|
||||||
c := e.NewContext(req, rec)
|
c := e.NewContext(req, rec)
|
||||||
|
@ -14,7 +14,7 @@ func TestRecover(t *testing.T) {
|
|||||||
e := echo.New()
|
e := echo.New()
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
e.Logger.SetOutput(buf)
|
e.Logger.SetOutput(buf)
|
||||||
req, _ := http.NewRequest(echo.GET, "/", nil)
|
req := httptest.NewRequest(echo.GET, "/", nil)
|
||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
c := e.NewContext(req, rec)
|
c := e.NewContext(req, rec)
|
||||||
h := Recover()(echo.HandlerFunc(func(c echo.Context) error {
|
h := Recover()(echo.HandlerFunc(func(c echo.Context) error {
|
||||||
|
@ -14,12 +14,13 @@ func TestRedirectHTTPSRedirect(t *testing.T) {
|
|||||||
next := func(c echo.Context) (err error) {
|
next := func(c echo.Context) (err error) {
|
||||||
return c.NoContent(http.StatusOK)
|
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()
|
res := httptest.NewRecorder()
|
||||||
c := e.NewContext(req, res)
|
c := e.NewContext(req, res)
|
||||||
HTTPSRedirect()(next)(c)
|
HTTPSRedirect()(next)(c)
|
||||||
assert.Equal(t, http.StatusMovedPermanently, res.Code)
|
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) {
|
func TestRedirectHTTPSWWWRedirect(t *testing.T) {
|
||||||
@ -27,12 +28,13 @@ func TestRedirectHTTPSWWWRedirect(t *testing.T) {
|
|||||||
next := func(c echo.Context) (err error) {
|
next := func(c echo.Context) (err error) {
|
||||||
return c.NoContent(http.StatusOK)
|
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()
|
res := httptest.NewRecorder()
|
||||||
c := e.NewContext(req, res)
|
c := e.NewContext(req, res)
|
||||||
HTTPSWWWRedirect()(next)(c)
|
HTTPSWWWRedirect()(next)(c)
|
||||||
assert.Equal(t, http.StatusMovedPermanently, res.Code)
|
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) {
|
func TestRedirectHTTPSNonWWWRedirect(t *testing.T) {
|
||||||
@ -40,12 +42,13 @@ func TestRedirectHTTPSNonWWWRedirect(t *testing.T) {
|
|||||||
next := func(c echo.Context) (err error) {
|
next := func(c echo.Context) (err error) {
|
||||||
return c.NoContent(http.StatusOK)
|
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()
|
res := httptest.NewRecorder()
|
||||||
c := e.NewContext(req, res)
|
c := e.NewContext(req, res)
|
||||||
HTTPSNonWWWRedirect()(next)(c)
|
HTTPSNonWWWRedirect()(next)(c)
|
||||||
assert.Equal(t, http.StatusMovedPermanently, res.Code)
|
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) {
|
func TestRedirectWWWRedirect(t *testing.T) {
|
||||||
@ -53,12 +56,13 @@ func TestRedirectWWWRedirect(t *testing.T) {
|
|||||||
next := func(c echo.Context) (err error) {
|
next := func(c echo.Context) (err error) {
|
||||||
return c.NoContent(http.StatusOK)
|
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()
|
res := httptest.NewRecorder()
|
||||||
c := e.NewContext(req, res)
|
c := e.NewContext(req, res)
|
||||||
WWWRedirect()(next)(c)
|
WWWRedirect()(next)(c)
|
||||||
assert.Equal(t, http.StatusMovedPermanently, res.Code)
|
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) {
|
func TestRedirectNonWWWRedirect(t *testing.T) {
|
||||||
@ -66,10 +70,11 @@ func TestRedirectNonWWWRedirect(t *testing.T) {
|
|||||||
next := func(c echo.Context) (err error) {
|
next := func(c echo.Context) (err error) {
|
||||||
return c.NoContent(http.StatusOK)
|
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()
|
res := httptest.NewRecorder()
|
||||||
c := e.NewContext(req, res)
|
c := e.NewContext(req, res)
|
||||||
NonWWWRedirect()(next)(c)
|
NonWWWRedirect()(next)(c)
|
||||||
assert.Equal(t, http.StatusMovedPermanently, res.Code)
|
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))
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
|
|
||||||
func TestSecure(t *testing.T) {
|
func TestSecure(t *testing.T) {
|
||||||
e := echo.New()
|
e := echo.New()
|
||||||
req, _ := http.NewRequest(echo.GET, "/", nil)
|
req := httptest.NewRequest(echo.GET, "/", nil)
|
||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
c := e.NewContext(req, rec)
|
c := e.NewContext(req, rec)
|
||||||
h := func(c echo.Context) error {
|
h := func(c echo.Context) error {
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
|
|
||||||
func TestAddTrailingSlash(t *testing.T) {
|
func TestAddTrailingSlash(t *testing.T) {
|
||||||
e := echo.New()
|
e := echo.New()
|
||||||
req, _ := http.NewRequest(echo.GET, "/add-slash", nil)
|
req := httptest.NewRequest(echo.GET, "/add-slash", nil)
|
||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
c := e.NewContext(req, rec)
|
c := e.NewContext(req, rec)
|
||||||
h := AddTrailingSlash()(func(c echo.Context) error {
|
h := AddTrailingSlash()(func(c echo.Context) error {
|
||||||
@ -37,7 +37,7 @@ func TestAddTrailingSlash(t *testing.T) {
|
|||||||
|
|
||||||
func TestRemoveTrailingSlash(t *testing.T) {
|
func TestRemoveTrailingSlash(t *testing.T) {
|
||||||
e := echo.New()
|
e := echo.New()
|
||||||
req, _ := http.NewRequest(echo.GET, "/remove-slash/", nil)
|
req := httptest.NewRequest(echo.GET, "/remove-slash/", nil)
|
||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
c := e.NewContext(req, rec)
|
c := e.NewContext(req, rec)
|
||||||
h := RemoveTrailingSlash()(func(c echo.Context) error {
|
h := RemoveTrailingSlash()(func(c echo.Context) error {
|
||||||
|
@ -11,11 +11,9 @@ import (
|
|||||||
|
|
||||||
func TestStatic(t *testing.T) {
|
func TestStatic(t *testing.T) {
|
||||||
e := echo.New()
|
e := echo.New()
|
||||||
// TODO: Once go1.6 is dropped, use `httptest.Request()`.
|
req := httptest.NewRequest(echo.GET, "/", nil)
|
||||||
req, _ := http.NewRequest(echo.GET, "/", nil)
|
|
||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
c := e.NewContext(req, rec)
|
c := e.NewContext(req, rec)
|
||||||
c.SetParamNames("*")
|
|
||||||
config := StaticConfig{
|
config := StaticConfig{
|
||||||
Root: "../_fixture",
|
Root: "../_fixture",
|
||||||
}
|
}
|
||||||
@ -27,22 +25,25 @@ func TestStatic(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// File found
|
// File found
|
||||||
h = StaticWithConfig(config)(echo.NotFoundHandler)
|
req = httptest.NewRequest(echo.GET, "/images/walle.png", nil)
|
||||||
c.SetParamValues("/images/walle.png")
|
rec = httptest.NewRecorder()
|
||||||
|
c = e.NewContext(req, rec)
|
||||||
if assert.NoError(t, h(c)) {
|
if assert.NoError(t, h(c)) {
|
||||||
assert.Equal(t, http.StatusOK, rec.Code)
|
assert.Equal(t, http.StatusOK, rec.Code)
|
||||||
assert.Equal(t, rec.Header().Get(echo.HeaderContentLength), "219885")
|
assert.Equal(t, rec.Header().Get(echo.HeaderContentLength), "219885")
|
||||||
}
|
}
|
||||||
|
|
||||||
// File not found
|
// File not found
|
||||||
c.SetParamValues("/none")
|
req = httptest.NewRequest(echo.GET, "/none", nil)
|
||||||
rec.Body.Reset()
|
rec = httptest.NewRecorder()
|
||||||
|
c = e.NewContext(req, rec)
|
||||||
he := h(c).(*echo.HTTPError)
|
he := h(c).(*echo.HTTPError)
|
||||||
assert.Equal(t, http.StatusNotFound, he.Code)
|
assert.Equal(t, http.StatusNotFound, he.Code)
|
||||||
|
|
||||||
// HTML5
|
// HTML5
|
||||||
c.SetParamValues("/random")
|
req = httptest.NewRequest(echo.GET, "/random", nil)
|
||||||
rec.Body.Reset()
|
rec = httptest.NewRecorder()
|
||||||
|
c = e.NewContext(req, rec)
|
||||||
config.HTML5 = true
|
config.HTML5 = true
|
||||||
static := StaticWithConfig(config)
|
static := StaticWithConfig(config)
|
||||||
h = static(echo.NotFoundHandler)
|
h = static(echo.NotFoundHandler)
|
||||||
@ -52,8 +53,9 @@ func TestStatic(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Browse
|
// Browse
|
||||||
c.SetParamValues("/")
|
req = httptest.NewRequest(echo.GET, "/", nil)
|
||||||
rec.Body.Reset()
|
rec = httptest.NewRecorder()
|
||||||
|
c = e.NewContext(req, rec)
|
||||||
config.Browse = true
|
config.Browse = true
|
||||||
static = StaticWithConfig(config)
|
static = StaticWithConfig(config)
|
||||||
h = static(echo.NotFoundHandler)
|
h = static(echo.NotFoundHandler)
|
||||||
|
Loading…
Reference in New Issue
Block a user