warehouse/utils/pagination_test.go
2024-11-17 22:08:06 +01:00

38 lines
605 B
Go

package utils
import (
"fmt"
"reflect"
"testing"
)
func TestPagination(t *testing.T) {
cases := []struct {
Slice []int
Offset int
Limit int
Expected []int
}{
{
Slice: []int{1, 2, 3, 4, 5},
Offset: 1,
Limit: 4,
Expected: []int{2, 3, 4, 5},
},
}
for _, tc := range cases {
t.Run(
fmt.Sprintf("%v %d %d %v", tc.Slice, tc.Offset, tc.Limit, tc.Expected),
func(t *testing.T) {
got := Paginate(tc.Slice, tc.Offset, tc.Limit)
if !reflect.DeepEqual(got, tc.Expected) {
t.Errorf("Expected %v, but got %v", tc.Expected, got)
}
})
}
}