-
Notifications
You must be signed in to change notification settings - Fork 2
/
zebra_test.go
63 lines (49 loc) · 1 KB
/
zebra_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
63
package zebra
import (
"testing"
)
func TestServeHTTP(t *testing.T) {
tester := NewTestHelper(t)
z := New()
m1 := &demoMiddleware{}
m2 := &demoMiddleware2{}
m3 := &demoMiddleware3{}
z.Use(m1)
z.Use(m2)
z.Use(m3)
z.ServeHTTP(nil, tester.NewRequest("GET", "/foo"))
tester.AssertTrue(m1.excuted)
tester.AssertTrue(m2.excuted)
tester.AssertFalse(m3.excuted)
tester.AssertTrue(m1.callbacked)
}
func TestRun(t *testing.T) {
go New().Run()
go New().RunOnAddr(":8888")
}
///-----------------------------------------------
type demoMiddleware struct {
excuted bool
callbacked bool
}
func (m *demoMiddleware) Excute(c *Context) bool {
m.excuted = true
return true
}
func (m *demoMiddleware) Callback(c *Context) {
m.callbacked = true
}
type demoMiddleware2 struct {
excuted bool
}
func (m *demoMiddleware2) Excute(c *Context) bool {
m.excuted = true
return false
}
type demoMiddleware3 struct {
excuted bool
}
func (m *demoMiddleware3) Excute(c *Context) bool {
m.excuted = true
return true
}