-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache_test.go
More file actions
63 lines (49 loc) · 1.21 KB
/
cache_test.go
File metadata and controls
63 lines (49 loc) · 1.21 KB
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
package traefik_auth_middleware
import (
"testing"
"time"
)
func TestEmpty(t *testing.T) {
cache := Cache{}
_, ok := cache.Get("foo")
if ok {
t.Error("Expected get on empty cache to be empty, but got ok")
}
// check that call to ClearExpired doesn't blow up if cache empty
cache.ClearExpired()
}
func TestCache(t *testing.T) {
cache := Cache{}
items := map[string]Token{
"foo": {"fooAccessor", "fooSecret", time.Now()},
"bar": {"barAccessor", "barSecret", time.Now()},
"baz": {"bazAccessor", "bazSecret", time.Now()},
}
for k, v := range items {
cache.Store(k, v)
}
for k, v := range items {
rv, ok := cache.Get(k)
if !ok {
t.Errorf("exected %v to be found in cache, but didn't", k)
}
if rv != v {
t.Errorf("exected %v but got %v", v, rv)
}
}
}
func TestCacheExpiry(t *testing.T) {
cache := Cache{}
items := map[string]Token{
"foo": {"fooAccessor", "fooSecret", time.Now().Add(time.Hour)},
"bar": {"barAccessor", "barSecret", time.Now().Add(time.Hour)},
"baz": {"bazAccessor", "bazSecret", time.Now()},
}
for k, v := range items {
cache.Store(k, v)
}
cache.ClearExpired()
if _, ok := cache.Get("baz"); ok {
t.Errorf("expired item still returned from cache")
}
}