(t *testing.T)
| 1621 | } |
| 1622 | |
| 1623 | func TestWalkNested(t *testing.T) { |
| 1624 | router := NewRouter() |
| 1625 | |
| 1626 | routeSubrouter := func(r *Route) (*Route, *Router) { |
| 1627 | return r, r.Subrouter() |
| 1628 | } |
| 1629 | |
| 1630 | gRoute, g := routeSubrouter(router.Path("/g")) |
| 1631 | oRoute, o := routeSubrouter(g.PathPrefix("/o")) |
| 1632 | rRoute, r := routeSubrouter(o.PathPrefix("/r")) |
| 1633 | iRoute, i := routeSubrouter(r.PathPrefix("/i")) |
| 1634 | l1Route, l1 := routeSubrouter(i.PathPrefix("/l")) |
| 1635 | l2Route, l2 := routeSubrouter(l1.PathPrefix("/l")) |
| 1636 | l2.Path("/a") |
| 1637 | |
| 1638 | testCases := []struct { |
| 1639 | path string |
| 1640 | ancestors []*Route |
| 1641 | }{ |
| 1642 | {"/g", []*Route{}}, |
| 1643 | {"/g/o", []*Route{gRoute}}, |
| 1644 | {"/g/o/r", []*Route{gRoute, oRoute}}, |
| 1645 | {"/g/o/r/i", []*Route{gRoute, oRoute, rRoute}}, |
| 1646 | {"/g/o/r/i/l", []*Route{gRoute, oRoute, rRoute, iRoute}}, |
| 1647 | {"/g/o/r/i/l/l", []*Route{gRoute, oRoute, rRoute, iRoute, l1Route}}, |
| 1648 | {"/g/o/r/i/l/l/a", []*Route{gRoute, oRoute, rRoute, iRoute, l1Route, l2Route}}, |
| 1649 | } |
| 1650 | |
| 1651 | idx := 0 |
| 1652 | err := router.Walk(func(route *Route, router *Router, ancestors []*Route) error { |
| 1653 | path := testCases[idx].path |
| 1654 | tpl := route.regexp.path.template |
| 1655 | if tpl != path { |
| 1656 | t.Errorf(`Expected %s got %s`, path, tpl) |
| 1657 | } |
| 1658 | currWantAncestors := testCases[idx].ancestors |
| 1659 | if !reflect.DeepEqual(currWantAncestors, ancestors) { |
| 1660 | t.Errorf(`Expected %+v got %+v`, currWantAncestors, ancestors) |
| 1661 | } |
| 1662 | idx++ |
| 1663 | return nil |
| 1664 | }) |
| 1665 | if err != nil { |
| 1666 | panic(err) |
| 1667 | } |
| 1668 | if idx != len(testCases) { |
| 1669 | t.Errorf("Expected %d routes, found %d", len(testCases), idx) |
| 1670 | } |
| 1671 | } |
| 1672 | |
| 1673 | func TestWalkSubrouters(t *testing.T) { |
| 1674 | router := NewRouter() |
nothing calls this directly
no test coverage detected