-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter_test.go
43 lines (35 loc) · 938 Bytes
/
router_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package looli
import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewRouter(t *testing.T) {
router := NewRouter()
assert.True(t, router.TrailingSlashRedirect)
assert.NotNil(t, router.allowMethods)
assert.NotNil(t, router.tree)
assert.NotNil(t, router.tree.children)
assert.NotNil(t, router.tree.handlers)
}
func TestAddhandlers(t *testing.T) {
router := NewRouter()
router.Handle(http.MethodGet, "/", []HandlerFunc{func(c *Context) {}})
assert.Panics(t, func() {
router.Handle(http.MethodGet, "/", []HandlerFunc{func(c *Context) {}})
})
}
func TestRouterHandle(t *testing.T) {
router := &Router{
TrailingSlashRedirect: true,
allowMethods: make(map[string]bool),
IgnoreCase: true,
}
assert.Panics(t, func() {
router.Handle(http.MethodGet, "a", nil)
})
assert.Panics(t, func() {
router.Handle("", "/a", nil)
})
router.Handle(http.MethodGet, "/a", nil)
}