-
Notifications
You must be signed in to change notification settings - Fork 124
/
invalid_setup_test.go
93 lines (71 loc) · 1.84 KB
/
invalid_setup_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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package web
import (
"github.com/stretchr/testify/assert"
"testing"
)
func (c *Context) InvalidHandler() {}
func (c *Context) InvalidHandler2(w ResponseWriter, r *Request) string { return "" }
func (c *Context) InvalidHandler3(w ResponseWriter, r ResponseWriter) {}
type invalidSubcontext struct{}
func (c *invalidSubcontext) Handler(w ResponseWriter, r *Request) {}
type invalidSubcontext2 struct {
*invalidSubcontext
}
func TestInvalidContext(t *testing.T) {
assert.Panics(t, func() {
New(1)
})
assert.Panics(t, func() {
router := New(Context{})
router.Subrouter(invalidSubcontext{}, "")
})
assert.Panics(t, func() {
router := New(Context{})
router.Subrouter(invalidSubcontext2{}, "")
})
}
func TestInvalidHandler(t *testing.T) {
router := New(Context{})
assert.Panics(t, func() {
router.Get("/action", 1)
})
assert.Panics(t, func() {
router.Get("/action", (*Context).InvalidHandler)
})
// Returns a string:
assert.Panics(t, func() {
router.Get("/action", (*Context).InvalidHandler2)
})
// Two writer inputs:
assert.Panics(t, func() {
router.Get("/action", (*Context).InvalidHandler3)
})
// Wrong context type:
assert.Panics(t, func() {
router.Get("/action", (*invalidSubcontext).Handler)
})
//
}
func TestInvalidMiddleware(t *testing.T) {
router := New(Context{})
assert.Panics(t, func() {
router.Middleware((*Context).InvalidHandler)
})
}
func TestInvalidNotFound(t *testing.T) {
router := New(Context{})
assert.Panics(t, func() {
router.NotFound((*Context).InvalidHandler)
})
// Valid handler not on main router:
subrouter := router.Subrouter(Context{}, "")
assert.Panics(t, func() {
subrouter.NotFound((*Context).A)
})
}
func TestInvalidError(t *testing.T) {
router := New(Context{})
assert.Panics(t, func() {
router.Error((*Context).InvalidHandler)
})
}