|
|
|
@ -39,8 +39,10 @@ type routeTest struct { |
|
|
|
query string // the expected query string of the built URL
|
|
|
|
query string // the expected query string of the built URL
|
|
|
|
pathTemplate string // the expected path template of the route
|
|
|
|
pathTemplate string // the expected path template of the route
|
|
|
|
hostTemplate string // the expected host template of the route
|
|
|
|
hostTemplate string // the expected host template of the route
|
|
|
|
|
|
|
|
queriesTemplate string // the expected query template of the route
|
|
|
|
methods []string // the expected route methods
|
|
|
|
methods []string // the expected route methods
|
|
|
|
pathRegexp string // the expected path regexp
|
|
|
|
pathRegexp string // the expected path regexp
|
|
|
|
|
|
|
|
queriesRegexp string // the expected query regexp
|
|
|
|
shouldMatch bool // whether the request is expected to match the route at all
|
|
|
|
shouldMatch bool // whether the request is expected to match the route at all
|
|
|
|
shouldRedirect bool // whether the request should result in a redirect
|
|
|
|
shouldRedirect bool // whether the request should result in a redirect
|
|
|
|
} |
|
|
|
} |
|
|
|
@ -746,6 +748,8 @@ func TestQueries(t *testing.T) { |
|
|
|
host: "", |
|
|
|
host: "", |
|
|
|
path: "", |
|
|
|
path: "", |
|
|
|
query: "foo=bar&baz=ding", |
|
|
|
query: "foo=bar&baz=ding", |
|
|
|
|
|
|
|
queriesTemplate: "foo=bar,baz=ding", |
|
|
|
|
|
|
|
queriesRegexp: "^foo=bar$,^baz=ding$", |
|
|
|
shouldMatch: true, |
|
|
|
shouldMatch: true, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -758,6 +762,8 @@ func TestQueries(t *testing.T) { |
|
|
|
query: "foo=bar&baz=ding", |
|
|
|
query: "foo=bar&baz=ding", |
|
|
|
pathTemplate: `/api`, |
|
|
|
pathTemplate: `/api`, |
|
|
|
hostTemplate: `www.example.com`, |
|
|
|
hostTemplate: `www.example.com`, |
|
|
|
|
|
|
|
queriesTemplate: "foo=bar,baz=ding", |
|
|
|
|
|
|
|
queriesRegexp: "^foo=bar$,^baz=ding$", |
|
|
|
shouldMatch: true, |
|
|
|
shouldMatch: true, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -770,6 +776,8 @@ func TestQueries(t *testing.T) { |
|
|
|
query: "foo=bar&baz=ding", |
|
|
|
query: "foo=bar&baz=ding", |
|
|
|
pathTemplate: `/api`, |
|
|
|
pathTemplate: `/api`, |
|
|
|
hostTemplate: `www.example.com`, |
|
|
|
hostTemplate: `www.example.com`, |
|
|
|
|
|
|
|
queriesTemplate: "foo=bar,baz=ding", |
|
|
|
|
|
|
|
queriesRegexp: "^foo=bar$,^baz=ding$", |
|
|
|
shouldMatch: true, |
|
|
|
shouldMatch: true, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -779,6 +787,8 @@ func TestQueries(t *testing.T) { |
|
|
|
vars: map[string]string{}, |
|
|
|
vars: map[string]string{}, |
|
|
|
host: "", |
|
|
|
host: "", |
|
|
|
path: "", |
|
|
|
path: "", |
|
|
|
|
|
|
|
queriesTemplate: "foo=bar,baz=ding", |
|
|
|
|
|
|
|
queriesRegexp: "^foo=bar$,^baz=ding$", |
|
|
|
shouldMatch: false, |
|
|
|
shouldMatch: false, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -789,6 +799,8 @@ func TestQueries(t *testing.T) { |
|
|
|
host: "", |
|
|
|
host: "", |
|
|
|
path: "", |
|
|
|
path: "", |
|
|
|
query: "foo=bar", |
|
|
|
query: "foo=bar", |
|
|
|
|
|
|
|
queriesTemplate: "foo={v1}", |
|
|
|
|
|
|
|
queriesRegexp: "^foo=(?P<v0>.*)$", |
|
|
|
shouldMatch: true, |
|
|
|
shouldMatch: true, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -799,6 +811,8 @@ func TestQueries(t *testing.T) { |
|
|
|
host: "", |
|
|
|
host: "", |
|
|
|
path: "", |
|
|
|
path: "", |
|
|
|
query: "foo=bar&baz=ding", |
|
|
|
query: "foo=bar&baz=ding", |
|
|
|
|
|
|
|
queriesTemplate: "foo={v1},baz={v2}", |
|
|
|
|
|
|
|
queriesRegexp: "^foo=(?P<v0>.*)$,^baz=(?P<v0>.*)$", |
|
|
|
shouldMatch: true, |
|
|
|
shouldMatch: true, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -809,6 +823,8 @@ func TestQueries(t *testing.T) { |
|
|
|
host: "", |
|
|
|
host: "", |
|
|
|
path: "", |
|
|
|
path: "", |
|
|
|
query: "foo=10", |
|
|
|
query: "foo=10", |
|
|
|
|
|
|
|
queriesTemplate: "foo={v1:[0-9]+}", |
|
|
|
|
|
|
|
queriesRegexp: "^foo=(?P<v0>[0-9]+)$", |
|
|
|
shouldMatch: true, |
|
|
|
shouldMatch: true, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -818,6 +834,8 @@ func TestQueries(t *testing.T) { |
|
|
|
vars: map[string]string{}, |
|
|
|
vars: map[string]string{}, |
|
|
|
host: "", |
|
|
|
host: "", |
|
|
|
path: "", |
|
|
|
path: "", |
|
|
|
|
|
|
|
queriesTemplate: "foo={v1:[0-9]+}", |
|
|
|
|
|
|
|
queriesRegexp: "^foo=(?P<v0>[0-9]+)$", |
|
|
|
shouldMatch: false, |
|
|
|
shouldMatch: false, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -828,6 +846,8 @@ func TestQueries(t *testing.T) { |
|
|
|
host: "", |
|
|
|
host: "", |
|
|
|
path: "", |
|
|
|
path: "", |
|
|
|
query: "foo=1", |
|
|
|
query: "foo=1", |
|
|
|
|
|
|
|
queriesTemplate: "foo={v1:[0-9]{1}}", |
|
|
|
|
|
|
|
queriesRegexp: "^foo=(?P<v0>[0-9]{1})$", |
|
|
|
shouldMatch: true, |
|
|
|
shouldMatch: true, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -838,6 +858,8 @@ func TestQueries(t *testing.T) { |
|
|
|
host: "", |
|
|
|
host: "", |
|
|
|
path: "", |
|
|
|
path: "", |
|
|
|
query: "foo=1", |
|
|
|
query: "foo=1", |
|
|
|
|
|
|
|
queriesTemplate: "foo={v1:[0-9]{1}}", |
|
|
|
|
|
|
|
queriesRegexp: "^foo=(?P<v0>[0-9]{1})$", |
|
|
|
shouldMatch: true, |
|
|
|
shouldMatch: true, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -847,6 +869,8 @@ func TestQueries(t *testing.T) { |
|
|
|
vars: map[string]string{}, |
|
|
|
vars: map[string]string{}, |
|
|
|
host: "", |
|
|
|
host: "", |
|
|
|
path: "", |
|
|
|
path: "", |
|
|
|
|
|
|
|
queriesTemplate: "foo={v1:[0-9]{1}}", |
|
|
|
|
|
|
|
queriesRegexp: "^foo=(?P<v0>[0-9]{1})$", |
|
|
|
shouldMatch: false, |
|
|
|
shouldMatch: false, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -857,6 +881,8 @@ func TestQueries(t *testing.T) { |
|
|
|
host: "", |
|
|
|
host: "", |
|
|
|
path: "", |
|
|
|
path: "", |
|
|
|
query: "foo=1a", |
|
|
|
query: "foo=1a", |
|
|
|
|
|
|
|
queriesTemplate: "foo={v1:[0-9]{1}(?:a|b)}", |
|
|
|
|
|
|
|
queriesRegexp: "^foo=(?P<v0>[0-9]{1}(?:a|b))$", |
|
|
|
shouldMatch: true, |
|
|
|
shouldMatch: true, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -866,6 +892,8 @@ func TestQueries(t *testing.T) { |
|
|
|
vars: map[string]string{}, |
|
|
|
vars: map[string]string{}, |
|
|
|
host: "", |
|
|
|
host: "", |
|
|
|
path: "", |
|
|
|
path: "", |
|
|
|
|
|
|
|
queriesTemplate: "foo={v1:[0-9]{1}}", |
|
|
|
|
|
|
|
queriesRegexp: "^foo=(?P<v0>[0-9]{1})$", |
|
|
|
shouldMatch: false, |
|
|
|
shouldMatch: false, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -876,6 +904,8 @@ func TestQueries(t *testing.T) { |
|
|
|
host: "", |
|
|
|
host: "", |
|
|
|
path: "", |
|
|
|
path: "", |
|
|
|
query: "foo=bar", |
|
|
|
query: "foo=bar", |
|
|
|
|
|
|
|
queriesTemplate: "foo={v-1}", |
|
|
|
|
|
|
|
queriesRegexp: "^foo=(?P<v0>.*)$", |
|
|
|
shouldMatch: true, |
|
|
|
shouldMatch: true, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -886,6 +916,8 @@ func TestQueries(t *testing.T) { |
|
|
|
host: "", |
|
|
|
host: "", |
|
|
|
path: "", |
|
|
|
path: "", |
|
|
|
query: "foo=bar&baz=ding", |
|
|
|
query: "foo=bar&baz=ding", |
|
|
|
|
|
|
|
queriesTemplate: "foo={v-1},baz={v-2}", |
|
|
|
|
|
|
|
queriesRegexp: "^foo=(?P<v0>.*)$,^baz=(?P<v0>.*)$", |
|
|
|
shouldMatch: true, |
|
|
|
shouldMatch: true, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -896,6 +928,8 @@ func TestQueries(t *testing.T) { |
|
|
|
host: "", |
|
|
|
host: "", |
|
|
|
path: "", |
|
|
|
path: "", |
|
|
|
query: "foo=10", |
|
|
|
query: "foo=10", |
|
|
|
|
|
|
|
queriesTemplate: "foo={v-1:[0-9]+}", |
|
|
|
|
|
|
|
queriesRegexp: "^foo=(?P<v0>[0-9]+)$", |
|
|
|
shouldMatch: true, |
|
|
|
shouldMatch: true, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -906,6 +940,8 @@ func TestQueries(t *testing.T) { |
|
|
|
host: "", |
|
|
|
host: "", |
|
|
|
path: "", |
|
|
|
path: "", |
|
|
|
query: "foo=1a", |
|
|
|
query: "foo=1a", |
|
|
|
|
|
|
|
queriesTemplate: "foo={v-1:[0-9]{1}(?:a|b)}", |
|
|
|
|
|
|
|
queriesRegexp: "^foo=(?P<v0>[0-9]{1}(?:a|b))$", |
|
|
|
shouldMatch: true, |
|
|
|
shouldMatch: true, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -916,6 +952,8 @@ func TestQueries(t *testing.T) { |
|
|
|
host: "", |
|
|
|
host: "", |
|
|
|
path: "", |
|
|
|
path: "", |
|
|
|
query: "foo=", |
|
|
|
query: "foo=", |
|
|
|
|
|
|
|
queriesTemplate: "foo=", |
|
|
|
|
|
|
|
queriesRegexp: "^foo=.*$", |
|
|
|
shouldMatch: true, |
|
|
|
shouldMatch: true, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -925,6 +963,8 @@ func TestQueries(t *testing.T) { |
|
|
|
vars: map[string]string{}, |
|
|
|
vars: map[string]string{}, |
|
|
|
host: "", |
|
|
|
host: "", |
|
|
|
path: "", |
|
|
|
path: "", |
|
|
|
|
|
|
|
queriesTemplate: "foo=", |
|
|
|
|
|
|
|
queriesRegexp: "^foo=.*$", |
|
|
|
shouldMatch: false, |
|
|
|
shouldMatch: false, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -935,6 +975,8 @@ func TestQueries(t *testing.T) { |
|
|
|
host: "", |
|
|
|
host: "", |
|
|
|
path: "", |
|
|
|
path: "", |
|
|
|
query: "foo=", |
|
|
|
query: "foo=", |
|
|
|
|
|
|
|
queriesTemplate: "foo=", |
|
|
|
|
|
|
|
queriesRegexp: "^foo=.*$", |
|
|
|
shouldMatch: true, |
|
|
|
shouldMatch: true, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -944,6 +986,8 @@ func TestQueries(t *testing.T) { |
|
|
|
vars: map[string]string{}, |
|
|
|
vars: map[string]string{}, |
|
|
|
host: "", |
|
|
|
host: "", |
|
|
|
path: "", |
|
|
|
path: "", |
|
|
|
|
|
|
|
queriesTemplate: "foo=bar", |
|
|
|
|
|
|
|
queriesRegexp: "^foo=bar$", |
|
|
|
shouldMatch: false, |
|
|
|
shouldMatch: false, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -953,6 +997,8 @@ func TestQueries(t *testing.T) { |
|
|
|
vars: map[string]string{}, |
|
|
|
vars: map[string]string{}, |
|
|
|
host: "", |
|
|
|
host: "", |
|
|
|
path: "", |
|
|
|
path: "", |
|
|
|
|
|
|
|
queriesTemplate: "foo={bar}", |
|
|
|
|
|
|
|
queriesRegexp: "^foo=(?P<v0>.*)$", |
|
|
|
shouldMatch: false, |
|
|
|
shouldMatch: false, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -963,6 +1009,8 @@ func TestQueries(t *testing.T) { |
|
|
|
host: "", |
|
|
|
host: "", |
|
|
|
path: "", |
|
|
|
path: "", |
|
|
|
query: "foo=", |
|
|
|
query: "foo=", |
|
|
|
|
|
|
|
queriesTemplate: "foo={bar}", |
|
|
|
|
|
|
|
queriesRegexp: "^foo=(?P<v0>.*)$", |
|
|
|
shouldMatch: true, |
|
|
|
shouldMatch: true, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -972,6 +1020,8 @@ func TestQueries(t *testing.T) { |
|
|
|
vars: map[string]string{}, |
|
|
|
vars: map[string]string{}, |
|
|
|
host: "", |
|
|
|
host: "", |
|
|
|
path: "", |
|
|
|
path: "", |
|
|
|
|
|
|
|
queriesTemplate: "foo=bar,baz=ding", |
|
|
|
|
|
|
|
queriesRegexp: "^foo=bar$,^baz=ding$", |
|
|
|
shouldMatch: false, |
|
|
|
shouldMatch: false, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -982,6 +1032,8 @@ func TestQueries(t *testing.T) { |
|
|
|
host: "", |
|
|
|
host: "", |
|
|
|
path: "", |
|
|
|
path: "", |
|
|
|
query: "foo=%25bar%26+%2F%3D%3F", |
|
|
|
query: "foo=%25bar%26+%2F%3D%3F", |
|
|
|
|
|
|
|
queriesTemplate: "foo={v1}", |
|
|
|
|
|
|
|
queriesRegexp: "^foo=(?P<v0>.*)$", |
|
|
|
shouldMatch: true, |
|
|
|
shouldMatch: true, |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
|
@ -989,7 +1041,9 @@ func TestQueries(t *testing.T) { |
|
|
|
for _, test := range tests { |
|
|
|
for _, test := range tests { |
|
|
|
testRoute(t, test) |
|
|
|
testRoute(t, test) |
|
|
|
testTemplate(t, test) |
|
|
|
testTemplate(t, test) |
|
|
|
|
|
|
|
testQueriesTemplates(t, test) |
|
|
|
testUseEscapedRoute(t, test) |
|
|
|
testUseEscapedRoute(t, test) |
|
|
|
|
|
|
|
testQueriesRegexp(t, test) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -1717,6 +1771,24 @@ func testRegexp(t *testing.T, test routeTest) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func testQueriesRegexp(t *testing.T, test routeTest) { |
|
|
|
|
|
|
|
route := test.route |
|
|
|
|
|
|
|
queries, queriesErr := route.GetQueriesRegexp() |
|
|
|
|
|
|
|
gotQueries := strings.Join(queries, ",") |
|
|
|
|
|
|
|
if test.queriesRegexp != "" && queriesErr == nil && gotQueries != test.queriesRegexp { |
|
|
|
|
|
|
|
t.Errorf("(%v) GetQueriesRegexp not equal: expected %v, got %v", test.title, test.queriesRegexp, gotQueries) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func testQueriesTemplates(t *testing.T, test routeTest) { |
|
|
|
|
|
|
|
route := test.route |
|
|
|
|
|
|
|
queries, queriesErr := route.GetQueriesTemplates() |
|
|
|
|
|
|
|
gotQueries := strings.Join(queries, ",") |
|
|
|
|
|
|
|
if test.queriesTemplate != "" && queriesErr == nil && gotQueries != test.queriesTemplate { |
|
|
|
|
|
|
|
t.Errorf("(%v) GetQueriesTemplates not equal: expected %v, got %v", test.title, test.queriesTemplate, gotQueries) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type TestA301ResponseWriter struct { |
|
|
|
type TestA301ResponseWriter struct { |
|
|
|
hh http.Header |
|
|
|
hh http.Header |
|
|
|
status int |
|
|
|
status int |
|
|
|
|