Skip to content

Commit 4f4c3ae

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

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-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

+25-2
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,30 @@ func SubtestFilter(t *testing.T, ds dstore.Datastore) {
222222
Op: dsq.LessThan,
223223
Key: "/2",
224224
})
225+
226+
test(&dsq.FilterKeyCompare{
227+
Op: dsq.Equal,
228+
Key: "/0key0",
229+
})
230+
231+
test(dsq.FilterKeyPrefix{
232+
Prefix: "/0key0",
233+
})
234+
235+
test(&dsq.FilterKeyPrefix{
236+
Prefix: "/0key0",
237+
})
238+
239+
test(dsq.FilterValueCompare{
240+
Op: dsq.LessThan,
241+
Value: randValue(),
242+
})
243+
}
244+
245+
func randValue() []byte {
246+
value := make([]byte, 64)
247+
rand.Read(value)
248+
return value
225249
}
226250

227251
func subtestQuery(t *testing.T, ds dstore.Datastore, q dsq.Query, check func(t *testing.T, input, output []dsq.Entry)) {
@@ -230,8 +254,7 @@ func subtestQuery(t *testing.T, ds dstore.Datastore, q dsq.Query, check func(t *
230254
for i := 0; i < count; i++ {
231255
s := fmt.Sprintf("%dkey%d", i, i)
232256
key := dstore.NewKey(s).String()
233-
value := make([]byte, 64)
234-
rand.Read(value)
257+
value := randValue()
235258
input = append(input, dsq.Entry{
236259
Key: key,
237260
Value: value,

0 commit comments

Comments
 (0)