forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_test.go
77 lines (72 loc) · 1.3 KB
/
utils_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package client_test
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/client"
)
func TestPaginate(t *testing.T) {
testCases := []struct {
name string
numObjs, page, limit, defLimit int
expectedStart, expectedEnd int
}{
{
"all objects in a single page",
100, 1, 100, 100,
0, 100,
},
{
"page one of three",
75, 1, 25, 100,
0, 25,
},
{
"page two of three",
75, 2, 25, 100,
25, 50,
},
{
"page three of three",
75, 3, 25, 100,
50, 75,
},
{
"end is greater than total number of objects",
75, 2, 50, 100,
50, 75,
},
{
"fallback to default limit",
75, 5, 0, 10,
40, 50,
},
{
"invalid start page",
75, 4, 25, 100,
-1, -1,
},
{
"invalid zero start page",
75, 0, 25, 100,
-1, -1,
},
{
"invalid negative start page",
75, -1, 25, 100,
-1, -1,
},
{
"invalid default limit",
75, 2, 0, -10,
-1, -1,
},
}
for i, tc := range testCases {
i, tc := i, tc
t.Run(tc.name, func(t *testing.T) {
start, end := client.Paginate(tc.numObjs, tc.page, tc.limit, tc.defLimit)
require.Equal(t, tc.expectedStart, start, "invalid result; test case #%d", i)
require.Equal(t, tc.expectedEnd, end, "invalid result; test case #%d", i)
})
}
}