-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache_test.go
More file actions
44 lines (35 loc) · 862 Bytes
/
cache_test.go
File metadata and controls
44 lines (35 loc) · 862 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
package didcomauth
import "errors"
// cache_test is just a cache_mem with a flag which returns error if needed
type cTest struct {
mem
shouldError bool
}
var ctError = errors.New("error!")
// newMem returns a new instance of mem with an in-memory map as backing store, typically used for testing.
func newCTest(shouldError bool) cache {
return cache(
cTest{
mem{store: make(map[string]Challenge)},
shouldError,
},
)
}
// Set implements the cache interface for redis.
func (m cTest) Set(c Challenge) error {
if m.shouldError {
return ctError
}
m.store[getKey(c.DID)] = c
return nil
}
// Get implements the cache interface for redis.
func (m cTest) Get(did string) (Challenge, error) {
if m.shouldError {
return Challenge{}, ctError
}
return m.store[getKey(did)], nil
}
func (m cTest) Delete(did string) {
delete(m.store, did)
}