Adds more units tests
This commit is contained in:
parent
ee021d06ea
commit
92475baba6
@ -7,6 +7,7 @@ package gin
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"path"
|
"path"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -50,6 +51,9 @@ func (group *RouterGroup) handle(httpMethod, relativePath string, handlers Handl
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (group *RouterGroup) Handle(httpMethod, relativePath string, handlers ...HandlerFunc) {
|
func (group *RouterGroup) Handle(httpMethod, relativePath string, handlers ...HandlerFunc) {
|
||||||
|
if matches, err := regexp.MatchString("^[A-Z]+$", httpMethod); !matches || err != nil {
|
||||||
|
panic("http method " + httpMethod + " is not valid")
|
||||||
|
}
|
||||||
group.handle(httpMethod, relativePath, handlers)
|
group.handle(httpMethod, relativePath, handlers)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,3 +123,28 @@ func TestRouterGroupTooManyHandlers(t *testing.T) {
|
|||||||
router.GET("/", handlers2...)
|
router.GET("/", handlers2...)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRouterGroupBadMethod(t *testing.T) {
|
||||||
|
router := New()
|
||||||
|
assert.Panics(t, func() {
|
||||||
|
router.Handle("get", "/")
|
||||||
|
})
|
||||||
|
assert.Panics(t, func() {
|
||||||
|
router.Handle(" GET", "/")
|
||||||
|
})
|
||||||
|
assert.Panics(t, func() {
|
||||||
|
router.Handle("GET ", "/")
|
||||||
|
})
|
||||||
|
assert.Panics(t, func() {
|
||||||
|
router.Handle("", "/")
|
||||||
|
})
|
||||||
|
assert.Panics(t, func() {
|
||||||
|
router.Handle("PO ST", "/")
|
||||||
|
})
|
||||||
|
assert.Panics(t, func() {
|
||||||
|
router.Handle("1GET", "/")
|
||||||
|
})
|
||||||
|
assert.Panics(t, func() {
|
||||||
|
router.Handle("PATCh", "/")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user