TestMethodsSubrouterStrictSlash matches handlers on subrouters with strict-slash matchers.
(t *testing.T)
| 2243 | // TestMethodsSubrouterStrictSlash matches handlers on subrouters with |
| 2244 | // strict-slash matchers. |
| 2245 | func TestMethodsSubrouterStrictSlash(t *testing.T) { |
| 2246 | t.Parallel() |
| 2247 | |
| 2248 | router := NewRouter() |
| 2249 | sub := router.PathPrefix("/").Subrouter() |
| 2250 | sub.StrictSlash(true).Path("/foo").Methods("GET").Subrouter().HandleFunc("", methodHandler("GET")) |
| 2251 | sub.StrictSlash(true).Path("/foo/").Methods("PUT").Subrouter().HandleFunc("/", methodHandler("PUT")) |
| 2252 | sub.StrictSlash(true).Path("/foo/").Methods("POST").Subrouter().HandleFunc("/", methodHandler("POST")) |
| 2253 | |
| 2254 | tests := []methodsSubrouterTest{ |
| 2255 | { |
| 2256 | title: "match POST handler", |
| 2257 | router: router, |
| 2258 | method: "POST", |
| 2259 | path: "http://localhost/foo/", |
| 2260 | wantCode: http.StatusOK, |
| 2261 | }, |
| 2262 | { |
| 2263 | title: "match GET handler", |
| 2264 | router: router, |
| 2265 | method: "GET", |
| 2266 | path: "http://localhost/foo", |
| 2267 | wantCode: http.StatusOK, |
| 2268 | }, |
| 2269 | { |
| 2270 | title: "match POST handler, redirect strict-slash", |
| 2271 | router: router, |
| 2272 | method: "POST", |
| 2273 | path: "http://localhost/foo", |
| 2274 | redirectTo: "http://localhost/foo/", |
| 2275 | wantCode: http.StatusMovedPermanently, |
| 2276 | }, |
| 2277 | { |
| 2278 | title: "match GET handler, redirect strict-slash", |
| 2279 | router: router, |
| 2280 | method: "GET", |
| 2281 | path: "http://localhost/foo/", |
| 2282 | redirectTo: "http://localhost/foo", |
| 2283 | wantCode: http.StatusMovedPermanently, |
| 2284 | }, |
| 2285 | { |
| 2286 | title: "disallow DELETE method", |
| 2287 | router: router, |
| 2288 | method: "DELETE", |
| 2289 | path: "http://localhost/foo", |
| 2290 | wantCode: http.StatusMethodNotAllowed, |
| 2291 | }, |
| 2292 | } |
| 2293 | |
| 2294 | for _, test := range tests { |
| 2295 | t.Run(test.title, func(t *testing.T) { |
| 2296 | testMethodsSubrouter(t, test) |
| 2297 | }) |
| 2298 | } |
| 2299 | } |
| 2300 | |
| 2301 | // TestMethodsSubrouterPathPrefix matches handlers on subrouters created |
| 2302 | // on a router with a path prefix matcher and method matcher. |
nothing calls this directly
no test coverage detected