Skip to content

Commit

Permalink
Fix tests to check total count
Browse files Browse the repository at this point in the history
Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com>
  • Loading branch information
dborovcanin committed Jun 20, 2019
1 parent c980f05 commit b172544
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
14 changes: 11 additions & 3 deletions things/postgres/channels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -217,45 +218,52 @@ 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,
offset: 0,
limit: n,
name: "wrong",
size: 0,
total: 0,
},
}

for desc, tc := range cases {
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))
}
}
Expand Down
13 changes: 10 additions & 3 deletions things/postgres/things_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -393,45 +393,52 @@ 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,
offset: 0,
limit: n,
name: "wrong",
size: 0,
total: 0,
},
}

for desc, tc := range cases {
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))
}
}
Expand Down

0 comments on commit b172544

Please sign in to comment.