-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmiddleware_test.go
More file actions
40 lines (36 loc) · 862 Bytes
/
middleware_test.go
File metadata and controls
40 lines (36 loc) · 862 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
40
package gomw
import (
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestMiddlewareToCallNext(t *testing.T) {
next := newMockNextHandler()
testcases := []struct {
description string
handler http.Handler
}{
{
description: "call next from TimeoutMiddleware",
handler: Timeout(time.Second)(next),
},
{
description: "call next from Filter Middleware",
handler: Filter(func(r *http.Request) bool { return true })(next),
},
{
description: "call next from logger middleware",
handler: RequestLogger(next),
},
}
for _, tc := range testcases {
t.Run(tc.description, func(t *testing.T) {
r, _ := http.NewRequest("GET", "/some/url", nil)
w := httptest.NewRecorder()
tc.handler.ServeHTTP(w, r)
})
}
assert.Equal(t, len(testcases), next.totalCalls)
}