forked from redis/rueidis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
match_test.go
107 lines (95 loc) · 3.2 KB
/
match_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
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
package mock
import (
"reflect"
"strings"
"testing"
"github.com/golang/mock/gomock"
"github.com/redis/rueidis"
"github.com/redis/rueidis/internal/cmds"
)
func TestMatch_Completed(t *testing.T) {
cmd := cmds.NewBuilder(cmds.NoSlot).Get().Key("k").Build()
if m := Match("GET", "k"); !m.Matches(cmd) {
t.Fatalf("not matched %s", m.String())
}
}
func TestMatchFn_Completed(t *testing.T) {
cmd := cmds.NewBuilder(cmds.NoSlot).Get().Key("k").Build()
if m := MatchFn(func(cmd []string) bool {
return reflect.DeepEqual(cmd, []string{"GET", "k"})
}, "GET k"); !m.Matches(cmd) {
t.Fatalf("not matched %s", m.String())
}
}
func TestMatch_Cacheable(t *testing.T) {
cmd := cmds.NewBuilder(cmds.NoSlot).Get().Key("k").Cache()
if m := Match("GET", "k"); !m.Matches(cmd) {
t.Fatalf("not matched %s", m.String())
}
}
func TestMatchFn_Cacheable(t *testing.T) {
cmd := cmds.NewBuilder(cmds.NoSlot).Get().Key("k").Cache()
if m := MatchFn(func(cmd []string) bool {
return reflect.DeepEqual(cmd, []string{"GET", "k"})
}, "GET k"); !m.Matches(cmd) {
t.Fatalf("not matched %s", m.String())
}
}
func TestMatch_CacheableTTL(t *testing.T) {
cmd := cmds.NewBuilder(cmds.NoSlot).Get().Key("k").Cache()
if m := Match("GET", "k"); !m.Matches(rueidis.CacheableTTL{Cmd: cmd}) {
t.Fatalf("not matched %s", m.String())
}
}
func TestMatchFn_CacheableTTL(t *testing.T) {
cmd := cmds.NewBuilder(cmds.NoSlot).Get().Key("k").Cache()
if m := MatchFn(func(cmd []string) bool {
return reflect.DeepEqual(cmd, []string{"GET", "k"})
}, "GET k"); !m.Matches(cmd) {
t.Fatalf("not matched %s", m.String())
}
}
func TestMatch_Other(t *testing.T) {
if m := Match("GET", "k"); m.Matches(1) {
t.Fatalf("unexpected matched %s", m.String())
}
if m := Match("GET", "k"); m.Matches([]rueidis.Completed{
cmds.NewBuilder(cmds.NoSlot).Get().Key("k").Build(), // https://github.com/redis/rueidis/issues/120
}) {
t.Fatalf("unexpected matched %s", m.String())
}
}
func TestMatchFn_Other(t *testing.T) {
if m := MatchFn(func(cmd []string) bool {
return reflect.DeepEqual(cmd, []string{"GET", "k"})
}, "GET k"); m.Matches(1) {
t.Fatalf("unexpected matched %s", m.String())
}
if m := MatchFn(func(cmd []string) bool {
return reflect.DeepEqual(cmd, []string{"GET", "k"})
}, "GET k"); m.Matches([]rueidis.Completed{
cmds.NewBuilder(cmds.NoSlot).Get().Key("k").Build(), // https://github.com/redis/rueidis/issues/120
}) {
t.Fatalf("unexpected matched %s", m.String())
}
}
func TestMatch_Format(t *testing.T) {
matcher := Match("GET", "t")
if !strings.Contains(matcher.String(), "GET t") {
t.Fatalf("unexpected format %v", matcher.String())
}
if !strings.Contains(matcher.(gomock.GotFormatter).Got(cmds.NewBuilder(cmds.NoSlot).Get().Key("k").Build()), "GET k") {
t.Fatalf("unexpected format %v", matcher.String())
}
}
func TestMatchFn_Format(t *testing.T) {
matcher := MatchFn(func(cmd []string) bool {
return reflect.DeepEqual(cmd, []string{"GET", "t"})
}, "GET t")
if !strings.Contains(matcher.String(), "GET t") {
t.Fatalf("unexpected format %v", matcher.String())
}
if !strings.Contains(matcher.(gomock.GotFormatter).Got(cmds.NewBuilder(cmds.NoSlot).Get().Key("k").Build()), "GET k") {
t.Fatalf("unexpected format %v", matcher.String())
}
}