query: add tests for ReturnSizes

parent b089db1e
...@@ -301,6 +301,10 @@ func SubtestFilter(t *testing.T, ds dstore.Datastore) { ...@@ -301,6 +301,10 @@ func SubtestFilter(t *testing.T, ds dstore.Datastore) {
test(new(testFilter)) test(new(testFilter))
} }
func SubtestReturnSizes(t *testing.T, ds dstore.Datastore) {
subtestQuery(t, ds, dsq.Query{ReturnsSizes: true}, 100)
}
func randValue() []byte { func randValue() []byte {
value := make([]byte, 64) value := make([]byte, 64)
rand.Read(value) rand.Read(value)
...@@ -376,7 +380,9 @@ func subtestQuery(t *testing.T, ds dstore.Datastore, q dsq.Query, count int) { ...@@ -376,7 +380,9 @@ func subtestQuery(t *testing.T, ds dstore.Datastore, q dsq.Query, count int) {
if !q.KeysOnly && !bytes.Equal(actual[i].Value, expected[i].Value) { if !q.KeysOnly && !bytes.Equal(actual[i].Value, expected[i].Value) {
t.Errorf("value mismatch for result %d (key=%q)", i, expected[i].Key) t.Errorf("value mismatch for result %d (key=%q)", i, expected[i].Key)
} }
if q.ReturnsSizes && actual[i].Size <= 0 {
t.Errorf("for result %d, expected size > 0 with ReturnsSizes", i)
}
} }
t.Log("deleting all keys") t.Log("deleting all keys")
......
...@@ -18,6 +18,7 @@ var BasicSubtests = []func(t *testing.T, ds dstore.Datastore){ ...@@ -18,6 +18,7 @@ var BasicSubtests = []func(t *testing.T, ds dstore.Datastore){
SubtestLimit, SubtestLimit,
SubtestFilter, SubtestFilter,
SubtestManyKeysAndQuery, SubtestManyKeysAndQuery,
SubtestReturnSizes,
} }
// BatchSubtests is a list of all basic batching datastore tests. // BatchSubtests is a list of all basic batching datastore tests.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment