Skip to content

Commit 821135a

Browse files
committed
More generic change to test.
1 parent bd6899d commit 821135a

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

mux_test.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ func (r *routeRegexp) GoString() string {
2929
type routeTest struct {
3030
title string // title of the test
3131
route *Route // the route being tested
32+
routeBuilder func() *Route // if set, ignore route and call this to build one during test
3233
request *http.Request // a request to test the route
3334
vars map[string]string // the expected vars of the match
3435
host string // the expected host of the match
3536
path string // the expected path of the match
3637
pathTemplate string // the expected path template to match
3738
hostTemplate string // the expected host template to match
38-
additionalPath string // additional path to add to route (and parse) during test
3939
shouldMatch bool // whether the request is expected to match the route at all
4040
shouldRedirect bool // whether the request should result in a redirect
4141
shouldPanic bool // whether processing should result in a panic
@@ -1397,10 +1397,9 @@ func TestPanicOnCapturingGroups(t *testing.T) {
13971397

13981398
tests := []routeTest{
13991399
{
1400-
title: "Test that capturing groups now fail fast",
1401-
route: r.NewRoute(),
1402-
additionalPath: "/{type:(promo|special)}/{promoId}.json",
1403-
shouldPanic: true,
1400+
title: "Test that capturing groups now fail fast",
1401+
routeBuilder: func() *Route { return r.NewRoute().Path("/{type:(promo|special)}/{promoId}.json") },
1402+
shouldPanic: true,
14041403
},
14051404
{
14061405
title: "Test that same example works with non-capturing groups",
@@ -1443,17 +1442,16 @@ func testRoute(t *testing.T, test routeTest) {
14431442

14441443
request := test.request
14451444
route := test.route
1445+
if test.routeBuilder != nil {
1446+
route = test.routeBuilder()
1447+
}
14461448
vars := test.vars
14471449
shouldMatch := test.shouldMatch
14481450
host := test.host
14491451
path := test.path
14501452
url := test.host + test.path
14511453
shouldRedirect := test.shouldRedirect
14521454

1453-
if len(test.additionalPath) != 0 {
1454-
route = route.Path(test.additionalPath)
1455-
}
1456-
14571455
var match RouteMatch
14581456
ok := route.Match(request, &match)
14591457
if ok != shouldMatch {

0 commit comments

Comments
 (0)