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

Function TestRewriteWithConfigPreMiddleware_Issue1143

middleware/rewrite_test.go:175–204  ·  view source on GitHub ↗

Issue #1143

(t *testing.T)

Source from the content-addressed store, hash-verified

173
174// Issue #1143
175func TestRewriteWithConfigPreMiddleware_Issue1143(t *testing.T) {
176 e := echo.New()
177
178 // middlewares added with `Pre()` are executed before routing is done and therefore change which handler matches
179 e.Pre(RewriteWithConfig(RewriteConfig{
180 Rules: map[string]string{
181 "/api/*/mgmt/proj/*/agt": "/api/$1/hosts/$2",
182 "/api/*/mgmt/proj": "/api/$1/eng",
183 },
184 }))
185
186 e.Add(http.MethodGet, "/api/:version/hosts/:name", func(c *echo.Context) error {
187 return c.String(http.StatusOK, "hosts")
188 })
189 e.Add(http.MethodGet, "/api/:version/eng", func(c *echo.Context) error {
190 return c.String(http.StatusOK, "eng")
191 })
192
193 for range 100 {
194 req := httptest.NewRequest(http.MethodGet, "/api/v1/mgmt/proj/test/agt", nil)
195 rec := httptest.NewRecorder()
196 e.ServeHTTP(rec, req)
197 assert.Equal(t, "/api/v1/hosts/test", req.URL.EscapedPath())
198 assert.Equal(t, http.StatusOK, rec.Code)
199
200 defer rec.Result().Body.Close()
201 bodyBytes, _ := io.ReadAll(rec.Result().Body)
202 assert.Equal(t, "hosts", string(bodyBytes))
203 }
204}
205
206// Issue #1573
207func TestEchoRewriteWithCaret(t *testing.T) {

Callers

nothing calls this directly

Calls 6

RewriteWithConfigFunction · 0.85
PreMethod · 0.80
ServeHTTPMethod · 0.80
AddMethod · 0.65
StringMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…