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

Function TestEchoRewritePreMiddleware

middleware/rewrite_test.go:153–172  ·  view source on GitHub ↗

Issue #1086

(t *testing.T)

Source from the content-addressed store, hash-verified

151
152// Issue #1086
153func TestEchoRewritePreMiddleware(t *testing.T) {
154 e := echo.New()
155
156 // Rewrite old url to new one
157 // middlewares added with `Pre()` are executed before routing is done and therefore change which handler matches
158 e.Pre(RewriteWithConfig(RewriteConfig{
159 Rules: map[string]string{"/old": "/new"}}),
160 )
161
162 // Route
163 e.Add(http.MethodGet, "/new", func(c *echo.Context) error {
164 return c.NoContent(http.StatusOK)
165 })
166
167 req := httptest.NewRequest(http.MethodGet, "/old", nil)
168 rec := httptest.NewRecorder()
169 e.ServeHTTP(rec, req)
170 assert.Equal(t, "/new", req.URL.EscapedPath())
171 assert.Equal(t, http.StatusOK, rec.Code)
172}
173
174// Issue #1143
175func TestRewriteWithConfigPreMiddleware_Issue1143(t *testing.T) {

Callers

nothing calls this directly

Calls 5

RewriteWithConfigFunction · 0.85
PreMethod · 0.80
NoContentMethod · 0.80
ServeHTTPMethod · 0.80
AddMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…