-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatekeeper_test.go
92 lines (76 loc) · 1.42 KB
/
gatekeeper_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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package cuckooc
import (
"context"
"sync"
"testing"
)
func TestGatekeeper_IntegrationTests(t *testing.T) {
tests := []struct {
cmd string
result string
}{
{
cmd: "test new 30",
result: "true",
},
{
cmd: "test set a b c d e",
result: "true true true true true",
},
{
cmd: "test setu a b f g",
result: "true true true true",
},
{
cmd: "test check a b 1 2 c d e f g",
result: "true true false false true true true true true",
},
{
cmd: "test count",
result: "7",
},
{
cmd: "test loadfactor",
result: "0.2188",
},
{
cmd: "test delete a c d f z",
result: "true true true true false",
},
{
cmd: "test count",
result: "3",
},
{
cmd: "test loadfactor",
result: "0.0938",
},
{
cmd: "test stop",
result: "true",
},
}
respCh := make(chan string)
gk := NewGatekeeper(make(chan Executor))
wg := new(sync.WaitGroup)
ctx, cancel := context.WithCancel(context.Background())
wg.Add(1)
go gk.Start(ctx, Config{}, wg)
for _, c := range tests {
exe, err := parseCommand(c.cmd, respCh)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
gk.CMDCh <- exe
result := <-respCh
if result != c.result {
t.Fatalf("expected result %s but got %s", c.result, result)
}
}
cancel()
wg.Wait()
_, ok := gk.filters["test"]
if ok {
t.Fatalf("expected filter to be missing but got one")
}
}