@@ -176,6 +176,14 @@ func SubtestManyKeysAndQuery(t *testing.T, ds dstore.Datastore) {
176
176
})
177
177
}
178
178
179
+ // need a custom test filter to test the "fallback" filter case for unknown
180
+ // filters.
181
+ type testFilter struct {}
182
+
183
+ func (testFilter ) Filter (e dsq.Entry ) bool {
184
+ return len (e .Key )% 2 == 0
185
+ }
186
+
179
187
func SubtestFilter (t * testing.T , ds dstore.Datastore ) {
180
188
test := func (filters ... dsq.Filter ) {
181
189
var types []string
@@ -222,6 +230,32 @@ func SubtestFilter(t *testing.T, ds dstore.Datastore) {
222
230
Op : dsq .LessThan ,
223
231
Key : "/2" ,
224
232
})
233
+
234
+ test (& dsq.FilterKeyCompare {
235
+ Op : dsq .Equal ,
236
+ Key : "/0key0" ,
237
+ })
238
+
239
+ test (dsq.FilterKeyPrefix {
240
+ Prefix : "/0key0" ,
241
+ })
242
+
243
+ test (& dsq.FilterKeyPrefix {
244
+ Prefix : "/0key0" ,
245
+ })
246
+
247
+ test (dsq.FilterValueCompare {
248
+ Op : dsq .LessThan ,
249
+ Value : randValue (),
250
+ })
251
+
252
+ test (new (testFilter ))
253
+ }
254
+
255
+ func randValue () []byte {
256
+ value := make ([]byte , 64 )
257
+ rand .Read (value )
258
+ return value
225
259
}
226
260
227
261
func subtestQuery (t * testing.T , ds dstore.Datastore , q dsq.Query , check func (t * testing.T , input , output []dsq.Entry )) {
@@ -230,8 +264,7 @@ func subtestQuery(t *testing.T, ds dstore.Datastore, q dsq.Query, check func(t *
230
264
for i := 0 ; i < count ; i ++ {
231
265
s := fmt .Sprintf ("%dkey%d" , i , i )
232
266
key := dstore .NewKey (s ).String ()
233
- value := make ([]byte , 64 )
234
- rand .Read (value )
267
+ value := randValue ()
235
268
input = append (input , dsq.Entry {
236
269
Key : key ,
237
270
Value : value ,
0 commit comments