From e11de1df62494152d51e775353d32050f6cc5774 Mon Sep 17 00:00:00 2001 From: Tim Anema Date: Sun, 26 Apr 2015 18:17:46 -0400 Subject: [PATCH 1/3] small change to allow nested groups --- echo.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/echo.go b/echo.go index ea9ae0647..f2dbf717c 100644 --- a/echo.go +++ b/echo.go @@ -147,7 +147,7 @@ func New() (e *Echo) { // the parent. Passing middleware overrides parent middleware. func (e *Echo) Group(pfx string, m ...Middleware) *Echo { g := *e - g.prefix = pfx + g.prefix = g.prefix + pfx if len(m) > 0 { g.middleware = nil g.Use(m...) From 8dd92bce9787e9aac78f5bdaa8640650fb273359 Mon Sep 17 00:00:00 2001 From: Tim Anema Date: Sun, 26 Apr 2015 18:27:20 -0400 Subject: [PATCH 2/3] test for nested group --- echo_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/echo_test.go b/echo_test.go index 8c9794894..cae9cb16e 100644 --- a/echo_test.go +++ b/echo_test.go @@ -218,6 +218,19 @@ func TestEchoGroup(t *testing.T) { if b.String() != "3" { t.Errorf("should execute middleware 3, executed %s", b.String()) } + + // Nested Group + g3 := e.Group("/group3") + g4 := g3.Group("/group4") + g4.Get("/test", func(c *Context) { + c.String(http.StatusOK, "okay") + }) + w = httptest.NewRecorder() + r, _ = http.NewRequest(GET, "/group3/group4/test", nil) + e.ServeHTTP(w, r) + if w.Body.String() != "okay" { + t.Error("body should be okay") + } } func TestEchoMethod(t *testing.T) { From ff75c9c907578bae38105ab73b34cd44e305f04c Mon Sep 17 00:00:00 2001 From: Vishal Rana Date: Sun, 26 Apr 2015 18:06:18 -0700 Subject: [PATCH 3/3] Closing 39 Signed-off-by: Vishal Rana --- echo_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/echo_test.go b/echo_test.go index cae9cb16e..c2a3fc32f 100644 --- a/echo_test.go +++ b/echo_test.go @@ -219,17 +219,17 @@ func TestEchoGroup(t *testing.T) { t.Errorf("should execute middleware 3, executed %s", b.String()) } - // Nested Group + // Nested group g3 := e.Group("/group3") g4 := g3.Group("/group4") - g4.Get("/test", func(c *Context) { - c.String(http.StatusOK, "okay") + g4.Get("/home", func(c *Context) { + c.NoContent(http.StatusOK) }) w = httptest.NewRecorder() - r, _ = http.NewRequest(GET, "/group3/group4/test", nil) + r, _ = http.NewRequest(GET, "/group3/group4/home", nil) e.ServeHTTP(w, r) - if w.Body.String() != "okay" { - t.Error("body should be okay") + if w.Code != 200 { + t.Errorf("status code should be 200, found %d", w.Code) } }