Testing new Any routing.

This commit is contained in:
Manu Mtz-Almeida 2015-05-19 23:00:55 +02:00
parent a91893d22b
commit 53329e4646
2 changed files with 24 additions and 1 deletions

View File

@ -94,6 +94,22 @@ func (group *RouterGroup) UNLINK(relativePath string, handlers ...HandlerFunc) {
group.Handle("UNLINK", relativePath, handlers) group.Handle("UNLINK", relativePath, handlers)
} }
func (group *RouterGroup) Any(relativePath string, handlers ...HandlerFunc) {
// GET, POST, PUT, PATCH, HEAD, OPTIONS, DELETE, CONNECT, WS, LINK, UNLINK, TRACE
group.Handle("GET", relativePath, handlers)
group.Handle("POST", relativePath, handlers)
group.Handle("PUT", relativePath, handlers)
group.Handle("PATCH", relativePath, handlers)
group.Handle("HEAD", relativePath, handlers)
group.Handle("OPTIONS", relativePath, handlers)
group.Handle("DELETE", relativePath, handlers)
group.Handle("CONNECT", relativePath, handlers)
group.Handle("WS", relativePath, handlers)
group.Handle("LINK", relativePath, handlers)
group.Handle("UNLINK", relativePath, handlers)
group.Handle("TRACE", relativePath, handlers)
}
// Static serves files from the given file system root. // Static serves files from the given file system root.
// Internally a http.FileServer is used, therefore http.NotFound is used instead // Internally a http.FileServer is used, therefore http.NotFound is used instead
// of the Router's NotFound handler. // of the Router's NotFound handler.

View File

@ -25,15 +25,22 @@ func performRequest(r http.Handler, method, path string) *httptest.ResponseRecor
func testRouteOK(method string, t *testing.T) { func testRouteOK(method string, t *testing.T) {
passed := false passed := false
passedAny := false
r := New() r := New()
r.Any("/test2", func(c *Context) {
passedAny = true
})
r.Handle(method, "/test", HandlersChain{func(c *Context) { r.Handle(method, "/test", HandlersChain{func(c *Context) {
passed = true passed = true
}}) }})
w := performRequest(r, method, "/test") w := performRequest(r, method, "/test")
assert.True(t, passed) assert.True(t, passed)
assert.Equal(t, w.Code, http.StatusOK) assert.Equal(t, w.Code, http.StatusOK)
performRequest(r, method, "/test2")
assert.True(t, passedAny)
} }
// TestSingleRouteOK tests that POST route is correctly invoked. // TestSingleRouteOK tests that POST route is correctly invoked.