-
Notifications
You must be signed in to change notification settings - Fork 1
/
dsi_test.go
71 lines (63 loc) · 1.5 KB
/
dsi_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
64
65
66
67
68
69
70
71
package dsi
import (
"context"
"testing"
)
func Test_Traceme(t *testing.T) {
patchconfig = []*patch{
{
What: "test",
Match: "1",
Return: true,
},
{
What: "test2",
Match: "1",
Patch: true,
},
{
What: "test3",
Match: "1",
Patch: true,
Repeat: 3,
},
}
var res, called bool
res, called = false, false
p := 1
Traceme(context.Background(), "test", map[string]interface{}{"a": &p}, func() { called = true }, &res)
if !res {
t.Errorf("res was not set to true")
}
if called {
t.Errorf("return should not call")
}
res, called = false, false
Traceme(context.Background(), "test2", map[string]interface{}{}, func() { called = true }, &res)
if !res {
t.Errorf("res was not set to true")
}
if !called {
t.Errorf("patch should call")
}
t.Run("repeats", func(t *testing.T) {
Traceme(context.Background(), "test3", map[string]interface{}{}, func() { called = true }, &res)
Traceme(context.Background(), "test3", map[string]interface{}{}, func() { called = true }, &res)
res, called = false, false
Traceme(context.Background(), "test3", map[string]interface{}{}, func() { called = true }, &res)
if !res {
t.Errorf("res was not set to true")
}
if !called {
t.Errorf("patch should call")
}
res, called = false, false
Traceme(context.Background(), "test3", map[string]interface{}{}, func() { called = true }, &res)
if res {
t.Errorf("res should not be patched again")
}
if !called {
t.Errorf("after repetition should call")
}
})
}