Also remove duplicate pagination: - move function to extract query params into types/rest - adjust pagination values locally until available in tendermint for validators Code cleanup: - helper function in test - fix pagination description in swagger.yaml - uint instead of int when possible Closes: #3226 Closes: #3991
32 lines
567 B
Go
32 lines
567 B
Go
package rest
|
|
|
|
import (
|
|
"github.com/stretchr/testify/require"
|
|
"testing"
|
|
)
|
|
|
|
func TestAdjustPagination(t *testing.T) {
|
|
type args struct {
|
|
s string
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
size uint
|
|
page uint
|
|
limit uint
|
|
start uint
|
|
end uint
|
|
}{
|
|
{"Ok", 3, 0, 1, 0, 1},
|
|
{"Limit too big", 3, 1, 5, 0, 3},
|
|
{"Page over limit", 3, 2, 3, 0, 3},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
start, end := adjustPagination(tt.size, tt.page, tt.limit)
|
|
require.Equal(t, tt.start, start)
|
|
require.Equal(t, tt.end, end)
|
|
})
|
|
}
|
|
}
|