-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathwrap_test.go
53 lines (44 loc) · 1.01 KB
/
wrap_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
package middleware
import (
"net/http"
"testing"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)
func TestWrap_Add(t *testing.T) {
a := assert.New(t)
wrap := NewWrap(logrus.StandardLogger())
eLen := 5
for i := 0; i < eLen; i++ {
wrap.Add(func(handler http.Handler) http.Handler { return handler })
}
a.Len(wrap.list, eLen)
}
func TestWrap_Do(t *testing.T) {
a := assert.New(t)
wrap := NewWrap(logrus.StandardLogger())
checkArray := make([]int, 0)
wrap.Add(
func(handler http.Handler) http.Handler {
checkArray = append(checkArray, 1)
return handler
},
)
wrap.Add(
func(handler http.Handler) http.Handler {
checkArray = append(checkArray, 2)
return handler
},
)
wrap.Add(
func(handler http.Handler) http.Handler {
checkArray = append(checkArray, 3)
return handler
},
)
wrap.Do(http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {}))
a.Len(checkArray, 3)
a.Equal(1, checkArray[0])
a.Equal(2, checkArray[1])
a.Equal(3, checkArray[2])
}