-
Notifications
You must be signed in to change notification settings - Fork 0
/
options_test_matchers.go
64 lines (52 loc) · 1.06 KB
/
options_test_matchers.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
63
64
package store
import (
"fmt"
"time"
"golang.org/x/exp/slices"
)
type OptionsMatcher struct {
Cost int64
Expiration time.Duration
Tags []string
}
func (m OptionsMatcher) Matches(x interface{}) bool {
switch values := x.(type) {
case []Option:
opts := &Options{}
for _, value := range values {
value(opts)
}
return opts.Cost == m.Cost &&
opts.Expiration == m.Expiration &&
slices.Equal(opts.Tags, m.Tags)
}
return false
}
func (m OptionsMatcher) String() string {
return fmt.Sprintf(
"options should match (cost: %v expiration: %v tags: %v)",
m.Cost,
m.Expiration,
m.Tags,
)
}
type InvalidateOptionsMatcher struct {
Tags []string
}
func (m InvalidateOptionsMatcher) Matches(x interface{}) bool {
switch values := x.(type) {
case []InvalidateOption:
opts := &InvalidateOptions{}
for _, value := range values {
value(opts)
}
return slices.Equal(opts.Tags, m.Tags)
}
return false
}
func (m InvalidateOptionsMatcher) String() string {
return fmt.Sprintf(
"invalidate options should match (tags: %v)",
m.Tags,
)
}