-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler_test.go
62 lines (46 loc) · 1.32 KB
/
handler_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 logjam
import (
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestNotFoundHandler(t *testing.T) {
agent := NewAgent(&Options{})
defer agent.Shutdown()
rr := httptest.NewRecorder()
r, err := http.NewRequest("GET", "/foo", nil)
if err != nil {
t.Fatal(err)
}
handler := agent.NewMiddleware(MiddlewareOptions{})(http.HandlerFunc(NotFoundHandler))
handler.ServeHTTP(rr, r)
rs := rr.Result()
Convey("handler response", t, func() {
So(rs.StatusCode, ShouldEqual, http.StatusNotFound)
So(rr.Header().Get("X-Logjam-Action"), ShouldEqual, "System#notFound")
defer rs.Body.Close()
body, err := ioutil.ReadAll(rs.Body)
if err != nil {
t.Fatal(err)
}
So(string(body), ShouldEqual, "Not Found\n")
})
}
func TestMethodNotAllowedHandler(t *testing.T) {
agent := NewAgent(&Options{})
defer agent.Shutdown()
rr := httptest.NewRecorder()
r, err := http.NewRequest("GET", "/foo", nil)
if err != nil {
t.Fatal(err)
}
handler := agent.NewMiddleware(MiddlewareOptions{})(http.HandlerFunc(MethodNotAllowedHandler))
handler.ServeHTTP(rr, r)
rs := rr.Result()
Convey("handler response", t, func() {
So(rs.StatusCode, ShouldEqual, http.StatusMethodNotAllowed)
So(rr.Header().Get("X-Logjam-Action"), ShouldEqual, "System#methodNotAllowed")
})
}