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

Function TestSubRouting

old_test.go:567–588  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

565}
566
567func 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
590func TestVariableNames(t *testing.T) {
591 route := new(Route).Host("{arg1}.domain.com").Path("/{arg1}/{arg2:[0-9]+}")

Callers

nothing calls this directly

Calls 9

NewRouteMethod · 0.95
MatchMethod · 0.95
GetMethod · 0.95
NewRouterFunction · 0.85
SubrouterMethod · 0.80
URLMethod · 0.80
HostMethod · 0.45
NameMethod · 0.45
PathMethod · 0.45

Tested by

no test coverage detected