-
Notifications
You must be signed in to change notification settings - Fork 0
/
func_test.go
59 lines (46 loc) · 1.25 KB
/
func_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
package less
import (
"context"
"testing"
)
func TestChain(t *testing.T) {
h := func(ctx context.Context, ch Channel, message interface{}) error {
t.Logf("handle message: %v", message)
return nil
}
mws := Chain(middleware1(t), middleware2(t))
err := Chain(mws, middleware3(t))(h)(context.Background(), nil, "middleware test")
if err != nil {
t.Errorf("expect %v, got %v", nil, err)
}
}
func middleware1(t *testing.T) Middleware {
return func(handler Handler) Handler {
return func(ctx context.Context, ch Channel, message interface{}) error {
t.Logf("middleware1 before...")
err := handler(ctx, ch, message)
t.Logf("middleware1 after...")
return err
}
}
}
func middleware2(t *testing.T) Middleware {
return func(handler Handler) Handler {
return func(ctx context.Context, ch Channel, message interface{}) error {
t.Logf("middleware2 before...")
err := handler(ctx, ch, message)
t.Logf("middleware2 after...")
return err
}
}
}
func middleware3(t *testing.T) Middleware {
return func(handler Handler) Handler {
return func(ctx context.Context, ch Channel, message interface{}) error {
t.Logf("middleware3 before...")
err := handler(ctx, ch, message)
t.Logf("middleware3 after...")
return err
}
}
}