Skip to content

Commit ffc9f91

Browse files
committed
test: improve query coverage
1 parent 54ed9bc commit ffc9f91

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

keytransform/keytransform_test.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,14 @@ func strsToKeys(strs []string) []ds.Key {
113113
return keys
114114
}
115115

116-
func TestSuite(t *testing.T) {
116+
func TestSuiteDefaultPair(t *testing.T) {
117117
mpds := dstest.NewTestDatastore(true)
118118
ktds := kt.Wrap(mpds, pair)
119119
dstest.SubtestAll(t, ktds)
120120
}
121+
122+
func TestSuitePrefixTransform(t *testing.T) {
123+
mpds := dstest.NewTestDatastore(true)
124+
ktds := kt.Wrap(mpds, kt.PrefixTransform{Prefix: ds.NewKey("/foo")})
125+
dstest.SubtestAll(t, ktds)
126+
}

test/basic_tests.go

+35-2
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,14 @@ func SubtestManyKeysAndQuery(t *testing.T, ds dstore.Datastore) {
176176
})
177177
}
178178

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+
179187
func SubtestFilter(t *testing.T, ds dstore.Datastore) {
180188
test := func(filters ...dsq.Filter) {
181189
var types []string
@@ -222,6 +230,32 @@ func SubtestFilter(t *testing.T, ds dstore.Datastore) {
222230
Op: dsq.LessThan,
223231
Key: "/2",
224232
})
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
225259
}
226260

227261
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 *
230264
for i := 0; i < count; i++ {
231265
s := fmt.Sprintf("%dkey%d", i, i)
232266
key := dstore.NewKey(s).String()
233-
value := make([]byte, 64)
234-
rand.Read(value)
267+
value := randValue()
235268
input = append(input, dsq.Entry{
236269
Key: key,
237270
Value: value,

0 commit comments

Comments
 (0)