-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbloomd_test.go
103 lines (79 loc) · 2.02 KB
/
bloomd_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
93
94
95
96
97
98
99
100
101
102
103
package bloomd
import (
"context"
"os/exec"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
// NOTE: Requires bloomd to be available as `bloomd`
const (
testBloomdHost = "localhost:8673"
testFilter1 = "test_filter_1"
testFilter2 = "test_filter_2"
)
var bloomd *exec.Cmd
func TestNewClient(t *testing.T) {
assert := assert.New(t)
startBloomdServer()
defer killBloomdServer()
client, err := NewClient(testBloomdHost)
assert.NoError(err)
assert.NoError(client.Ping())
}
func TestListAllFilters(t *testing.T) {
assert := assert.New(t)
startBloomdServer()
defer killBloomdServer()
client, _ := NewClient(testBloomdHost)
ctx := context.Background()
assert.NoError(client.Create(ctx, testFilter1))
assert.NoError(client.Create(ctx, testFilter2))
filters, err := client.ListAll(ctx)
assert.NoError(err)
assert.Equal(2, len(filters))
assert.Equal("test_filter_1", filters[0].Name)
assert.Equal("test_filter_2", filters[1].Name)
assert.NoError(client.Drop(ctx, testFilter1))
assert.NoError(client.Drop(ctx, testFilter2))
}
func TestGetSetGet(t *testing.T) {
assert := assert.New(t)
startBloomdServer()
defer killBloomdServer()
client, _ := NewClient(testBloomdHost)
ctx := context.Background()
assert.NoError(client.Create(ctx, testFilter1))
keys := []string{
"test-1",
"test-2",
"test-3",
"test-4",
"test-5",
}
r1, err := client.Multi(ctx, testFilter1, keys...)
assert.NoError(err)
for i := 0; i < len(r1); i++ {
assert.Equal(false, r1[i])
}
r2, err := client.Bulk(ctx, testFilter1, "test-1", "test-3", "test-5")
assert.NoError(err)
for i := 0; i < len(r2); i++ {
assert.Equal(true, r2[i])
}
r3, err := client.Multi(ctx, testFilter1, keys...)
assert.NoError(err)
for i := 0; i < len(r3); i++ {
assert.Equal(i%2 == 0, r3[i])
}
assert.NoError(client.Drop(ctx, testFilter1))
}
func startBloomdServer() {
bloomd = exec.Command("bloomd")
bloomd.Start()
time.Sleep(time.Millisecond * 10)
}
func killBloomdServer() {
bloomd.Process.Kill()
time.Sleep(time.Millisecond * 10)
}