From ec83e2407f257c0fa7b5ee17727d175d9d6e9f1a Mon Sep 17 00:00:00 2001 From: Vishal Rana Date: Sat, 9 Jan 2016 10:34:34 -0800 Subject: [PATCH] Closed #319 Signed-off-by: Vishal Rana --- _fixture/favicon.ico | Bin 0 -> 1150 bytes _fixture/folder/index.html | 9 +++++++++ {test/fixture => _fixture/images}/walle.png | Bin _fixture/index.html | 9 +++++++++ context_test.go | 4 ++-- echo_test.go | 21 ++++++++++---------- group.go | 12 +++++++++++ group_test.go | 2 ++ 8 files changed, 45 insertions(+), 12 deletions(-) create mode 100644 _fixture/favicon.ico create mode 100644 _fixture/folder/index.html rename {test/fixture => _fixture/images}/walle.png (100%) create mode 100644 _fixture/index.html diff --git a/_fixture/favicon.ico b/_fixture/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..d939ddca12aa14a2fa691e082b14436f18719f6b GIT binary patch literal 1150 zcmZQzU<5(|0R|wcz>vYhz#zuJz@P!dKp~(AL>x#lFaYI*xgi+L$0S%eIXJ|4d3e=$ zc=$9q*f})W*w{3AxVg1?dHFTCxVU71TG%nQ!9^s*C1e}r6xHtm@dI&j$+JSjqKD-a z)E)x)52d8#mN7Cgr~_3q!*xIzLZXr&7N@L&MvuI*?teKY?f(+eioe7p3-i zipeOb?_p!-lme;)8iNY#y}}th{6lyR9m5aFStkFNx6S&mWS;@V>Hn3T^ZqMa;8qR43_WoB7nfzbbr}e*9NZ)^>jyEcB5D~<+3`sc1>sGYKwp`v5j zgo^Gt|D*C+{(Hxj{P#>K{U4Ck^gq98>i?R)d1sp^&J}2!I2S|z%ALmmsy{F`jln-ARk5h5aYt9* zj16{yc^j0iVpbHkPBBa^s?yiCa9}le@x`haBp8{T%@C22>snl1`#mEv>3=|I+E;tu z_=n{M)i2vSC%z1cPj!k)%D|~VFfN0^CoYq}ptP + + + + Echo + + + + diff --git a/test/fixture/walle.png b/_fixture/images/walle.png similarity index 100% rename from test/fixture/walle.png rename to _fixture/images/walle.png diff --git a/_fixture/index.html b/_fixture/index.html new file mode 100644 index 00000000..9b07a758 --- /dev/null +++ b/_fixture/index.html @@ -0,0 +1,9 @@ + + + + + Echo + + + + diff --git a/context_test.go b/context_test.go index 460c0d36..04f4ea8f 100644 --- a/context_test.go +++ b/context_test.go @@ -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") diff --git a/echo_test.go b/echo_test.go index 7bba3d7a..626e24d4 100644 --- a/echo_test.go +++ b/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, "")) @@ -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, "")) + // assert.Equal(t, "sub directory", r) } func TestEchoMiddleware(t *testing.T) { diff --git a/group.go b/group.go index 856a3365..56effb9c 100644 --- a/group.go +++ b/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) } diff --git a/group_test.go b/group_test.go index f605993c..d4eebb3f 100644 --- a/group_test.go +++ b/group_test.go @@ -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")