-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdisk_cache_test.go
70 lines (62 loc) · 1.67 KB
/
disk_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
67
68
69
70
package fcache
import (
"fmt"
"testing"
)
func printList(t *testing.T, cache *diskCache) {
list := cache.lru.Traversal()
for i := range list {
t.Logf("%#v", list[i])
}
}
func TestDiskCacheFileName(t *testing.T) {
cache := &diskCache{dir: DefaultDiskCacheDir}
t.Log(cache.fileName("test"))
}
func TestDiskCacheCreateFile(t *testing.T) {
cache := newDiskCache(100, false, DefaultDiskCacheDir, 0).(*diskCache)
if err := cache.createFile("test", []byte("1234567890")); err != nil {
t.Fatal(err)
}
t.Logf("%#v", cache)
}
func TestDiskCacheSet(t *testing.T) {
cache := newDiskCache(100, false, DefaultDiskCacheDir, 0).(*diskCache)
for i := 0; i < 10; i++ {
cache.Set(fmt.Sprintf("key%d", i), []byte("1234567890"))
}
t.Logf("%#v", cache)
printList(t, cache)
}
func TestDiskCacheGet(t *testing.T) {
cache := newDiskCache(100, false, DefaultDiskCacheDir, 0).(*diskCache)
for i := 0; i < 10; i++ {
cache.Set(fmt.Sprintf("key%d", i), []byte("1234567890"))
}
t.Logf("%#v", cache)
t.Log(cache.Get("key5"))
t.Logf("%#v", cache)
printList(t, cache)
}
func TestDiskCacheEliminate(t *testing.T) {
cache := newDiskCache(100, false, DefaultDiskCacheDir, 0).(*diskCache)
for i := 0; i < 10; i++ {
cache.Set(fmt.Sprintf("key%d", i), []byte("1234567890"))
}
t.Logf("%#v", cache)
t.Log(cache.Get("key5"))
t.Logf("%#v", cache)
printList(t, cache)
t.Log(cache.Set("key10", []byte("hello")))
printList(t, cache)
t.Logf("%#v", cache)
}
func TestDiskCacheInit(t *testing.T) {
cache := newDiskCache(100, false, DefaultDiskCacheDir, 0).(*diskCache)
if err := cache.init(); err != nil {
t.Fatal(err)
}
t.Logf("%#v", cache)
cache.Set("key10", []byte("1111"))
printList(t, cache)
}