From 53329e46464d83189a9df401ab3882257064c0db Mon Sep 17 00:00:00 2001 From: Manu Mtz-Almeida Date: Tue, 19 May 2015 23:00:55 +0200 Subject: [PATCH] Testing new Any routing. --- routergroup.go | 16 ++++++++++++++++ routes_test.go | 9 ++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/routergroup.go b/routergroup.go index 09791dc..7d182ce 100644 --- a/routergroup.go +++ b/routergroup.go @@ -94,6 +94,22 @@ func (group *RouterGroup) UNLINK(relativePath string, handlers ...HandlerFunc) { 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. // Internally a http.FileServer is used, therefore http.NotFound is used instead // of the Router's NotFound handler. diff --git a/routes_test.go b/routes_test.go index 12b5510..4a5543d 100644 --- a/routes_test.go +++ b/routes_test.go @@ -25,15 +25,22 @@ func performRequest(r http.Handler, method, path string) *httptest.ResponseRecor func testRouteOK(method string, t *testing.T) { passed := false + passedAny := false r := New() + r.Any("/test2", func(c *Context) { + passedAny = true + }) r.Handle(method, "/test", HandlersChain{func(c *Context) { passed = true }}) w := performRequest(r, method, "/test") - assert.True(t, passed) assert.Equal(t, w.Code, http.StatusOK) + + performRequest(r, method, "/test2") + assert.True(t, passedAny) + } // TestSingleRouteOK tests that POST route is correctly invoked.