From 2bc8d10b2103890c48ae68d7cdf8b39c01c1d8cd Mon Sep 17 00:00:00 2001 From: Roland Lammel Date: Fri, 4 Oct 2019 01:15:54 +0200 Subject: [PATCH] Add tests for group routing with middleware and match any routes --- group_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/group_test.go b/group_test.go index de98ce30..ea5488b0 100644 --- a/group_test.go +++ b/group_test.go @@ -65,3 +65,41 @@ func TestGroupRouteMiddleware(t *testing.T) { c, _ = request(http.MethodGet, "/group/405", e) assert.Equal(t, 405, c) } + +func TestGroupRouteMiddlewareWithMatchAny(t *testing.T) { + // Ensure middleware and match any routes do not conflict + e := New() + g := e.Group("/group") + m1 := func(next HandlerFunc) HandlerFunc { + return func(c Context) error { + return next(c) + } + } + m2 := func(next HandlerFunc) HandlerFunc { + return func(c Context) error { + return c.String(http.StatusOK, c.Path()) + } + } + h := func(c Context) error { + return c.String(http.StatusOK, c.Path()) + } + g.Use(m1) + g.GET("/help", h, m2) + g.GET("/*", h, m2) + g.GET("", h, m2) + e.GET("*", h, m2) + + _, m := request(http.MethodGet, "/group/help", e) + assert.Equal(t, "/group/help", m) + _, m = request(http.MethodGet, "/group/help/other", e) + assert.Equal(t, "/group/*", m) + _, m = request(http.MethodGet, "/group/404", e) + assert.Equal(t, "/group/*", m) + _, m = request(http.MethodGet, "/group", e) + assert.Equal(t, "/group", m) + _, m = request(http.MethodGet, "/other", e) + assert.Equal(t, "/*", m) + _, m = request(http.MethodGet, "/", e) + assert.Equal(t, "/*", m) + +}