-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions_test.go
102 lines (68 loc) · 1.95 KB
/
options_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
94
95
96
97
98
99
100
101
102
package kid
import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
type mockEverything struct{}
func (*mockEverything) RenderHTML(res http.ResponseWriter, path string, data any) {}
func (*mockEverything) Write(w http.ResponseWriter, in any, indent string) {}
func (*mockEverything) Read(req *http.Request, out any) error {
return nil
}
func TestWithDebug(t *testing.T) {
k := New()
opt := WithDebug(true)
opt.apply(k)
assert.True(t, k.Debug())
}
func TestWithHTMLRenderer(t *testing.T) {
k := New()
assert.PanicsWithValue(t, "renderer cannot be nil", func() {
WithHTMLRenderer(nil)
})
renderer := &mockEverything{}
opt := WithHTMLRenderer(renderer)
opt.apply(k)
assert.Equal(t, renderer, k.htmlRenderer)
}
func TestWithXMLSerializer(t *testing.T) {
k := New()
assert.PanicsWithValue(t, "xml serializer cannot be nil", func() {
WithXMLSerializer(nil)
})
serializer := &mockEverything{}
opt := WithXMLSerializer(serializer)
opt.apply(k)
assert.Equal(t, serializer, k.xmlSerializer)
}
func TestWithJSONSerializer(t *testing.T) {
k := New()
assert.PanicsWithValue(t, "json serializer cannot be nil", func() {
WithJSONSerializer(nil)
})
serializer := &mockEverything{}
opt := WithJSONSerializer(serializer)
opt.apply(k)
assert.Equal(t, serializer, k.jsonSerializer)
}
func TestWithNotFoundHandler(t *testing.T) {
k := New()
assert.PanicsWithValue(t, "not found handler cannot be nil", func() {
WithNotFoundHandler(nil)
})
hanlder := func(c *Context) {}
opt := WithNotFoundHandler(hanlder)
opt.apply(k)
assert.True(t, funcsAreEqual(hanlder, k.notFoundHandler))
}
func TestWithMethodNotAllowedHandler(t *testing.T) {
k := New()
assert.PanicsWithValue(t, "method not allowed handler cannot be nil", func() {
WithMethodNotAllowedHandler(nil)
})
hanlder := func(c *Context) {}
opt := WithMethodNotAllowedHandler(hanlder)
opt.apply(k)
assert.True(t, funcsAreEqual(hanlder, k.methodNotAllowedHandler))
}