| 15 | ) |
| 16 | |
| 17 | func TestGroup_withoutRouteWillNotExecuteMiddleware(t *testing.T) { |
| 18 | e := New() |
| 19 | |
| 20 | called := false |
| 21 | mw := func(next HandlerFunc) HandlerFunc { |
| 22 | return func(c *Context) error { |
| 23 | called = true |
| 24 | return c.NoContent(http.StatusTeapot) |
| 25 | } |
| 26 | } |
| 27 | // even though group has middleware it will not be executed when there are no routes under that group |
| 28 | _ = e.Group("/group", mw) |
| 29 | |
| 30 | status, body := request(http.MethodGet, "/group/nope", e) |
| 31 | assert.Equal(t, http.StatusNotFound, status) |
| 32 | assert.Equal(t, `{"message":"Not Found"}`+"\n", body) |
| 33 | |
| 34 | assert.False(t, called) |
| 35 | } |
| 36 | |
| 37 | func TestGroup_withRoutesWillNotExecuteMiddlewareFor404(t *testing.T) { |
| 38 | e := New() |