aboutsummaryrefslogtreecommitdiff
path: root/internal/api/api_test.go
diff options
context:
space:
mode:
authorEthan Lee <ethanalee@google.com>2026-03-24 15:29:27 +0000
committerGopher Robot <gobot@golang.org>2026-03-31 12:06:07 -0700
commit50f3e086f52d8af852dacd214738f8f83a9007aa (patch)
tree3cf980b0797cfe39cf4814eed64f928e6e2a8bec /internal/api/api_test.go
parent553cc7bbf577a297ad6e78870316bdf5e4c19e04 (diff)
downloadgo-x-pkgsite-50f3e086f52d8af852dacd214738f8f83a9007aa.tar.xz
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 <ethanalee@google.com> Reviewed-by: Jonathan Amsterdam <jba@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> kokoro-CI: kokoro <noreply+kokoro@google.com>
Diffstat (limited to 'internal/api/api_test.go')
-rw-r--r--internal/api/api_test.go24
1 files changed, 24 insertions, 0 deletions
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)
+ }
}
})
}