mirror of https://github.com/gin-gonic/gin.git
Testing new Any routing.
This commit is contained in:
parent
a91893d22b
commit
53329e4646
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue