@@ -29,13 +29,13 @@ func (r *routeRegexp) GoString() string {
29
29
type routeTest struct {
30
30
title string // title of the test
31
31
route * Route // the route being tested
32
+ routeBuilder func () * Route // if set, ignore route and call this to build one during test
32
33
request * http.Request // a request to test the route
33
34
vars map [string ]string // the expected vars of the match
34
35
host string // the expected host of the match
35
36
path string // the expected path of the match
36
37
pathTemplate string // the expected path template to match
37
38
hostTemplate string // the expected host template to match
38
- additionalPath string // additional path to add to route (and parse) during test
39
39
shouldMatch bool // whether the request is expected to match the route at all
40
40
shouldRedirect bool // whether the request should result in a redirect
41
41
shouldPanic bool // whether processing should result in a panic
@@ -1397,10 +1397,9 @@ func TestPanicOnCapturingGroups(t *testing.T) {
1397
1397
1398
1398
tests := []routeTest {
1399
1399
{
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 ,
1404
1403
},
1405
1404
{
1406
1405
title : "Test that same example works with non-capturing groups" ,
@@ -1443,17 +1442,16 @@ func testRoute(t *testing.T, test routeTest) {
1443
1442
1444
1443
request := test .request
1445
1444
route := test .route
1445
+ if test .routeBuilder != nil {
1446
+ route = test .routeBuilder ()
1447
+ }
1446
1448
vars := test .vars
1447
1449
shouldMatch := test .shouldMatch
1448
1450
host := test .host
1449
1451
path := test .path
1450
1452
url := test .host + test .path
1451
1453
shouldRedirect := test .shouldRedirect
1452
1454
1453
- if len (test .additionalPath ) != 0 {
1454
- route = route .Path (test .additionalPath )
1455
- }
1456
-
1457
1455
var match RouteMatch
1458
1456
ok := route .Match (request , & match )
1459
1457
if ok != shouldMatch {
0 commit comments