github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/client/utils_test.go (about) 1 package client_test 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 8 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client" 9 ) 10 11 func TestPaginate(t *testing.T) { 12 testCases := []struct { 13 name string 14 numObjs, page, limit, defLimit int 15 expectedStart, expectedEnd int 16 }{ 17 { 18 "all objects in a single page", 19 100, 1, 100, 100, 20 0, 100, 21 }, 22 { 23 "page one of three", 24 75, 1, 25, 100, 25 0, 25, 26 }, 27 { 28 "page two of three", 29 75, 2, 25, 100, 30 25, 50, 31 }, 32 { 33 "page three of three", 34 75, 3, 25, 100, 35 50, 75, 36 }, 37 { 38 "end is greater than total number of objects", 39 75, 2, 50, 100, 40 50, 75, 41 }, 42 { 43 "invalid start page", 44 75, 4, 25, 100, 45 -1, -1, 46 }, 47 { 48 "invalid zero start page", 49 75, 0, 25, 100, 50 -1, -1, 51 }, 52 } 53 54 for i, tc := range testCases { 55 i, tc := i, tc 56 t.Run(tc.name, func(t *testing.T) { 57 start, end := client.Paginate(tc.numObjs, tc.page, tc.limit, tc.defLimit) 58 require.Equal(t, tc.expectedStart, start, "invalid result; test case #%d", i) 59 require.Equal(t, tc.expectedEnd, end, "invalid result; test case #%d", i) 60 }) 61 } 62 }