-
Notifications
You must be signed in to change notification settings - Fork 7
/
logger_test.go
67 lines (62 loc) · 1.58 KB
/
logger_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
package neko
import (
. "github.com/smartystreets/goconvey/convey"
"net/http"
"testing"
)
func Test_Logger(t *testing.T) {
testLogger("GET", t)
testLogger("POST", t)
testLogger("DELETE", t)
testLogger("PATCH", t)
testLogger("PUT", t)
testLogger("OPTIONS", t)
testLogger("HEAD", t)
m := New()
m.Use(Logger())
m.GET("/30x", func(ctx *Context) {
ctx.Redirect("/")
})
m.GET("/5xx", func(ctx *Context) {
ctx.Text("Bad Gateway", http.StatusBadGateway)
})
Convey("HTTP 30x", t, func() {
w := performRequest(m, "GET", "/30x", "")
So(w.Code, ShouldEqual, http.StatusFound)
})
Convey("HTTP 4xx", t, func() {
w := performRequest(m, "GET", "/404", "")
So(w.Code, ShouldEqual, http.StatusNotFound)
})
Convey("HTTP 5xx", t, func() {
w := performRequest(m, "GET", "/5xx", "")
So(w.Code, ShouldEqual, http.StatusBadGateway)
})
}
func testLogger(method string, t *testing.T) {
Convey(method+" Method Logger", t, func() {
passed := false
m := New()
m.Use(Logger())
switch method {
case "GET":
m.GET("", func(ctx *Context) { passed = true })
case "POST":
m.POST("", func(ctx *Context) { passed = true })
case "DELETE":
m.DELETE("", func(ctx *Context) { passed = true })
case "PATCH":
m.PATCH("", func(ctx *Context) { passed = true })
case "PUT":
m.PUT("", func(ctx *Context) { passed = true })
case "OPTIONS":
m.OPTIONS("", func(ctx *Context) { passed = true })
case "HEAD":
m.HEAD("", func(ctx *Context) { passed = true })
}
// RUN
w := performRequest(m, method, "/", "")
So(passed, ShouldBeTrue)
So(w.Code, ShouldEqual, http.StatusOK)
})
}