forked from krishpranav/webfr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext_test.go
46 lines (37 loc) · 990 Bytes
/
context_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
package webfr
import (
"net/http"
"testing"
)
func TestNext(t *testing.T) {
routes := []struct {
path string
middleware handlerFunc
handler handlerFunc
}{
{path: "/ok", middleware: emptyMiddleware, handler: emptyMiddlewareHandler},
{path: "/unauthorized", middleware: unAuthorizedHandler, handler: emptyHandler},
}
wbf := setupwebfr()
for _, r := range routes {
wbf.Get(r.path, r.middleware, r.handler)
}
startwebfr(wbf)
testCases := []struct {
path string
statusCode int
}{
{path: "/ok", statusCode: StatusOK},
{path: "/unauthorized", statusCode: StatusUnauthorized},
}
for _, tc := range testCases {
req, _ := http.NewRequest(MethodGet, tc.path, nil)
response, err := makeRequest(req, wbf)
if err != nil {
t.Fatalf("%s(%s): %s", MethodGet, tc.path, err.Error())
}
if response.StatusCode != tc.statusCode {
t.Fatalf("%s(%s): returned %d expected %d", MethodGet, tc.path, response.StatusCode, tc.statusCode)
}
}
}