-
Notifications
You must be signed in to change notification settings - Fork 0
/
audit_test.go
47 lines (45 loc) · 961 Bytes
/
audit_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
package memcache
import (
"testing"
"time"
)
func TestNewAuditorFunc(t *testing.T) {
type args struct {
key string
}
tests := []struct {
name string
args args
shouldExist bool
}{
{
name: "key should exist after AuditFunc auditing",
args: args{
key: "key 1",
},
shouldExist: false,
},
{
name: "key shouldn't exist after AuditFunc auditing",
args: args{
key: "key 2",
},
shouldExist: true,
},
}
mc := New(5, 5, 75*time.Millisecond)
auditFn := NewAuditorFunc(20*time.Millisecond, 30*time.Millisecond)
done, stop := auditFn(mc)
mc.Put("key 1", "tag 1")
time.Sleep(80 * time.Millisecond)
mc.Put("key 2", "tag 1")
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if _, err := mc.Get(tt.args.key); err != nil && tt.shouldExist {
t.Errorf("MemCache.Renew(%v) error = %v, should exist = %v", tt.args.key, err, tt.shouldExist)
}
})
}
stop <- struct{}{}
<-done
}