-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdriver_test.go
49 lines (46 loc) · 1.2 KB
/
driver_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
package microcache
import (
"net/http"
"testing"
)
// Remove should work as expected
func TestRemove(t *testing.T) {
var testDriver = func(name string, d Driver) {
cache := New(Config{Driver: d})
defer cache.Stop()
handler := cache.Middleware(http.HandlerFunc(noopSuccessHandler))
batchGet(handler, []string{
"/",
})
if d.GetSize() != 1 {
t.Fatalf("%s Driver reports inaccurate length", name)
}
r, _ := http.NewRequest("GET", "/", nil)
reqHash := getRequestHash(cache, r)
reqOpts := buildRequestOpts(cache, Response{}, r)
objHash := reqOpts.getObjectHash(reqHash, r)
d.Remove(objHash)
if d.GetSize() != 0 {
t.Fatalf("%s Driver cannot delete items", name)
}
}
testDriver("ARC", NewDriverARC(10))
testDriver("LRU", NewDriverLRU(10))
}
// Empty init should not fatal
func TestEmptyInit(t *testing.T) {
var testDriver = func(name string, d Driver) {
cache := New(Config{Driver: d})
defer cache.Stop()
handler := cache.Middleware(http.HandlerFunc(noopSuccessHandler))
batchGet(handler, []string{
"/a",
"/b",
})
if d.GetSize() != 1 {
t.Fatalf("%s Driver should have length 1", name)
}
}
testDriver("ARC", NewDriverARC(0))
testDriver("LRU", NewDriverLRU(0))
}