-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcache_proxy_test.go
69 lines (67 loc) · 1.37 KB
/
cache_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
66
67
68
69
package cb_cache
import (
"context"
lruk "github.com/cold-bin/cb-cache/lru-k"
"reflect"
"testing"
)
func TestGroup_Get(t *testing.T) {
type fields struct {
namespace string
cache cacheProxy
getter GetterFunc
}
type args struct {
ctx context.Context
k string
}
tests := []struct {
name string
fields fields
args args
want ByteView
wantErr bool
}{
{
name: "get data from getter",
fields: fields{
namespace: "rank",
cache: cacheProxy{
cache: lruk.NewCache(2),
},
getter: func(ctx context.Context, k string) (v []byte, err error) {
if k == "key1" {
return []byte("good case"), nil
} else {
return []byte{}, nil
}
},
},
args: args{
ctx: context.Background(),
k: "key1",
},
want: ByteView{
b: []byte("good case"),
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
g := &Group{
namespace: tt.fields.namespace,
mainCache: tt.fields.cache,
getter: tt.fields.getter,
}
got, err := g.Get(tt.args.ctx, tt.args.k)
if (err != nil) != tt.wantErr {
t.Errorf("Group.Get(%v, %v) error = %v, wantErr %v", tt.args.ctx, tt.args.k, err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("Group.Get(%v, %v) = %v, want %v", tt.args.ctx, tt.args.k, got, tt.want)
}
})
}
}