-
Notifications
You must be signed in to change notification settings - Fork 3
/
cache_test.go
62 lines (50 loc) · 1.14 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
package carrot
import (
"testing"
)
func TestCacheInstantiation(t *testing.T) {
ccl := NewCachedControllersList()
if ccl == nil {
t.Error("The cached controllers list was not instantiated")
}
}
func TestCacheGetAndAdd(t *testing.T) {
key := "key"
ccl := NewCachedControllersList()
if ccl.Exists(key) {
t.Error("The key shouldn't exist in the cached controller list yet")
}
_, err := ccl.Get(key)
if err == nil {
t.Error("A controller shouldn't have been returned because its key doesn't exist")
}
c, err := getTestController(endpoint1)
if err != nil {
t.Error(err)
}
ccl.Add(key, c)
if !ccl.Exists(key) {
t.Error("The key should exist in the cached controllers list")
}
_, err = ccl.Get(key)
if err != nil {
t.Error(err)
}
}
func TestCacheDeleteOldest(t *testing.T) {
key := "key"
ccl := NewCachedControllersList()
err := ccl.DeleteOldest()
if err == nil {
t.Error("Nothing should have been deleted since none of the cached controllers have a matching key")
}
c, err := getTestController(endpoint1)
if err != nil {
t.Error(err)
}
ccl.Add(key, c)
err = ccl.DeleteOldest()
if err != nil {
t.Error(err)
}
}