From 68a77964d1eb0a20bf478b1a44fa274d22ebea53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Fri, 22 Nov 2019 14:49:37 +0100 Subject: [PATCH] query: add tests for ReturnSizes --- test/basic_tests.go | 8 +++++++- test/suite.go | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/test/basic_tests.go b/test/basic_tests.go index 519ccba..b1c73de 100644 --- a/test/basic_tests.go +++ b/test/basic_tests.go @@ -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) @@ -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") diff --git a/test/suite.go b/test/suite.go index 20d0f69..3d17401 100644 --- a/test/suite.go +++ b/test/suite.go @@ -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.