forked from baron/baron-sso
테넌트 목록 조회 cursor기반으로 재구성. 사용자 metadata 미사용 필드 제거
This commit is contained in:
55
backend/internal/pagination/cursor_test.go
Normal file
55
backend/internal/pagination/cursor_test.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package pagination
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
type testItem struct {
|
||||
id string
|
||||
createdAt time.Time
|
||||
}
|
||||
|
||||
func TestPageByCursorReturnsNextCursorAndNextPage(t *testing.T) {
|
||||
now := time.Date(2026, 5, 13, 8, 0, 0, 0, time.UTC)
|
||||
items := []testItem{
|
||||
{id: "c", createdAt: now},
|
||||
{id: "b", createdAt: now.Add(-time.Minute)},
|
||||
{id: "a", createdAt: now.Add(-2 * time.Minute)},
|
||||
}
|
||||
key := func(item testItem) (time.Time, string) {
|
||||
return item.createdAt, item.id
|
||||
}
|
||||
|
||||
firstPage, nextCursor, err := PageByCursor(items, 2, "", key)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, firstPage, 2)
|
||||
require.NotEmpty(t, nextCursor)
|
||||
|
||||
secondPage, nextCursor, err := PageByCursor(items, 2, nextCursor, key)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, secondPage, 1)
|
||||
require.Empty(t, nextCursor)
|
||||
require.Equal(t, "a", secondPage[0].id)
|
||||
}
|
||||
|
||||
func TestSortByKeyDescUsesIDAsTieBreaker(t *testing.T) {
|
||||
now := time.Date(2026, 5, 13, 8, 0, 0, 0, time.UTC)
|
||||
items := []testItem{
|
||||
{id: "a", createdAt: now},
|
||||
{id: "c", createdAt: now},
|
||||
{id: "b", createdAt: now},
|
||||
}
|
||||
|
||||
SortByKeyDesc(items, func(item testItem) (time.Time, string) {
|
||||
return item.createdAt, item.id
|
||||
})
|
||||
|
||||
require.Equal(t, []string{"c", "b", "a"}, []string{
|
||||
items[0].id,
|
||||
items[1].id,
|
||||
items[2].id,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user