mirror of
https://github.com/labstack/echo.git
synced 2024-12-22 20:06:21 +02:00
parent
c8d77b2675
commit
ec83e2407f
BIN
_fixture/favicon.ico
Normal file
BIN
_fixture/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
9
_fixture/folder/index.html
Normal file
9
_fixture/folder/index.html
Normal file
@ -0,0 +1,9 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Echo</title>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
Before Width: | Height: | Size: 215 KiB After Width: | Height: | Size: 215 KiB |
9
_fixture/index.html
Normal file
9
_fixture/index.html
Normal file
@ -0,0 +1,9 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Echo</title>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
@ -194,7 +194,7 @@ func TestContext(t *testing.T) {
|
||||
// File
|
||||
rec = httptest.NewRecorder()
|
||||
c = NewContext(req, NewResponse(rec, e), e)
|
||||
err = c.File("test/fixture/walle.png", "", false)
|
||||
err = c.File("_fixture/images/walle.png", "", false)
|
||||
if assert.NoError(t, err) {
|
||||
assert.Equal(t, http.StatusOK, rec.Code)
|
||||
assert.Equal(t, 219885, rec.Body.Len())
|
||||
@ -203,7 +203,7 @@ func TestContext(t *testing.T) {
|
||||
// File as attachment
|
||||
rec = httptest.NewRecorder()
|
||||
c = NewContext(req, NewResponse(rec, e), e)
|
||||
err = c.File("test/fixture/walle.png", "WALLE.PNG", true)
|
||||
err = c.File("_fixture/images/walle.png", "WALLE.PNG", true)
|
||||
if assert.NoError(t, err) {
|
||||
assert.Equal(t, http.StatusOK, rec.Code)
|
||||
assert.Equal(t, rec.Header().Get(ContentDisposition), "attachment; filename=WALLE.PNG")
|
||||
|
21
echo_test.go
21
echo_test.go
@ -43,7 +43,7 @@ func TestEcho(t *testing.T) {
|
||||
|
||||
func TestEchoIndex(t *testing.T) {
|
||||
e := New()
|
||||
e.Index("recipes/website/public/index.html")
|
||||
e.Index("_fixture/index.html")
|
||||
c, b := request(GET, "/", e)
|
||||
assert.Equal(t, http.StatusOK, c)
|
||||
assert.NotEmpty(t, b)
|
||||
@ -51,7 +51,7 @@ func TestEchoIndex(t *testing.T) {
|
||||
|
||||
func TestEchoFavicon(t *testing.T) {
|
||||
e := New()
|
||||
e.Favicon("recipes/website/public/favicon.ico")
|
||||
e.Favicon("_fixture/favicon.ico")
|
||||
c, b := request(GET, "/favicon.ico", e)
|
||||
assert.Equal(t, http.StatusOK, c)
|
||||
assert.NotEmpty(t, b)
|
||||
@ -61,23 +61,23 @@ func TestEchoStatic(t *testing.T) {
|
||||
e := New()
|
||||
|
||||
// OK
|
||||
e.Static("/scripts", "recipes/website/public/scripts")
|
||||
c, b := request(GET, "/scripts/main.js", e)
|
||||
e.Static("/images", "_fixture/images")
|
||||
c, b := request(GET, "/images/walle.png", e)
|
||||
assert.Equal(t, http.StatusOK, c)
|
||||
assert.NotEmpty(t, b)
|
||||
|
||||
// No file
|
||||
e.Static("/scripts", "recipes/website/public/scripts")
|
||||
c, _ = request(GET, "/scripts/index.js", e)
|
||||
e.Static("/images", "_fixture/scripts")
|
||||
c, _ = request(GET, "/images/bolt.png", e)
|
||||
assert.Equal(t, http.StatusNotFound, c)
|
||||
|
||||
// Directory
|
||||
e.Static("/scripts", "recipes/website/public/scripts")
|
||||
c, _ = request(GET, "/scripts", e)
|
||||
e.Static("/images", "_fixture/images")
|
||||
c, _ = request(GET, "/images", e)
|
||||
assert.Equal(t, http.StatusForbidden, c)
|
||||
|
||||
// Directory with index.html
|
||||
e.Static("/", "recipes/website/public")
|
||||
e.Static("/", "_fixture")
|
||||
c, r := request(GET, "/", e)
|
||||
assert.Equal(t, http.StatusOK, c)
|
||||
assert.Equal(t, true, strings.HasPrefix(r, "<!doctype html>"))
|
||||
@ -85,7 +85,8 @@ func TestEchoStatic(t *testing.T) {
|
||||
// Sub-directory with index.html
|
||||
c, r = request(GET, "/folder", e)
|
||||
assert.Equal(t, http.StatusOK, c)
|
||||
assert.Equal(t, "sub directory", r)
|
||||
assert.Equal(t, true, strings.HasPrefix(r, "<!doctype html>"))
|
||||
// assert.Equal(t, "sub directory", r)
|
||||
}
|
||||
|
||||
func TestEchoMiddleware(t *testing.T) {
|
||||
|
12
group.go
12
group.go
@ -48,6 +48,18 @@ func (g *Group) Trace(path string, h Handler) {
|
||||
g.echo.Trace(path, h)
|
||||
}
|
||||
|
||||
func (g *Group) Any(path string, h Handler) {
|
||||
for _, m := range methods {
|
||||
g.echo.add(m, path, h)
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Group) Match(methods []string, path string, h Handler) {
|
||||
for _, m := range methods {
|
||||
g.echo.add(m, path, h)
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Group) WebSocket(path string, h HandlerFunc) {
|
||||
g.echo.WebSocket(path, h)
|
||||
}
|
||||
|
@ -14,6 +14,8 @@ func TestGroup(t *testing.T) {
|
||||
g.Post("/", h)
|
||||
g.Put("/", h)
|
||||
g.Trace("/", h)
|
||||
g.Any("/", h)
|
||||
g.Match([]string{GET, POST}, "/", h)
|
||||
g.WebSocket("/ws", h)
|
||||
g.Static("/scripts", "scripts")
|
||||
g.ServeDir("/scripts", "scripts")
|
||||
|
Loading…
Reference in New Issue
Block a user