MCPcopy
hub / github.com/gorilla/mux / TestMethodsSubrouterPathPrefix

Function TestMethodsSubrouterPathPrefix

mux_test.go:2303–2348  ·  view source on GitHub ↗

TestMethodsSubrouterPathPrefix matches handlers on subrouters created on a router with a path prefix matcher and method matcher.

(t *testing.T)

Source from the content-addressed store, hash-verified

2301// TestMethodsSubrouterPathPrefix matches handlers on subrouters created
2302// on a router with a path prefix matcher and method matcher.
2303func TestMethodsSubrouterPathPrefix(t *testing.T) {
2304 t.Parallel()
2305
2306 router := NewRouter()
2307 router.PathPrefix("/1").Methods("POST").Subrouter().HandleFunc("/2", methodHandler("POST"))
2308 router.PathPrefix("/1").Methods("DELETE").Subrouter().HandleFunc("/2", methodHandler("DELETE"))
2309 router.PathPrefix("/1").Methods("PUT").Subrouter().HandleFunc("/2", methodHandler("PUT"))
2310 router.PathPrefix("/1").Methods("POST").Subrouter().HandleFunc("/2", methodHandler("POST2"))
2311
2312 tests := []methodsSubrouterTest{
2313 {
2314 title: "match first POST handler",
2315 router: router,
2316 method: "POST",
2317 path: "http://localhost/1/2",
2318 wantCode: http.StatusOK,
2319 },
2320 {
2321 title: "match DELETE handler",
2322 router: router,
2323 method: "DELETE",
2324 path: "http://localhost/1/2",
2325 wantCode: http.StatusOK,
2326 },
2327 {
2328 title: "match PUT handler",
2329 router: router,
2330 method: "PUT",
2331 path: "http://localhost/1/2",
2332 wantCode: http.StatusOK,
2333 },
2334 {
2335 title: "disallow PATCH method",
2336 router: router,
2337 method: "PATCH",
2338 path: "http://localhost/1/2",
2339 wantCode: http.StatusMethodNotAllowed,
2340 },
2341 }
2342
2343 for _, test := range tests {
2344 t.Run(test.title, func(t *testing.T) {
2345 testMethodsSubrouter(t, test)
2346 })
2347 }
2348}
2349
2350// TestMethodsSubrouterSubrouter matches handlers on subrouters produced
2351// from method matchers registered on a root subrouter.

Callers

nothing calls this directly

Calls 7

PathPrefixMethod · 0.95
NewRouterFunction · 0.85
methodHandlerFunction · 0.85
testMethodsSubrouterFunction · 0.85
HandleFuncMethod · 0.80
SubrouterMethod · 0.80
MethodsMethod · 0.45

Tested by

no test coverage detected