Skip to content

Commit 2fe8b68

Browse files
committed
test(query): be thurough
1 parent ae428d8 commit 2fe8b68

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

query/filter_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
)
77

88
func testKeyFilter(t *testing.T, f Filter, keys []string, expect []string) {
9+
t.Helper()
910
e := make([]Entry, len(keys))
1011
for i, k := range keys {
1112
e[i] = Entry{Key: k}
@@ -37,6 +38,8 @@ func TestFilterKeyCompare(t *testing.T) {
3738
testKeyFilter(t, FilterKeyCompare{GreaterThan, "/ab"}, sampleKeys, []string{
3839
"/ab/c",
3940
"/ab/cd",
41+
"/ab/ef",
42+
"/ab/fg",
4043
"/abce",
4144
"/abcf",
4245
})
@@ -51,6 +54,8 @@ func TestFilterKeyPrefix(t *testing.T) {
5154
testKeyFilter(t, FilterKeyPrefix{"/a"}, sampleKeys, []string{
5255
"/ab/c",
5356
"/ab/cd",
57+
"/ab/ef",
58+
"/ab/fg",
5459
"/a",
5560
"/abce",
5661
"/abcf",
@@ -59,5 +64,7 @@ func TestFilterKeyPrefix(t *testing.T) {
5964
testKeyFilter(t, FilterKeyPrefix{"/ab/"}, sampleKeys, []string{
6065
"/ab/c",
6166
"/ab/cd",
67+
"/ab/ef",
68+
"/ab/fg",
6269
})
6370
}

query/order_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
)
77

88
func testKeyOrder(t *testing.T, f Order, keys []string, expect []string) {
9+
t.Helper()
10+
911
e := make([]Entry, len(keys))
1012
for i, k := range keys {
1113
e[i] = Entry{Key: k}
@@ -39,12 +41,16 @@ func TestOrderByKey(t *testing.T) {
3941
"/ab",
4042
"/ab/c",
4143
"/ab/cd",
44+
"/ab/ef",
45+
"/ab/fg",
4246
"/abce",
4347
"/abcf",
4448
})
4549
testKeyOrder(t, OrderByKeyDescending{}, sampleKeys, []string{
4650
"/abcf",
4751
"/abce",
52+
"/ab/fg",
53+
"/ab/ef",
4854
"/ab/cd",
4955
"/ab/c",
5056
"/ab",

query/query_test.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
var sampleKeys = []string{
1010
"/ab/c",
1111
"/ab/cd",
12+
"/ab/ef",
13+
"/ab/fg",
1214
"/a",
1315
"/abce",
1416
"/abcf",
@@ -60,8 +62,8 @@ func TestNaiveQueryApply(t *testing.T) {
6062

6163
q = Query{Offset: 3, Limit: 2}
6264
testNaiveQueryApply(t, q, sampleKeys, []string{
63-
"/abce",
64-
"/abcf",
65+
"/ab/fg",
66+
"/a",
6567
})
6668

6769
f := &FilterKeyCompare{Op: Equal, Key: "/ab"}
@@ -74,31 +76,37 @@ func TestNaiveQueryApply(t *testing.T) {
7476
testNaiveQueryApply(t, q, sampleKeys, []string{
7577
"/ab/c",
7678
"/ab/cd",
79+
"/ab/ef",
80+
"/ab/fg",
7781
})
7882

7983
q = Query{Orders: []Order{OrderByKeyDescending{}}}
8084
testNaiveQueryApply(t, q, sampleKeys, []string{
8185
"/abcf",
8286
"/abce",
87+
"/ab/fg",
88+
"/ab/ef",
8389
"/ab/cd",
8490
"/ab/c",
8591
"/ab",
8692
"/a",
8793
})
8894

8995
q = Query{
90-
Limit: 3,
96+
Limit: 2,
9197
Offset: 1,
9298
Prefix: "/ab",
9399
Orders: []Order{OrderByKey{}},
94100
}
95101
testNaiveQueryApply(t, q, sampleKeys, []string{
96102
"/ab/cd",
103+
"/ab/ef",
97104
})
98105
}
99106

100107
func TestLimit(t *testing.T) {
101108
testKeyLimit := func(t *testing.T, limit int, keys []string, expect []string) {
109+
t.Helper()
102110
e := make([]Entry, len(keys))
103111
for i, k := range keys {
104112
e[i] = Entry{Key: k}
@@ -112,6 +120,8 @@ func TestLimit(t *testing.T) {
112120
testKeyLimit(t, 0, sampleKeys, []string{ // none
113121
"/ab/c",
114122
"/ab/cd",
123+
"/ab/ef",
124+
"/ab/fg",
115125
"/a",
116126
"/abce",
117127
"/abcf",
@@ -121,6 +131,8 @@ func TestLimit(t *testing.T) {
121131
testKeyLimit(t, 10, sampleKeys, []string{ // large
122132
"/ab/c",
123133
"/ab/cd",
134+
"/ab/ef",
135+
"/ab/fg",
124136
"/a",
125137
"/abce",
126138
"/abcf",
@@ -136,6 +148,7 @@ func TestLimit(t *testing.T) {
136148
func TestOffset(t *testing.T) {
137149

138150
testOffset := func(t *testing.T, offset int, keys []string, expect []string) {
151+
t.Helper()
139152
e := make([]Entry, len(keys))
140153
for i, k := range keys {
141154
e[i] = Entry{Key: k}
@@ -149,6 +162,8 @@ func TestOffset(t *testing.T) {
149162
testOffset(t, 0, sampleKeys, []string{ // none
150163
"/ab/c",
151164
"/ab/cd",
165+
"/ab/ef",
166+
"/ab/fg",
152167
"/a",
153168
"/abce",
154169
"/abcf",
@@ -159,6 +174,8 @@ func TestOffset(t *testing.T) {
159174
})
160175

161176
testOffset(t, 2, sampleKeys, []string{
177+
"/ab/ef",
178+
"/ab/fg",
162179
"/a",
163180
"/abce",
164181
"/abcf",

0 commit comments

Comments
 (0)