-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathredis_bitset_test.go
54 lines (49 loc) · 1.15 KB
/
redis_bitset_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
package bloom_test
import (
"testing"
"time"
"github.com/alicebob/miniredis"
"github.com/bculberson/bloom"
"github.com/garyburd/redigo/redis"
)
func TestRedisBitSet_New_Set_Test(t *testing.T) {
s, err := miniredis.Run()
if err != nil {
t.Error("Miniredis could not start")
}
defer s.Close()
pool := &redis.Pool{
MaxIdle: 3,
IdleTimeout: 240 * time.Second,
Dial: func() (redis.Conn, error) { return redis.Dial("tcp", s.Addr()) },
}
conn := pool.Get()
defer conn.Close()
bitSet := bloom.NewRedisBitSet("test_key", 512, conn)
isSetBefore, err := bitSet.Test([]uint{0})
if err != nil {
t.Error("Could not test bitset in redis")
}
if isSetBefore {
t.Error("Bit should not be set")
}
err = bitSet.Set([]uint{512})
if err != nil {
t.Error("Could not set bitset in redis")
}
isSetAfter, err := bitSet.Test([]uint{512})
if err != nil {
t.Error("Could not test bitset in redis")
}
if !isSetAfter {
t.Error("Bit should be set")
}
err = bitSet.Expire(3600)
if err != nil {
t.Errorf("Error adding expiration to bitset: %v", err)
}
err = bitSet.Delete()
if err != nil {
t.Errorf("Error cleaning up bitset: %v", err)
}
}