-
Notifications
You must be signed in to change notification settings - Fork 235
Expand file tree
/
Copy pathop_name_test.go
More file actions
119 lines (111 loc) · 2.73 KB
/
op_name_test.go
File metadata and controls
119 lines (111 loc) · 2.73 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package rueidisotel
import (
"testing"
"time"
"github.com/redis/rueidis"
"github.com/redis/rueidis/internal/cmds"
)
func TestDefaultOpNameResolver_OpName(t *testing.T) {
resolver := DefaultOpNameResolver{}
cmd := cmds.NewBuilder(cmds.NoSlot).Get().Key("one").Build()
got := resolver.OpName(t.Context(), cmd)
if got != "GET" {
t.Errorf("OpName() = %v, want %v", got, "GET")
}
}
func TestDefaultOpNameResolver_MultiOpName(t *testing.T) {
builder := cmds.NewBuilder(cmds.NoSlot)
tests := [...]struct {
name string
limit int
cmds rueidis.Commands
want string
}{
{
name: "empty commands",
},
{
name: "single command",
cmds: rueidis.Commands{
builder.Get().Key("one").Build(),
},
want: "GET",
},
{
name: "many commands without limit",
cmds: rueidis.Commands{
builder.Get().Key("one").Build(),
builder.Mget().Key("two").Build(),
builder.Strlen().Key("three").Build(),
},
want: "GET MGET STRLEN",
},
{
name: "many commands with limit",
limit: 2,
cmds: rueidis.Commands{
builder.Get().Key("one").Build(),
builder.Mget().Key("two").Build(),
builder.Strlen().Key("three").Build(),
},
want: "GET MGET",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
resolver := DefaultOpNameResolver{Limit: tt.limit}
got := resolver.MultiOpName(t.Context(), tt.cmds)
if got != tt.want {
t.Errorf("MultiOpName() = %v, want %v", got, tt.want)
}
})
}
}
func TestDefaultOpNameResolver_MultiCacheableOpName(t *testing.T) {
builder := cmds.NewBuilder(cmds.NoSlot)
tests := [...]struct {
name string
limit int
cmds []rueidis.CacheableTTL
want string
}{
{
name: "empty commands",
},
{
name: "single command",
cmds: []rueidis.CacheableTTL{
rueidis.CT(builder.Get().Key("one").Cache(), time.Minute),
},
want: "GET",
},
{
name: "many commands without limit",
cmds: []rueidis.CacheableTTL{
rueidis.CT(builder.Get().Key("one").Cache(), time.Minute),
rueidis.CT(builder.Mget().Key("two").Cache(), time.Minute),
rueidis.CT(builder.Strlen().Key("three").Cache(), time.Minute),
},
want: "GET MGET STRLEN",
},
{
name: "many commands with limit",
limit: 2,
cmds: []rueidis.CacheableTTL{
rueidis.CT(builder.Get().Key("one").Cache(), time.Minute),
rueidis.CT(builder.Mget().Key("two").Cache(), time.Minute),
rueidis.CT(builder.Strlen().Key("three").Cache(), time.Minute),
},
want: "GET MGET",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
resolver := DefaultOpNameResolver{Limit: tt.limit}
got := resolver.MultiCacheableOpName(t.Context(), tt.cmds)
if got != tt.want {
t.Errorf("MultiOpName() = %v, want %v", got, tt.want)
}
})
}
}