forked from philchia/agollo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache_test.go
66 lines (53 loc) · 1.13 KB
/
cache_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
package agollo
import (
"io/ioutil"
"os"
"testing"
)
func TestCache(t *testing.T) {
cache := newCache()
cache.set("key", "val")
if val, ok := cache.get("key"); !ok || val != "val" {
t.FailNow()
}
cache.set("key", "val2")
if val, ok := cache.get("key"); !ok || val != "val2" {
t.FailNow()
}
kv := cache.dump()
if len(kv) != 1 || kv["key"] != "val2" {
t.FailNow()
}
cache.delete("key")
if _, ok := cache.get("key"); ok {
t.FailNow()
}
}
func TestCacheDump(t *testing.T) {
var caches = newNamespaceCahce()
defer caches.drain()
caches.mustGetCache("namespace").set("key", "val")
f, err := ioutil.TempFile(".", "agollo")
if err != nil {
t.Error(err)
}
f.Close()
defer os.Remove(f.Name())
if err := caches.dump(f.Name()); err != nil {
t.Error(err)
}
var restore = newNamespaceCahce()
defer restore.drain()
if err := restore.load(f.Name()); err != nil {
t.Error(err)
}
if val, _ := restore.mustGetCache("namespace").get("key"); val != "val" {
t.FailNow()
}
if err := restore.load("null"); err == nil {
t.FailNow()
}
if err := restore.load("./testdata/app.properties"); err == nil {
t.FailNow()
}
}