Skip to content

Commit 2bc8d10

Browse files
committed
Add tests for group routing with middleware and match any routes
1 parent 16ed3a8 commit 2bc8d10

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

group_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,41 @@ func TestGroupRouteMiddleware(t *testing.T) {
6565
c, _ = request(http.MethodGet, "/group/405", e)
6666
assert.Equal(t, 405, c)
6767
}
68+
69+
func TestGroupRouteMiddlewareWithMatchAny(t *testing.T) {
70+
// Ensure middleware and match any routes do not conflict
71+
e := New()
72+
g := e.Group("/group")
73+
m1 := func(next HandlerFunc) HandlerFunc {
74+
return func(c Context) error {
75+
return next(c)
76+
}
77+
}
78+
m2 := func(next HandlerFunc) HandlerFunc {
79+
return func(c Context) error {
80+
return c.String(http.StatusOK, c.Path())
81+
}
82+
}
83+
h := func(c Context) error {
84+
return c.String(http.StatusOK, c.Path())
85+
}
86+
g.Use(m1)
87+
g.GET("/help", h, m2)
88+
g.GET("/*", h, m2)
89+
g.GET("", h, m2)
90+
e.GET("*", h, m2)
91+
92+
_, m := request(http.MethodGet, "/group/help", e)
93+
assert.Equal(t, "/group/help", m)
94+
_, m = request(http.MethodGet, "/group/help/other", e)
95+
assert.Equal(t, "/group/*", m)
96+
_, m = request(http.MethodGet, "/group/404", e)
97+
assert.Equal(t, "/group/*", m)
98+
_, m = request(http.MethodGet, "/group", e)
99+
assert.Equal(t, "/group", m)
100+
_, m = request(http.MethodGet, "/other", e)
101+
assert.Equal(t, "/*", m)
102+
_, m = request(http.MethodGet, "/", e)
103+
assert.Equal(t, "/*", m)
104+
105+
}

0 commit comments

Comments
 (0)