From b1725446f8f47cc7b51113e8985e13464ffbfccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Borov=C4=8Danin?= Date: Thu, 20 Jun 2019 18:58:29 +0200 Subject: [PATCH] Fix tests to check total count MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Dušan Borovčanin --- things/postgres/channels_test.go | 14 +++++++++++--- things/postgres/things_test.go | 13 ++++++++++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/things/postgres/channels_test.go b/things/postgres/channels_test.go index 494c31297c0..e4c24fa2c3b 100644 --- a/things/postgres/channels_test.go +++ b/things/postgres/channels_test.go @@ -204,7 +204,8 @@ func TestMultiChannelRetrieval(t *testing.T) { Owner: email, } - if i == 0 { + // Create first two Channels with name. + if i < 2 { c.Name = channelName } @@ -217,31 +218,36 @@ func TestMultiChannelRetrieval(t *testing.T) { limit uint64 name string size uint64 + total uint64 }{ "retrieve all channels with existing owner": { owner: email, offset: 0, limit: n, size: n, + total: n, }, "retrieve subset of channels with existing owner": { owner: email, offset: n / 2, limit: n, size: n / 2, + total: n, }, "retrieve channels with non-existing owner": { owner: wrongValue, offset: n / 2, limit: n, size: 0, + total: 0, }, - "retrieve all channels with existing name": { + "retrieve channels with existing name": { owner: email, - offset: 0, + offset: 1, limit: n, name: channelName, size: 1, + total: 2, }, "retrieve all channels with non-existing name": { owner: email, @@ -249,6 +255,7 @@ func TestMultiChannelRetrieval(t *testing.T) { limit: n, name: "wrong", size: 0, + total: 0, }, } @@ -256,6 +263,7 @@ func TestMultiChannelRetrieval(t *testing.T) { page, err := chanRepo.RetrieveAll(tc.owner, tc.offset, tc.limit, tc.name) size := uint64(len(page.Channels)) assert.Equal(t, tc.size, size, fmt.Sprintf("%s: expected %d got %d\n", desc, tc.size, size)) + assert.Equal(t, tc.total, page.Total, fmt.Sprintf("%s: expected %d got %d\n", desc, tc.total, page.Total)) assert.Nil(t, err, fmt.Sprintf("%s: expected no error got %d\n", desc, err)) } } diff --git a/things/postgres/things_test.go b/things/postgres/things_test.go index 381ff9362c1..3a4e30c3a83 100644 --- a/things/postgres/things_test.go +++ b/things/postgres/things_test.go @@ -379,8 +379,8 @@ func TestMultiThingRetrieval(t *testing.T) { Key: thkey, } - // Create first Thing with name - if i == 0 { + // Create first two Things with name. + if i < 2 { th.Name = name } @@ -393,31 +393,36 @@ func TestMultiThingRetrieval(t *testing.T) { limit uint64 name string size uint64 + total uint64 }{ "retrieve all things with existing owner": { owner: email, offset: 0, limit: n, size: n, + total: n, }, "retrieve subset of things with existing owner": { owner: email, offset: n / 2, limit: n, size: n / 2, + total: n, }, "retrieve things with non-existing owner": { owner: wrongValue, offset: 0, limit: n, size: 0, + total: 0, }, "retrieve things with existing name": { owner: email, - offset: 0, + offset: 1, limit: n, name: name, size: 1, + total: 2, }, "retrieve things with non-existing name": { owner: email, @@ -425,6 +430,7 @@ func TestMultiThingRetrieval(t *testing.T) { limit: n, name: "wrong", size: 0, + total: 0, }, } @@ -432,6 +438,7 @@ func TestMultiThingRetrieval(t *testing.T) { page, err := thingRepo.RetrieveAll(tc.owner, tc.offset, tc.limit, tc.name) size := uint64(len(page.Things)) assert.Equal(t, tc.size, size, fmt.Sprintf("%s: expected %d got %d\n", desc, tc.size, size)) + assert.Equal(t, tc.total, page.Total, fmt.Sprintf("%s: expected %d got %d\n", desc, tc.total, page.Total)) assert.Nil(t, err, fmt.Sprintf("%s: expected no error got %d\n", desc, err)) } }