forked from jellydator/ttlcache
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options_test.go
60 lines (45 loc) · 1.27 KB
/
options_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
54
55
56
57
58
59
60
package ttlcache
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func Test_optionFunc_apply(t *testing.T) {
var called bool
optionFunc[string, string](func(_ *options[string, string]) {
called = true
}).apply(nil)
assert.True(t, called)
}
func Test_applyOptions(t *testing.T) {
var opts options[string, string]
applyOptions(&opts,
WithCapacity[string, string](12),
WithTTL[string, string](time.Hour),
)
assert.Equal(t, uint64(12), opts.capacity)
assert.Equal(t, time.Hour, opts.ttl)
}
func Test_WithCapacity(t *testing.T) {
var opts options[string, string]
WithCapacity[string, string](12).apply(&opts)
assert.Equal(t, uint64(12), opts.capacity)
}
func Test_WithTTL(t *testing.T) {
var opts options[string, string]
WithTTL[string, string](time.Hour).apply(&opts)
assert.Equal(t, time.Hour, opts.ttl)
}
func Test_WithLoader(t *testing.T) {
var opts options[string, string]
l := LoaderFunc[string, string](func(_ *Cache[string, string], _ string) *Item[string, string] {
return nil
})
WithLoader[string, string](l).apply(&opts)
assert.NotNil(t, opts.loader)
}
func Test_WithDisableTouchOnHit(t *testing.T) {
var opts options[string, string]
WithDisableTouchOnHit[string, string]().apply(&opts)
assert.True(t, opts.disableTouchOnHit)
}