-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathinterceptor_test.go
55 lines (51 loc) · 1.04 KB
/
interceptor_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
package sqlingo
import (
"context"
"testing"
)
func TestChainInterceptors(t *testing.T) {
s := ""
i1 := func(ctx context.Context, sql string, invoker InvokerFunc) error {
s += "<i1>"
s += sql
defer func() {
s += "</i1>"
}()
return invoker(ctx, sql+"s1")
}
i2 := func(ctx context.Context, sql string, invoker InvokerFunc) error {
s += "<i2>"
s += sql
defer func() {
s += "</i2>"
}()
return invoker(ctx, sql+"s2")
}
chain := ChainInterceptors(i1, i2)
_ = chain(context.Background(), "sql", func(ctx context.Context, sql string) error {
s += "<invoker>"
s += sql
defer func() {
s += "</invoker>"
}()
return nil
})
if s != "<i1>sql<i2>sqls1<invoker>sqls1s2</invoker></i2></i1>" {
t.Error(s)
}
}
func TestEmptyChainInterceptors(t *testing.T) {
s := ""
chain := ChainInterceptors()
_ = chain(context.Background(), "sql", func(ctx context.Context, sql string) error {
s += "<invoker>"
defer func() {
s += "</invoker>"
}()
s += sql
return nil
})
if s != "<invoker>sql</invoker>" {
t.Error(s)
}
}