fix: update GetPage to check for empty items slice #13
+1
-1
@@ -52,7 +52,7 @@ func EncodeCursor(cursor string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetPage[T any](items []T, first *int, after *string, last *int, before *string, max int, fn func(T) string) ([]T, PageInfo) {
|
func GetPage[T any](items []T, first *int, after *string, last *int, before *string, max int, fn func(T) string) ([]T, PageInfo) {
|
||||||
if items == nil {
|
if len(items) == 0 {
|
||||||
return nil, PageInfo{}
|
return nil, PageInfo{}
|
||||||
}
|
}
|
||||||
tmp := min(max, len(items))
|
tmp := min(max, len(items))
|
||||||
|
|||||||
+7
-1
@@ -24,11 +24,17 @@ func TestGetPage(t *testing.T) {
|
|||||||
}
|
}
|
||||||
tests := []testCase[string]{
|
tests := []testCase[string]{
|
||||||
{
|
{
|
||||||
name: "empty",
|
name: "nil items",
|
||||||
args: args[string]{max: 10},
|
args: args[string]{max: 10},
|
||||||
wantItems: nil,
|
wantItems: nil,
|
||||||
wantPageInfo: PageInfo{},
|
wantPageInfo: PageInfo{},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "empty items",
|
||||||
|
args: args[string]{items: []string{}, max: 10},
|
||||||
|
wantItems: nil,
|
||||||
|
wantPageInfo: PageInfo{},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "first 2",
|
name: "first 2",
|
||||||
args: args[string]{items: []string{"1", "2", "3"}, first: ptr(2), max: 10, fn: func(s string) string { return s }},
|
args: args[string]{items: []string{"1", "2", "3"}, first: ptr(2), max: 10, fn: func(s string) string { return s }},
|
||||||
|
|||||||
Reference in New Issue
Block a user