-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
proxy_test.go
65 lines (54 loc) · 998 Bytes
/
proxy_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
61
62
63
64
65
package zcache
import (
"reflect"
"testing"
)
func TestProxy(t *testing.T) {
c := New[string, any](NoExpiration, 0)
pc := NewProxy[string, string, any](c)
has := func(v any, ok bool) {
t.Helper()
if !ok {
t.Error("ok false")
}
if v != "vvv" {
t.Errorf("value wrong: %q", v)
}
}
not := func(v interface{}, ok bool) {
t.Helper()
if ok {
t.Error("ok true")
}
if v != nil {
t.Errorf("value not nil: %q", v)
}
}
c.Set("k", "vvv")
pc.Proxy("k", "p")
has(pc.Get("p"))
not(pc.Get("k"))
pc.Delete("k")
has(pc.Get("p"))
pc.Delete("p")
not(pc.Get("p"))
pc.Set("main", "proxy", "vvv")
has(pc.Get("proxy"))
not(pc.Get("main"))
if !reflect.DeepEqual(pc.Items(), map[string]string{"proxy": "main"}) {
t.Error()
}
if k, ok := pc.Key("adsasdasd"); k != "" || ok != false {
t.Error()
}
if k, ok := pc.Key("proxy"); k != "main" || ok != true {
t.Error()
}
if pc.Cache() != c {
t.Error()
}
pc.Reset()
if len(pc.m) != 0 {
t.Error()
}
}