TestMethodsSubrouterCatchall matches handlers for subrouters where a catchall handler is set for a mis-matching method.
(t *testing.T)
| 2194 | // TestMethodsSubrouterCatchall matches handlers for subrouters where a |
| 2195 | // catchall handler is set for a mis-matching method. |
| 2196 | func TestMethodsSubrouterCatchall(t *testing.T) { |
| 2197 | t.Parallel() |
| 2198 | |
| 2199 | router := NewRouter() |
| 2200 | router.Methods("PATCH").Subrouter().PathPrefix("/").HandlerFunc(methodHandler("PUT")) |
| 2201 | router.Methods("GET").Subrouter().HandleFunc("/foo", methodHandler("GET")) |
| 2202 | router.Methods("POST").Subrouter().HandleFunc("/foo", methodHandler("POST")) |
| 2203 | router.Methods("DELETE").Subrouter().HandleFunc("/foo", methodHandler("DELETE")) |
| 2204 | |
| 2205 | tests := []methodsSubrouterTest{ |
| 2206 | { |
| 2207 | title: "match GET handler", |
| 2208 | router: router, |
| 2209 | path: "http://localhost/foo", |
| 2210 | method: "GET", |
| 2211 | wantCode: http.StatusOK, |
| 2212 | }, |
| 2213 | { |
| 2214 | title: "match POST handler", |
| 2215 | router: router, |
| 2216 | method: "POST", |
| 2217 | path: "http://localhost/foo", |
| 2218 | wantCode: http.StatusOK, |
| 2219 | }, |
| 2220 | { |
| 2221 | title: "match DELETE handler", |
| 2222 | router: router, |
| 2223 | method: "DELETE", |
| 2224 | path: "http://localhost/foo", |
| 2225 | wantCode: http.StatusOK, |
| 2226 | }, |
| 2227 | { |
| 2228 | title: "disallow PUT method", |
| 2229 | router: router, |
| 2230 | method: "PUT", |
| 2231 | path: "http://localhost/foo", |
| 2232 | wantCode: http.StatusMethodNotAllowed, |
| 2233 | }, |
| 2234 | } |
| 2235 | |
| 2236 | for _, test := range tests { |
| 2237 | t.Run(test.title, func(t *testing.T) { |
| 2238 | testMethodsSubrouter(t, test) |
| 2239 | }) |
| 2240 | } |
| 2241 | } |
| 2242 | |
| 2243 | // TestMethodsSubrouterStrictSlash matches handlers on subrouters with |
| 2244 | // strict-slash matchers. |
nothing calls this directly
no test coverage detected