@@ -35,6 +35,7 @@ type routeTest struct {
35
35
path string // the expected path of the match
36
36
pathTemplate string // the expected path template to match
37
37
hostTemplate string // the expected host template to match
38
+ methods []string // the expected route methods
38
39
pathRegexp string // the expected path regexp
39
40
shouldMatch bool // whether the request is expected to match the route at all
40
41
shouldRedirect bool // whether the request should result in a redirect
@@ -660,6 +661,7 @@ func TestMethods(t *testing.T) {
660
661
vars : map [string ]string {},
661
662
host : "" ,
662
663
path : "" ,
664
+ methods : []string {"GET" , "POST" },
663
665
shouldMatch : true ,
664
666
},
665
667
{
@@ -669,6 +671,7 @@ func TestMethods(t *testing.T) {
669
671
vars : map [string ]string {},
670
672
host : "" ,
671
673
path : "" ,
674
+ methods : []string {"GET" , "POST" },
672
675
shouldMatch : true ,
673
676
},
674
677
{
@@ -678,13 +681,25 @@ func TestMethods(t *testing.T) {
678
681
vars : map [string ]string {},
679
682
host : "" ,
680
683
path : "" ,
684
+ methods : []string {"GET" , "POST" },
681
685
shouldMatch : false ,
682
686
},
687
+ {
688
+ title : "Route without methods" ,
689
+ route : new (Route ),
690
+ request : newRequest ("PUT" , "http://localhost" ),
691
+ vars : map [string ]string {},
692
+ host : "" ,
693
+ path : "" ,
694
+ methods : []string {},
695
+ shouldMatch : true ,
696
+ },
683
697
}
684
698
685
699
for _ , test := range tests {
686
700
testRoute (t , test )
687
701
testTemplate (t , test )
702
+ testMethods (t , test )
688
703
}
689
704
}
690
705
@@ -1512,6 +1527,14 @@ func testTemplate(t *testing.T, test routeTest) {
1512
1527
}
1513
1528
}
1514
1529
1530
+ func testMethods (t * testing.T , test routeTest ) {
1531
+ route := test .route
1532
+ methods , _ := route .GetMethods ()
1533
+ if strings .Join (methods , "," ) != strings .Join (test .methods , "," ) {
1534
+ t .Errorf ("(%v) GetMethods not equal: expected %v, got %v" , test .title , test .methods , methods )
1535
+ }
1536
+ }
1537
+
1515
1538
func testRegexp (t * testing.T , test routeTest ) {
1516
1539
route := test .route
1517
1540
routePathRegexp , regexpErr := route .GetPathRegexp ()
0 commit comments