-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathmcache_test.go
72 lines (62 loc) · 1.24 KB
/
mcache_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
package mcache
import (
"log"
"testing"
)
var (
mcache *CacheDriver
dataSet = new(TestData)
key1 = "keystr1"
key2 = "keystr2"
)
//TestData
type TestData struct {
ID int
Name string
Age int
}
func init() {
mcache = New()
}
//Set cache Pointer data
func TestSet(t *testing.T) {
err := mcache.Set(key2, dataSet, TTL_FOREVER)
if err != nil {
t.Errorf("Error %s cache data: %v, ERROR_MSG: %v", t.Name(), dataSet, err)
}
log.Printf("%s : OK\n", t.Name())
}
//Get cache Pointer
func TestGetPointer(t *testing.T) {
if pointer, ok := mcache.Get(key2); ok {
if obj, ok := pointer.(*TestData); ok {
if obj.Age != dataSet.Age {
t.Errorf("Cache data incorrect by key: %s", key2)
}
}
} else {
t.Errorf("Cache not found by key: %s", key2)
}
log.Printf("%s : OK\n", t.Name())
}
//Get Len cache
func TestLen(t *testing.T) {
if mcache.Len() != 1 {
t.Errorf("Cache %s incorrect by key", t.Name())
}
log.Printf("%s : OK\n", t.Name())
}
//Remove two key
func TestRemove(t *testing.T) {
mcache.Remove(key2)
mcache.Remove(key1)
if mcache.Len() != 0 {
t.Errorf("Cache %s incorrect", t.Name())
}
log.Printf("%s : OK\n", t.Name())
}
//TestClose
func TestClose(t *testing.T) {
mcache.Close()
log.Printf("%s : OK\n", t.Name())
}