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

Function TestMustRewriteWithConfig_skipper

middleware/rewrite_test.go:102–150  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

100}
101
102func TestMustRewriteWithConfig_skipper(t *testing.T) {
103 var testCases = []struct {
104 name string
105 givenSkipper func(c *echo.Context) bool
106 whenURL string
107 expectURL string
108 expectStatus int
109 }{
110 {
111 name: "not skipped",
112 whenURL: "/old",
113 expectURL: "/new",
114 expectStatus: http.StatusOK,
115 },
116 {
117 name: "skipped",
118 givenSkipper: func(c *echo.Context) bool {
119 return true
120 },
121 whenURL: "/old",
122 expectURL: "/old",
123 expectStatus: http.StatusNotFound,
124 },
125 }
126
127 for _, tc := range testCases {
128 t.Run(tc.name, func(t *testing.T) {
129 e := echo.New()
130
131 e.Pre(RewriteWithConfig(
132 RewriteConfig{
133 Skipper: tc.givenSkipper,
134 Rules: map[string]string{"/old": "/new"}},
135 ))
136
137 e.GET("/new", func(c *echo.Context) error {
138 return c.NoContent(http.StatusOK)
139 })
140
141 req := httptest.NewRequest(http.MethodGet, tc.whenURL, nil)
142 rec := httptest.NewRecorder()
143
144 e.ServeHTTP(rec, req)
145
146 assert.Equal(t, tc.expectURL, req.URL.EscapedPath())
147 assert.Equal(t, tc.expectStatus, rec.Code)
148 })
149 }
150}
151
152// Issue #1086
153func TestEchoRewritePreMiddleware(t *testing.T) {

Callers

nothing calls this directly

Calls 5

RewriteWithConfigFunction · 0.85
PreMethod · 0.80
NoContentMethod · 0.80
ServeHTTPMethod · 0.80
GETMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…