Skip to content

Commit

Permalink
query: add tests for ReturnSizes
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelMure committed Nov 22, 2019
1 parent b089db1 commit 68a7796
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion test/basic_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ func SubtestFilter(t *testing.T, ds dstore.Datastore) {
test(new(testFilter))
}

func SubtestReturnSizes(t *testing.T, ds dstore.Datastore) {
subtestQuery(t, ds, dsq.Query{ReturnsSizes: true}, 100)
}

func randValue() []byte {
value := make([]byte, 64)
rand.Read(value)
Expand Down Expand Up @@ -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) {
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")
Expand Down
1 change: 1 addition & 0 deletions test/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var BasicSubtests = []func(t *testing.T, ds dstore.Datastore){
SubtestLimit,
SubtestFilter,
SubtestManyKeysAndQuery,
SubtestReturnSizes,
}

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

0 comments on commit 68a7796

Please sign in to comment.