-
Notifications
You must be signed in to change notification settings - Fork 2
/
cache_test.go
53 lines (40 loc) · 941 Bytes
/
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
package main
import (
"testing"
"time"
)
func TestCachePut(t *testing.T) {
logger = setupLogger("ERROR")
testToken := "testtoken"
testMessage := "testmessage"
cacheTTL := 4 * time.Second
sleepTime := 2 * time.Second
cache := newCache(cacheTTL)
cache.put(testToken, testMessage)
time.Sleep(sleepTime)
objects := cache.pop(testToken)
if testMessage != objects[0].message {
t.Errorf(
"incorrect message in cache, got %s, expected %s",
objects[0].message,
testMessage,
)
}
}
func TestCacheMessageEvict(t *testing.T) {
logger = setupLogger("ERROR")
testToken := "testtoken"
testMessage := "testmessage"
cacheTTL := 4 * time.Second
sleepTime := 5 * time.Second
cache := newCache(cacheTTL)
cache.put(testToken, testMessage)
time.Sleep(sleepTime)
objects := cache.pop(testToken)
if len(objects) != 0 {
t.Errorf(
"incorrect length of message cache, got %d, expected 0",
len(objects),
)
}
}