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

Function TestWalkSubrouters

mux_test.go:1673–1699  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1671}
1672
1673func TestWalkSubrouters(t *testing.T) {
1674 router := NewRouter()
1675
1676 g := router.Path("/g").Subrouter()
1677 o := g.PathPrefix("/o").Subrouter()
1678 o.Methods("GET")
1679 o.Methods("PUT")
1680
1681 // all 4 routes should be matched
1682 paths := []string{"/g", "/g/o", "/g/o", "/g/o"}
1683 idx := 0
1684 err := router.Walk(func(route *Route, router *Router, ancestors []*Route) error {
1685 path := paths[idx]
1686 tpl, _ := route.GetPathTemplate()
1687 if tpl != path {
1688 t.Errorf(`Expected %s got %s`, path, tpl)
1689 }
1690 idx++
1691 return nil
1692 })
1693 if err != nil {
1694 panic(err)
1695 }
1696 if idx != len(paths) {
1697 t.Errorf("Expected %d routes, found %d", len(paths), idx)
1698 }
1699}
1700
1701func TestWalkErrorRoute(t *testing.T) {
1702 router := NewRouter()

Callers

nothing calls this directly

Calls 7

PathMethod · 0.95
WalkMethod · 0.95
NewRouterFunction · 0.85
SubrouterMethod · 0.80
GetPathTemplateMethod · 0.80
PathPrefixMethod · 0.45
MethodsMethod · 0.45

Tested by

no test coverage detected