Added method Route.GetMethods

This commit is contained in:
Bulat Gaifullin
2017-04-18 09:52:32 +03:00
committed by Kamil Kisiel
parent 1856953e53
commit b552615e22
2 changed files with 39 additions and 0 deletions

View File

@@ -35,6 +35,7 @@ type routeTest struct {
path string // the expected path of the match
pathTemplate string // the expected path template to match
hostTemplate string // the expected host template to match
methods []string // the expected route methods
pathRegexp string // the expected path regexp
shouldMatch bool // whether the request is expected to match the route at all
shouldRedirect bool // whether the request should result in a redirect
@@ -660,6 +661,7 @@ func TestMethods(t *testing.T) {
vars: map[string]string{},
host: "",
path: "",
methods: []string{"GET", "POST"},
shouldMatch: true,
},
{
@@ -669,6 +671,7 @@ func TestMethods(t *testing.T) {
vars: map[string]string{},
host: "",
path: "",
methods: []string{"GET", "POST"},
shouldMatch: true,
},
{
@@ -678,13 +681,25 @@ func TestMethods(t *testing.T) {
vars: map[string]string{},
host: "",
path: "",
methods: []string{"GET", "POST"},
shouldMatch: false,
},
{
title: "Route without methods",
route: new(Route),
request: newRequest("PUT", "http://localhost"),
vars: map[string]string{},
host: "",
path: "",
methods: []string{},
shouldMatch: true,
},
}
for _, test := range tests {
testRoute(t, test)
testTemplate(t, test)
testMethods(t, test)
}
}
@@ -1512,6 +1527,14 @@ func testTemplate(t *testing.T, test routeTest) {
}
}
func testMethods(t *testing.T, test routeTest) {
route := test.route
methods, _ := route.GetMethods()
if strings.Join(methods, ",") != strings.Join(test.methods, ",") {
t.Errorf("(%v) GetMethods not equal: expected %v, got %v", test.title, test.methods, methods)
}
}
func testRegexp(t *testing.T, test routeTest) {
route := test.route
routePathRegexp, regexpErr := route.GetPathRegexp()