-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtokencache_test.go
More file actions
54 lines (41 loc) · 947 Bytes
/
tokencache_test.go
File metadata and controls
54 lines (41 loc) · 947 Bytes
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
package sdk
import (
"reflect"
"testing"
"time"
)
func Test_TokenCache(t *testing.T) {
cache := NewMemoryTokenCache()
t.Run("Cache hit for token", func(t *testing.T) {
token := &Token{
IDToken: "token1",
Scope: []string{"function"},
}
cache.Set("token1", token)
got, ok := cache.Get("token1")
if !ok {
t.Errorf("Want cache hit")
}
if !reflect.DeepEqual(token, got) {
t.Errorf("Want cached token: %v, got: %v", token, got)
}
})
t.Run("No cache hit for missing key", func(t *testing.T) {
got, ok := cache.Get("token2")
if ok {
t.Errorf("Want cache miss, got: %v", got)
}
})
t.Run("No cache hit for expired token", func(t *testing.T) {
token := &Token{
IDToken: "token3",
Expiry: time.Now().Add(time.Minute * -10),
Scope: []string{"function"},
}
cache.Set("token3", token)
got, ok := cache.Get("token3")
if ok {
t.Errorf("Want cache miss, got: %v", got)
}
})
}