-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathneko_test.go
62 lines (55 loc) · 1.31 KB
/
neko_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
package neko
import (
. "github.com/smartystreets/goconvey/convey"
"net/http"
"testing"
)
func Test_New(t *testing.T) {
Convey("Initialize a new instance", t, func() {
So(New(), ShouldNotBeNil)
})
Convey("Initialize a ‘classic’ instance", t, func() {
So(Classic("Neko"), ShouldNotBeNil)
})
}
func Test_Run(t *testing.T) {
Convey("Just test that Run doesn't bomb", t, func() {
go New().Run(":3000")
})
}
func Test_Handlers(t *testing.T) {
Convey("Add custom handlers", t, func() {
result := ""
m := New()
m.Use(func(ctx *Context) {
result += "1"
ctx.Writer.Before(func(w ResponseWriter) {
result += "3"
})
ctx.SetHeader("x-before", "before")
ctx.Next()
result += "5"
So(ctx.Writer.Size(), ShouldEqual, 5)
})
m.Use(func(ctx *Context) {
ctx.Abort()
result += "2"
ctx.Text("abort", http.StatusBadRequest)
result += "4"
})
m.GET("/", func(ctx *Context) {
result += "0"
ctx.Text("not found", http.StatusNotFound)
})
w := performRequest(m, "GET", "/", "")
So(w.HeaderMap.Get("x-before"), ShouldEqual, "before")
So(w.Code, ShouldEqual, http.StatusBadRequest)
So(w.Body.String(), ShouldEqual, "abort")
So(result, ShouldEqual, "12345")
})
}
func Test_Version(t *testing.T) {
Convey("Get version", t, func() {
So(Version(), ShouldNotBeEmpty)
})
}