forked from oleiade/trousseau
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kv_test.go
118 lines (93 loc) · 2.99 KB
/
kv_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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package trousseau
import (
"testing"
)
func TestKVStoreGet(t *testing.T) {
kvStore := make(KVStore)
kvStore["abc"] = 123
v, err := kvStore.Get("abc")
ok(t, err)
equals(t, v, 123)
}
func TestKVStoreGet_errors_on_non_existing_key(t *testing.T) {
kvStore := make(KVStore)
v, err := kvStore.Get("easy as")
notOk(t, err)
equals(t, v, "")
}
func TestKVStoreSet(t *testing.T) {
kvStore := make(KVStore)
kvStore.Set("abc", 123)
equals(t, kvStore["abc"], 123)
}
func TestKVStoreDel(t *testing.T) {
kvStore := make(KVStore)
kvStore.Set("abc", 123)
kvStore.Del("abc")
_, in := kvStore["abc"]
assert(t, in == false, "Expected 'abc' key to be removed from KVStore Container")
}
func TestKVStoreRename_without_overwrite_and_non_existing_destination_key(t *testing.T) {
kvStore := make(KVStore)
kvStore["abc"] = 123
err := kvStore.Rename("abc", "easy as", false)
_, srcIn := kvStore["abc"]
_, destIn := kvStore["easy as"]
ok(t, err)
assert(t, srcIn == false, "Expected source key to have been removed from KVStore")
assert(t, destIn == true, "Expected destination key to be present in KVStore")
equals(t, kvStore["easy as"], 123)
}
func TestKVStoreRename_without_overwrite_and_existing_destination_key(t *testing.T) {
kvStore := make(KVStore)
kvStore["abc"] = 123
kvStore["easy as"] = "do re mi"
err := kvStore.Rename("abc", "easy as", false)
_, srcIn := kvStore["abc"]
_, destIn := kvStore["easy as"]
notOk(t, err)
assert(t, srcIn == true, "Expected source key to have been removed from KVStore")
assert(t, destIn == true, "Expected destination key to be present in KVStore")
equals(t, kvStore["easy as"], "do re mi")
}
func TestKVStoreRename_with_overwrite_and_existing_destination_key(t *testing.T) {
kvStore := make(KVStore)
kvStore["abc"] = 123
kvStore["easy as"] = "do re mi"
err := kvStore.Rename("abc", "easy as", true)
_, srcIn := kvStore["abc"]
_, destIn := kvStore["easy as"]
ok(t, err)
assert(t, srcIn == false, "Expected source key to have been removed from KVStore")
assert(t, destIn == true, "Expected destination key to be present in KVStore")
equals(t, kvStore["easy as"], 123)
}
func TestKVStoreRename_with_overwrite_and_non_existing_destination_key(t *testing.T) {
kvStore := make(KVStore)
kvStore["abc"] = 123
err := kvStore.Rename("abc", "easy as", true)
_, srcIn := kvStore["abc"]
_, destIn := kvStore["easy as"]
ok(t, err)
assert(t, srcIn == false, "Expected source key to have been removed from KVStore")
assert(t, destIn == true, "Expected destination key to be present in KVStore")
equals(t, kvStore["easy as"], 123)
}
func TestKVStoreKeys(t *testing.T) {
kvStore := make(KVStore)
kvStore["abc"] = 123
kvStore["easy as"] = "do re mi"
keys := kvStore.Keys()
equals(t, keys, []string{"abc", "easy as"})
}
func TestKVStoreItems(t *testing.T) {
kvStore := make(KVStore)
kvStore["abc"] = 123
kvStore["easy as"] = "do re mi"
items := kvStore.Items()
expected := map[string]interface{}{
"abc": 123,
"easy as": "do re mi",
}
equals(t, items, expected)
}