(t *testing.T)
| 2502 | } |
| 2503 | |
| 2504 | func TestSubrouterMatching(t *testing.T) { |
| 2505 | const ( |
| 2506 | none, stdOnly, subOnly uint8 = 0, 1 << 0, 1 << 1 |
| 2507 | both = subOnly | stdOnly |
| 2508 | ) |
| 2509 | |
| 2510 | type request struct { |
| 2511 | Name string |
| 2512 | Request *http.Request |
| 2513 | Flags uint8 |
| 2514 | } |
| 2515 | |
| 2516 | cases := []struct { |
| 2517 | Name string |
| 2518 | Standard, Subrouter func(*Router) |
| 2519 | Requests []request |
| 2520 | }{ |
| 2521 | { |
| 2522 | "pathPrefix", |
| 2523 | func(r *Router) { |
| 2524 | r.PathPrefix("/before").PathPrefix("/after") |
| 2525 | }, |
| 2526 | func(r *Router) { |
| 2527 | r.PathPrefix("/before").Subrouter().PathPrefix("/after") |
| 2528 | }, |
| 2529 | []request{ |
| 2530 | {"no match final path prefix", newRequest("GET", "/after"), none}, |
| 2531 | {"no match parent path prefix", newRequest("GET", "/before"), none}, |
| 2532 | {"matches append", newRequest("GET", "/before/after"), both}, |
| 2533 | {"matches as prefix", newRequest("GET", "/before/after/1234"), both}, |
| 2534 | }, |
| 2535 | }, |
| 2536 | { |
| 2537 | "path", |
| 2538 | func(r *Router) { |
| 2539 | r.Path("/before").Path("/after") |
| 2540 | }, |
| 2541 | func(r *Router) { |
| 2542 | r.Path("/before").Subrouter().Path("/after") |
| 2543 | }, |
| 2544 | []request{ |
| 2545 | {"no match subroute path", newRequest("GET", "/after"), none}, |
| 2546 | {"no match parent path", newRequest("GET", "/before"), none}, |
| 2547 | {"no match as prefix", newRequest("GET", "/before/after/1234"), none}, |
| 2548 | {"no match append", newRequest("GET", "/before/after"), none}, |
| 2549 | }, |
| 2550 | }, |
| 2551 | { |
| 2552 | "host", |
| 2553 | func(r *Router) { |
| 2554 | r.Host("before.com").Host("after.com") |
| 2555 | }, |
| 2556 | func(r *Router) { |
| 2557 | r.Host("before.com").Subrouter().Host("after.com") |
| 2558 | }, |
| 2559 | []request{ |
| 2560 | {"no match before", newRequestHost("GET", "/", "before.com"), none}, |
| 2561 | {"no match other", newRequestHost("GET", "/", "other.com"), none}, |
nothing calls this directly
no test coverage detected