(t *testing.T)
| 100 | } |
| 101 | |
| 102 | func 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 |
| 153 | func TestEchoRewritePreMiddleware(t *testing.T) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…