| 35 | } |
| 36 | |
| 37 | func TestGroup_withRoutesWillNotExecuteMiddlewareFor404(t *testing.T) { |
| 38 | e := New() |
| 39 | |
| 40 | called := false |
| 41 | mw := func(next HandlerFunc) HandlerFunc { |
| 42 | return func(c *Context) error { |
| 43 | called = true |
| 44 | return c.NoContent(http.StatusTeapot) |
| 45 | } |
| 46 | } |
| 47 | // even though group has middleware and routes when we have no match on some route the middlewares for that |
| 48 | // group will not be executed |
| 49 | g := e.Group("/group", mw) |
| 50 | g.GET("/yes", handlerFunc) |
| 51 | |
| 52 | status, body := request(http.MethodGet, "/group/nope", e) |
| 53 | assert.Equal(t, http.StatusNotFound, status) |
| 54 | assert.Equal(t, `{"message":"Not Found"}`+"\n", body) |
| 55 | |
| 56 | assert.False(t, called) |
| 57 | } |
| 58 | |
| 59 | func TestGroup_multiLevelGroup(t *testing.T) { |
| 60 | e := New() |