From 50f3e086f52d8af852dacd214738f8f83a9007aa Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Tue, 24 Mar 2026 15:29:27 +0000 Subject: internal/api: centralize pagination and trimming logic - All handlers returning lists will utilize the paginate helper. - Path trimming logic has also been modularized within a helper. Change-Id: I5c99ae8264ea76587137e29524ad19795652e43b Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/758642 Auto-Submit: Ethan Lee Reviewed-by: Jonathan Amsterdam LUCI-TryBot-Result: Go LUCI kokoro-CI: kokoro --- internal/api/api_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'internal/api/api_test.go') diff --git a/internal/api/api_test.go b/internal/api/api_test.go index 0bc409c5..9930e3c9 100644 --- a/internal/api/api_test.go +++ b/internal/api/api_test.go @@ -399,12 +399,30 @@ func TestServeModulePackages(t *testing.T) { url string wantStatus int wantCount int + wantTotal int + wantToken string }{ { name: "all packages", url: "/v1/packages/example.com?version=v1.0.0", wantStatus: http.StatusOK, wantCount: 2, + wantTotal: 2, + }, + { + name: "limit and token", + url: "/v1/packages/example.com?version=v1.0.0&limit=1", + wantStatus: http.StatusOK, + wantCount: 1, + wantTotal: 2, + wantToken: "1", + }, + { + name: "next page", + url: "/v1/packages/example.com?version=v1.0.0&limit=1&token=1", + wantStatus: http.StatusOK, + wantCount: 1, + wantTotal: 2, }, } { t.Run(test.name, func(t *testing.T) { @@ -428,6 +446,12 @@ func TestServeModulePackages(t *testing.T) { if len(got.Items) != test.wantCount { t.Errorf("count = %d, want %d", len(got.Items), test.wantCount) } + if got.Total != test.wantTotal { + t.Errorf("total = %d, want %d", got.Total, test.wantTotal) + } + if got.NextPageToken != test.wantToken { + t.Errorf("token = %q, want %q", got.NextPageToken, test.wantToken) + } } }) } -- cgit v1.3