Skip to content
Myr

Adds more units tests

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Manu Mtz-Almeida · committed by Manu Mtz-Almeida · parent ee021d0 · Browse files · 2 files+29 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+29 added−0 removed

  • other:+29 added−0 removed

2 files+29 added−0 removed

modified:routergroup_test.go+25 added
121 unmodified lines
122 assert.Panics(t, func() {123 router.GET("/", handlers2...)124 })125}126127func TestRouterGroupBadMethod(t *testing.T) {128 router := New()129 assert.Panics(t, func() {130 router.Handle("get", "/")131 })132 assert.Panics(t, func() {133 router.Handle(" GET", "/")134 })135 assert.Panics(t, func() {136 router.Handle("GET ", "/")137 })138 assert.Panics(t, func() {139 router.Handle("", "/")140 })141 assert.Panics(t, func() {142 router.Handle("PO ST", "/")143 })144 assert.Panics(t, func() {145 router.Handle("1GET", "/")146 })147 assert.Panics(t, func() {148 router.Handle("PATCh", "/")149 })150}
modified:routergroup.go+4 added
5 unmodified lines
67import (8 "net/http"9 "path"10 "regexp"11 "strings"12)1314// Used internally to configure router, a RouterGroup is associated with a prefix
35 unmodified lines
50 group.engine.addRoute(httpMethod, absolutePath, handlers)51}5253func (group *RouterGroup) Handle(httpMethod, relativePath string, handlers ...HandlerFunc) {54 if matches, err := regexp.MatchString("^[A-Z]+$", httpMethod); !matches || err != nil {55 panic("http method " + httpMethod + " is not valid")56 }57 group.handle(httpMethod, relativePath, handlers)58}5960// POST is a shortcut for router.Handle("POST", path, handle)
106 unmodified lines