Skip to content

Commit 68a7796

Browse files
committed
query: add tests for ReturnSizes
1 parent b089db1 commit 68a7796

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

test/basic_tests.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ func SubtestFilter(t *testing.T, ds dstore.Datastore) {
301301
test(new(testFilter))
302302
}
303303

304+
func SubtestReturnSizes(t *testing.T, ds dstore.Datastore) {
305+
subtestQuery(t, ds, dsq.Query{ReturnsSizes: true}, 100)
306+
}
307+
304308
func randValue() []byte {
305309
value := make([]byte, 64)
306310
rand.Read(value)
@@ -376,7 +380,9 @@ func subtestQuery(t *testing.T, ds dstore.Datastore, q dsq.Query, count int) {
376380
if !q.KeysOnly && !bytes.Equal(actual[i].Value, expected[i].Value) {
377381
t.Errorf("value mismatch for result %d (key=%q)", i, expected[i].Key)
378382
}
379-
383+
if q.ReturnsSizes && actual[i].Size <= 0 {
384+
t.Errorf("for result %d, expected size > 0 with ReturnsSizes", i)
385+
}
380386
}
381387

382388
t.Log("deleting all keys")

test/suite.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var BasicSubtests = []func(t *testing.T, ds dstore.Datastore){
1818
SubtestLimit,
1919
SubtestFilter,
2020
SubtestManyKeysAndQuery,
21+
SubtestReturnSizes,
2122
}
2223

2324
// BatchSubtests is a list of all basic batching datastore tests.

0 commit comments

Comments
 (0)