| 565 | } |
| 566 | |
| 567 | func TestSubRouting(t *testing.T) { |
| 568 | // Example from docs. |
| 569 | router := NewRouter() |
| 570 | subrouter := router.NewRoute().Host("www.example.com").Subrouter() |
| 571 | route := subrouter.NewRoute().Path("/products/").Name("products") |
| 572 | |
| 573 | url := "http://www.example.com/products/" |
| 574 | request, _ := http.NewRequest("GET", url, nil) |
| 575 | var rv RouteMatch |
| 576 | ok := router.Match(request, &rv) |
| 577 | |
| 578 | if !ok || rv.Route != route { |
| 579 | t.Errorf("Expected same route, got %+v.", rv.Route) |
| 580 | } |
| 581 | |
| 582 | u, _ := router.Get("products").URL() |
| 583 | builtURL := u.String() |
| 584 | // Yay, subroute aware of the domain when building! |
| 585 | if builtURL != url { |
| 586 | t.Errorf("Expected %q, got %q.", url, builtURL) |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | func TestVariableNames(t *testing.T) { |
| 591 | route := new(Route).Host("{arg1}.domain.com").Path("/{arg1}/{arg2:[0-9]+}") |