-
Notifications
You must be signed in to change notification settings - Fork 0
/
dict_test.go
68 lines (49 loc) · 1.67 KB
/
dict_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
package globe
import (
"testing"
"github.com/coreos/go-etcd/etcd"
)
var testCluster = []string{"http://127.0.0.1:4001"}
var rawClient = etcd.NewClient(testCluster)
func initNewTestDict(keyspace string) *Dict {
rawClient.Delete(keyspace, true)
rawClient.Set(keyspace + "/key1", "asdf", uint64(0))
rawClient.Set(keyspace + "/key2", "lkjh", uint64(0))
logClient := NewEtcdClient(testCluster)
newD, err := NewDict(keyspace, logClient)
if err != nil {
panic(err)
}
return newD
}
func TestDictInitial(t *testing.T) {
globeDict := initNewTestDict("TestDictInitial")
if val, _ := globeDict.Get("key1"); val != "asdf" {
t.Error("Expected key1 to be asdf but was", val)
}
}
func TestDictWatchExisting(t *testing.T) {
globeDict := initNewTestDict("TestDictWatchExisting")
rawClient.Set("TestDictWatchExisting/key1", "new val", uint64(0))
if val, _ := globeDict.Get("key1"); val != "new val" {
t.Errorf("Expected key1 to be new val but was %s", val)
}
}
func TestDictPut(t *testing.T) {
globeDict := initNewTestDict("TestDictPut")
globeDict.Put("key1", "new val")
if val, _ := globeDict.Get("key1"); val != "new val" {
t.Errorf("Expected key1 to be new val but was %s", val)
}
}
func TestDictWatchMulti(t *testing.T) {
globeDict := initNewTestDict("TestDictWatchMulti")
rawClient.Set("TestDictWatchMulti/key1", "new val", uint64(0))
if val, _ := globeDict.Get("key1"); val != "new val" {
t.Errorf("Expected key1 to be new val but was %s", val)
}
rawClient.Set("TestDictWatchMulti/key1", "new val2", uint64(0))
if val, _ := globeDict.Get("key1"); val != "new val2" {
t.Errorf("Expected key1 to be new val2 but was %s", val)
}
}