/
blackbox_test.go
82 lines (66 loc) · 1.67 KB
/
blackbox_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
package radish
import (
"os"
"sort"
"testing"
"time"
)
const testaddr = ":1234"
func TestMain(m *testing.M) {
s := NewServer()
go s.Listen(testaddr)
time.Sleep(10 * time.Millisecond)
ret := m.Run()
s.Stop()
os.Exit(ret)
}
func TestBBSimple(t *testing.T) {
c, _ := Open(testaddr)
defer c.Close()
c.Set("keybbsimple", "ups", NoExpiration)
if value, err := c.Get("keybbsimple"); err != nil || value != "ups" {
t.Fatal("incorrect value in cache")
}
}
func TestBBErrors(t *testing.T) {
c, _ := Open(testaddr)
defer c.Close()
if _, err := c.Get("keybbserrors"); err != NotFound {
t.Fatal("incorrect error")
}
}
func TestBBDict(t *testing.T) {
c, _ := Open(testaddr)
defer c.Close()
c.Set("keybbdict", map[string]interface{}{"key": "valuedict"}, NoExpiration)
if value, err := c.GetDict("keybbdict", "key"); err != nil || value != "valuedict" {
t.Fatal("incorrect value in cache")
}
}
func TestBBIndex(t *testing.T) {
c, _ := Open(testaddr)
defer c.Close()
c.Set("keybbindex", []interface{}{"valuelist1", "valuelist2"}, NoExpiration)
if value, err := c.GetIndex("keybbindex", 1); err != nil || value != "valuelist2" {
t.Fatal("incorrect value in cache")
}
}
func TestBBRemove(t *testing.T) {
c, _ := Open(testaddr)
defer c.Close()
c.Set("keybbremove", "val", NoExpiration)
c.Remove("keybbremove")
if _, err := c.GetIndex("keybbremove", 1); err != NotFound {
t.Fatal("value must be removed")
}
}
func TestBBKeys(t *testing.T) {
c, _ := Open(testaddr)
defer c.Close()
c.Set("keybbkeys", "val", NoExpiration)
k, _ := c.Keys()
sort.Strings(k)
if k[sort.SearchStrings(k, "keybbkeys")] != "keybbkeys" {
t.Fatal("keys must contains at least keybbkeys")
}
}