-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeys_test.go
91 lines (84 loc) · 2.29 KB
/
keys_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
package rds
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestSKey(t *testing.T) {
cases := []struct {
entity string
key string
value interface{}
want string
}{
{"users", "1234", 78, "users:1234:78"},
{"users", "bob", "78", "users:bob:78"},
{"users", "bob", "78-90", "users:bob:78-90"},
{"users:students", "bob", "78-90", "users:students:bob:78-90"},
{"users_students", "bob", "78-90", "users_students:bob:78-90"},
}
for i, tc := range cases {
assert.Equal(t, tc.want, sKey(tc.entity, tc.key, tc.value), fmt.Sprintf("Test case #%d", i))
}
}
func TestZKey(t *testing.T) {
cases := []struct {
entity string
key string
want string
}{
{"users", "bob", "users:bob"},
{"users", "bob", "users:bob"},
{"users:students", "bob", "users:students:bob"},
{"users_students", "bob", "users_students:bob"},
}
for i, tc := range cases {
assert.Equal(t, tc.want, zKey(tc.entity, tc.key), fmt.Sprintf("Test case #%d", i))
}
}
func TestSKeyLastAll(t *testing.T) {
cases := []struct {
entity string
key string
want string
}{
{"users", "bob", "users:bob:*"},
{"users", "bob", "users:bob:*"},
{"users:students", "bob", "users:students:bob:*"},
{"users_students", "bob", "users_students:bob:*"},
}
for i, tc := range cases {
assert.Equal(t, tc.want, sKeyLastAll(tc.entity, tc.key), fmt.Sprintf("Test case #%d", i))
}
}
func TestSKeyIDsAll(t *testing.T) {
cases := []struct {
entity string
want string
}{
{"users", "users:all_ids"},
{"", ":all_ids"},
{"users:students", "users:students:all_ids"},
{"users_students", "users_students:all_ids"},
}
for i, tc := range cases {
assert.Equal(t, tc.want, sKeyIDsAll(tc.entity), fmt.Sprintf("Test case #%d", i))
}
}
func TestAuxIndexListKey(t *testing.T) {
cases := []struct {
id string
sorted bool
want string
}{
{"users:123", true, "users:123:secondary_idx_zset_list"},
{"users:123", false, "users:123:secondary_idx_set_list"},
{"", true, ":secondary_idx_zset_list"},
{"", false, ":secondary_idx_set_list"},
{"users:", true, "users::secondary_idx_zset_list"},
{"users_foo:abcdef123", false, "users_foo:abcdef123:secondary_idx_set_list"},
}
for i, tc := range cases {
assert.Equal(t, tc.want, auxIndexListKey(tc.id, tc.sorted), fmt.Sprintf("Test case #%d", i))
}
}