MCPcopy Index your code
hub / github.com/labstack/echo / TestGroupRoute_catchAllMasksMethodHandling

Function TestGroupRoute_catchAllMasksMethodHandling

group_method_handling_test.go:91–115  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
91func 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}

Callers

nothing calls this directly

Calls 8

NewFunction · 0.85
requestFunction · 0.85
NoContentMethod · 0.80
ServeHTTPMethod · 0.80
GroupMethod · 0.45
GETMethod · 0.45
StringMethod · 0.45
RouteNotFoundMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…