Characterization of the regression the 405/OPTIONS tests above guard against: registering a group-wide catch-all (the manual equivalent of #2996's auto- registration) makes it match every method, so method mismatches and the automatic OPTIONS response are masked as 404 even though the concrete route
(t *testing.T)
| 89 | // OPTIONS response are masked as 404 even though the concrete route still resolves. |
| 90 | // If a future change teaches the catch-all to preserve method semantics, update this. |
| 91 | func TestGroupRoute_catchAllMasksMethodHandling(t *testing.T) { |
| 92 | e := New() |
| 93 | g := e.Group("/api") |
| 94 | g.GET("/users", func(c *Context) error { return c.String(http.StatusOK, "users") }) |
| 95 | g.RouteNotFound("/*", func(c *Context) error { return c.NoContent(http.StatusNotFound) }) |
| 96 | |
| 97 | // The concrete route still resolves. |
| 98 | status, body := request(http.MethodGet, "/api/users", e) |
| 99 | assert.Equal(t, http.StatusOK, status) |
| 100 | assert.Equal(t, "users", body) |
| 101 | |
| 102 | // But the catch-all masks the method mismatch (would be 405) ... |
| 103 | post := httptest.NewRequest(http.MethodPost, "/api/users", nil) |
| 104 | postRec := httptest.NewRecorder() |
| 105 | e.ServeHTTP(postRec, post) |
| 106 | assert.Equal(t, http.StatusNotFound, postRec.Code, |
| 107 | "a group-wide catch-all masks the 405 method-mismatch as 404") |
| 108 | |
| 109 | // ... and the automatic OPTIONS response (would be 204). |
| 110 | opts := httptest.NewRequest(http.MethodOptions, "/api/users", nil) |
| 111 | optsRec := httptest.NewRecorder() |
| 112 | e.ServeHTTP(optsRec, opts) |
| 113 | assert.Equal(t, http.StatusNotFound, optsRec.Code, |
| 114 | "a group-wide catch-all masks the automatic OPTIONS (204) response as 404") |
| 115 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…