|
|
|
|
@ -1017,6 +1017,9 @@ func TestBuildVarsFunc(t *testing.T) {
@@ -1017,6 +1017,9 @@ func TestBuildVarsFunc(t *testing.T) {
|
|
|
|
|
func TestSubRouter(t *testing.T) { |
|
|
|
|
subrouter1 := new(Route).Host("{v1:[a-z]+}.google.com").Subrouter() |
|
|
|
|
subrouter2 := new(Route).PathPrefix("/foo/{v1}").Subrouter() |
|
|
|
|
subrouter3 := new(Route).PathPrefix("/foo").Subrouter() |
|
|
|
|
subrouter4 := new(Route).PathPrefix("/foo/bar").Subrouter() |
|
|
|
|
subrouter5 := new(Route).PathPrefix("/{category}").Subrouter() |
|
|
|
|
|
|
|
|
|
tests := []routeTest{ |
|
|
|
|
{ |
|
|
|
|
@ -1057,6 +1060,61 @@ func TestSubRouter(t *testing.T) {
@@ -1057,6 +1060,61 @@ func TestSubRouter(t *testing.T) {
|
|
|
|
|
pathTemplate: `/foo/{v1}/baz/{v2}`, |
|
|
|
|
shouldMatch: false, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
route: subrouter3.Path("/"), |
|
|
|
|
request: newRequest("GET", "http://localhost/foo/"), |
|
|
|
|
vars: map[string]string{}, |
|
|
|
|
host: "", |
|
|
|
|
path: "/foo/", |
|
|
|
|
pathTemplate: `/foo/`, |
|
|
|
|
shouldMatch: true, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
route: subrouter3.Path(""), |
|
|
|
|
request: newRequest("GET", "http://localhost/foo"), |
|
|
|
|
vars: map[string]string{}, |
|
|
|
|
host: "", |
|
|
|
|
path: "/foo", |
|
|
|
|
pathTemplate: `/foo`, |
|
|
|
|
shouldMatch: true, |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
route: subrouter4.Path("/"), |
|
|
|
|
request: newRequest("GET", "http://localhost/foo/bar/"), |
|
|
|
|
vars: map[string]string{}, |
|
|
|
|
host: "", |
|
|
|
|
path: "/foo/bar/", |
|
|
|
|
pathTemplate: `/foo/bar/`, |
|
|
|
|
shouldMatch: true, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
route: subrouter4.Path(""), |
|
|
|
|
request: newRequest("GET", "http://localhost/foo/bar"), |
|
|
|
|
vars: map[string]string{}, |
|
|
|
|
host: "", |
|
|
|
|
path: "/foo/bar", |
|
|
|
|
pathTemplate: `/foo/bar`, |
|
|
|
|
shouldMatch: true, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
route: subrouter5.Path("/"), |
|
|
|
|
request: newRequest("GET", "http://localhost/baz/"), |
|
|
|
|
vars: map[string]string{"category": "baz"}, |
|
|
|
|
host: "", |
|
|
|
|
path: "/baz/", |
|
|
|
|
pathTemplate: `/{category}/`, |
|
|
|
|
shouldMatch: true, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
route: subrouter5.Path(""), |
|
|
|
|
request: newRequest("GET", "http://localhost/baz"), |
|
|
|
|
vars: map[string]string{"category": "baz"}, |
|
|
|
|
host: "", |
|
|
|
|
path: "/baz", |
|
|
|
|
pathTemplate: `/{category}`, |
|
|
|
|
shouldMatch: true, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for _, test := range tests { |
|
|
|
|
|