Skip to content

Commit ec83e24

Browse files
committed
Closed #319
Signed-off-by: Vishal Rana <vr@labstack.com>
1 parent c8d77b2 commit ec83e24

File tree

8 files changed

+45
-12
lines changed

8 files changed

+45
-12
lines changed

_fixture/favicon.ico

1.12 KB
Binary file not shown.

_fixture/folder/index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Echo</title>
6+
</head>
7+
<body>
8+
</body>
9+
</html>
File renamed without changes.

_fixture/index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Echo</title>
6+
</head>
7+
<body>
8+
</body>
9+
</html>

context_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func TestContext(t *testing.T) {
194194
// File
195195
rec = httptest.NewRecorder()
196196
c = NewContext(req, NewResponse(rec, e), e)
197-
err = c.File("test/fixture/walle.png", "", false)
197+
err = c.File("_fixture/images/walle.png", "", false)
198198
if assert.NoError(t, err) {
199199
assert.Equal(t, http.StatusOK, rec.Code)
200200
assert.Equal(t, 219885, rec.Body.Len())
@@ -203,7 +203,7 @@ func TestContext(t *testing.T) {
203203
// File as attachment
204204
rec = httptest.NewRecorder()
205205
c = NewContext(req, NewResponse(rec, e), e)
206-
err = c.File("test/fixture/walle.png", "WALLE.PNG", true)
206+
err = c.File("_fixture/images/walle.png", "WALLE.PNG", true)
207207
if assert.NoError(t, err) {
208208
assert.Equal(t, http.StatusOK, rec.Code)
209209
assert.Equal(t, rec.Header().Get(ContentDisposition), "attachment; filename=WALLE.PNG")

echo_test.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ func TestEcho(t *testing.T) {
4343

4444
func TestEchoIndex(t *testing.T) {
4545
e := New()
46-
e.Index("recipes/website/public/index.html")
46+
e.Index("_fixture/index.html")
4747
c, b := request(GET, "/", e)
4848
assert.Equal(t, http.StatusOK, c)
4949
assert.NotEmpty(t, b)
5050
}
5151

5252
func TestEchoFavicon(t *testing.T) {
5353
e := New()
54-
e.Favicon("recipes/website/public/favicon.ico")
54+
e.Favicon("_fixture/favicon.ico")
5555
c, b := request(GET, "/favicon.ico", e)
5656
assert.Equal(t, http.StatusOK, c)
5757
assert.NotEmpty(t, b)
@@ -61,31 +61,32 @@ func TestEchoStatic(t *testing.T) {
6161
e := New()
6262

6363
// OK
64-
e.Static("/scripts", "recipes/website/public/scripts")
65-
c, b := request(GET, "/scripts/main.js", e)
64+
e.Static("/images", "_fixture/images")
65+
c, b := request(GET, "/images/walle.png", e)
6666
assert.Equal(t, http.StatusOK, c)
6767
assert.NotEmpty(t, b)
6868

6969
// No file
70-
e.Static("/scripts", "recipes/website/public/scripts")
71-
c, _ = request(GET, "/scripts/index.js", e)
70+
e.Static("/images", "_fixture/scripts")
71+
c, _ = request(GET, "/images/bolt.png", e)
7272
assert.Equal(t, http.StatusNotFound, c)
7373

7474
// Directory
75-
e.Static("/scripts", "recipes/website/public/scripts")
76-
c, _ = request(GET, "/scripts", e)
75+
e.Static("/images", "_fixture/images")
76+
c, _ = request(GET, "/images", e)
7777
assert.Equal(t, http.StatusForbidden, c)
7878

7979
// Directory with index.html
80-
e.Static("/", "recipes/website/public")
80+
e.Static("/", "_fixture")
8181
c, r := request(GET, "/", e)
8282
assert.Equal(t, http.StatusOK, c)
8383
assert.Equal(t, true, strings.HasPrefix(r, "<!doctype html>"))
8484

8585
// Sub-directory with index.html
8686
c, r = request(GET, "/folder", e)
8787
assert.Equal(t, http.StatusOK, c)
88-
assert.Equal(t, "sub directory", r)
88+
assert.Equal(t, true, strings.HasPrefix(r, "<!doctype html>"))
89+
// assert.Equal(t, "sub directory", r)
8990
}
9091

9192
func TestEchoMiddleware(t *testing.T) {

group.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ func (g *Group) Trace(path string, h Handler) {
4848
g.echo.Trace(path, h)
4949
}
5050

51+
func (g *Group) Any(path string, h Handler) {
52+
for _, m := range methods {
53+
g.echo.add(m, path, h)
54+
}
55+
}
56+
57+
func (g *Group) Match(methods []string, path string, h Handler) {
58+
for _, m := range methods {
59+
g.echo.add(m, path, h)
60+
}
61+
}
62+
5163
func (g *Group) WebSocket(path string, h HandlerFunc) {
5264
g.echo.WebSocket(path, h)
5365
}

group_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ func TestGroup(t *testing.T) {
1414
g.Post("/", h)
1515
g.Put("/", h)
1616
g.Trace("/", h)
17+
g.Any("/", h)
18+
g.Match([]string{GET, POST}, "/", h)
1719
g.WebSocket("/ws", h)
1820
g.Static("/scripts", "scripts")
1921
g.ServeDir("/scripts", "scripts")

0 commit comments

Comments
 (0)