-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmiddleware_test.go
More file actions
39 lines (31 loc) · 954 Bytes
/
middleware_test.go
File metadata and controls
39 lines (31 loc) · 954 Bytes
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
package rex
import (
"net/http"
"net/http/httptest"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestMiddleware(t *testing.T) {
env := func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Powered-By", "rex")
next.ServeHTTP(w, r)
})
}
json := func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
next.ServeHTTP(w, r)
w.Header().Set("Content-Type", "application/json")
})
}
mw := new(middleware)
mw.stack = append(mw.stack, env)
mw.stack = append(mw.stack, json)
Convey("rex.middleware", t, func() {
request, _ := http.NewRequest("GET", "/", nil)
response := httptest.NewRecorder()
mw.ServeHTTP(response, request)
So(response.Header().Get("X-Powered-By"), ShouldEqual, "rex")
So(response.Header().Get("Content-Type"), ShouldEqual, "application/json")
})
}