MCPcopy
hub / github.com/labstack/echo / TestGroupRouteMiddleware

Function TestGroupRouteMiddleware

group_test.go:86–124  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

84}
85
86func TestGroupRouteMiddleware(t *testing.T) {
87 // Ensure middleware slices are not re-used
88 e := New()
89 g := e.Group("/group")
90 h := func(*Context) error { return nil }
91 m1 := func(next HandlerFunc) HandlerFunc {
92 return func(c *Context) error {
93 return next(c)
94 }
95 }
96 m2 := func(next HandlerFunc) HandlerFunc {
97 return func(c *Context) error {
98 return next(c)
99 }
100 }
101 m3 := func(next HandlerFunc) HandlerFunc {
102 return func(c *Context) error {
103 return next(c)
104 }
105 }
106 m4 := func(next HandlerFunc) HandlerFunc {
107 return func(c *Context) error {
108 return c.NoContent(404)
109 }
110 }
111 m5 := func(next HandlerFunc) HandlerFunc {
112 return func(c *Context) error {
113 return c.NoContent(405)
114 }
115 }
116 g.Use(m1, m2, m3)
117 g.GET("/404", h, m4)
118 g.GET("/405", h, m5)
119
120 c, _ := request(http.MethodGet, "/group/404", e)
121 assert.Equal(t, 404, c)
122 c, _ = request(http.MethodGet, "/group/405", e)
123 assert.Equal(t, 405, c)
124}
125
126func TestGroupRouteMiddlewareWithMatchAny(t *testing.T) {
127 // Ensure middleware and match any routes do not conflict

Callers

nothing calls this directly

Calls 6

NewFunction · 0.85
requestFunction · 0.85
NoContentMethod · 0.80
GroupMethod · 0.45
UseMethod · 0.45
GETMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…