From 5be49a8e80ce4d4fd0e2a59892844bdfeb4b98b7 Mon Sep 17 00:00:00 2001 From: "Jens L." Date: Fri, 6 Sep 2024 18:38:00 +0200 Subject: [PATCH] internal: fix go paginator not setting page correctly (#11253) Signed-off-by: Jens Langhammer --- internal/outpost/ak/api_utils.go | 7 ++++--- internal/outpost/ak/api_utils_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 internal/outpost/ak/api_utils_test.go diff --git a/internal/outpost/ak/api_utils.go b/internal/outpost/ak/api_utils.go index 6a8a90280b..d732ba7556 100644 --- a/internal/outpost/ak/api_utils.go +++ b/internal/outpost/ak/api_utils.go @@ -35,10 +35,11 @@ func Paginator[Tobj any, Treq any, Tres PaginatorResponse[Tobj]]( req PaginatorRequest[Treq, Tres], opts PaginatorOptions, ) ([]Tobj, error) { + var bfreq, cfreq interface{} fetchOffset := func(page int32) (Tres, error) { - req.Page(page) - req.PageSize(int32(opts.PageSize)) - res, _, err := req.Execute() + bfreq = req.Page(page) + cfreq = bfreq.(PaginatorRequest[Treq, Tres]).PageSize(int32(opts.PageSize)) + res, _, err := cfreq.(PaginatorRequest[Treq, Tres]).Execute() if err != nil { opts.Logger.WithError(err).WithField("page", page).Warning("failed to fetch page") } diff --git a/internal/outpost/ak/api_utils_test.go b/internal/outpost/ak/api_utils_test.go new file mode 100644 index 0000000000..ac751f943a --- /dev/null +++ b/internal/outpost/ak/api_utils_test.go @@ -0,0 +1,26 @@ +package ak + +// func Test_PaginatorCompile(t *testing.T) { +// req := api.ApiCoreUsersListRequest{} +// Paginator(req, PaginatorOptions{ +// PageSize: 100, +// }) +// } + +// func Test_PaginatorCompileExplicit(t *testing.T) { +// req := api.ApiCoreUsersListRequest{} +// Paginator[ +// api.User, +// api.ApiCoreUsersListRequest, +// *api.PaginatedUserList, +// ](req, PaginatorOptions{ +// PageSize: 100, +// }) +// } + +// func Test_PaginatorCompileOther(t *testing.T) { +// req := api.ApiOutpostsProxyListRequest{} +// Paginator(req, PaginatorOptions{ +// PageSize: 100, +// }) +// }