Documentation
¶
Overview ¶
Package paginationtest provides a reusable test suite for cursor-based pagination.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ListResult ¶
ListResult contains the result of a paginated list request.
type Suite ¶
type Suite[T any] struct { Name string // Store name for test output NewItem func(index int) T // Create item at index (0=oldest) InsertMany func(ctx context.Context, items []T) error // Batch insert List func(ctx context.Context, opts ListOpts) (ListResult[T], error) GetID func(T) string // Unique ID for comparison Matches func(T) bool // Filter predicate (optional) AfterInsert func(ctx context.Context) error // Flush hook (optional) Cleanup func(ctx context.Context) error // Reset state (optional) }
Suite is a reusable test suite for cursor-based pagination.
Basic Usage ¶
For testing pagination without filters, provide NewItem and InsertMany:
suite := paginationtest.Suite[*Event]{
Name: "pglogstore",
NewItem: func(i int) *Event { ... },
InsertMany: func(ctx context.Context, items []*Event) error { ... },
List: func(ctx context.Context, opts ListOpts) (ListResult[*Event], error) { ... },
GetID: func(e *Event) string { return e.ID },
}
suite.Run(t)
Testing with Filters ¶
When testing pagination with filters, use Matches to tell the suite which created items should appear in results:
suite := paginationtest.Suite[*Event]{
NewItem: func(i int) *Event {
typ := "order.created"
if i%2 == 0 { typ = "order.updated" }
return &Event{Type: typ, ...}
},
List: func(ctx context.Context, opts ListOpts) (ListResult[*Event], error) {
return store.ListEvents(ctx, ListEventsRequest{EventType: "order.created", ...})
},
Matches: func(e *Event) bool {
return e.Type == "order.created" // mirrors filter in List
},
}
Async/Eventually Consistent Stores ¶
For stores with async writes, use AfterInsert:
suite := paginationtest.Suite[*Event]{
AfterInsert: func(ctx context.Context) error {
time.Sleep(100 * time.Millisecond)
return nil
},
}
Click to show internal directories.
Click to hide internal directories.