aboutsummaryrefslogtreecommitdiff
path: root/internal/api/api_test.go
diff options
context:
space:
mode:
authorEthan Lee <ethanalee@google.com>2026-03-24 20:45:28 +0000
committerGopher Robot <gobot@golang.org>2026-04-02 08:01:06 -0700
commit2d0d60d0e456af02dfc52d79053d5a3a20fb11ff (patch)
tree62a8e4c6534dd434e8eb2b45fa152033624e4b41 /internal/api/api_test.go
parentaed8d2b9be2361625f8b305b91885f7c1a710f07 (diff)
downloadgo-x-pkgsite-2d0d60d0e456af02dfc52d79053d5a3a20fb11ff.tar.xz
internal/api: implement filtering logic based on query params
Change-Id: Ica73fe1f12b2c65d08240479d1a135a51c3ae566 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/758822 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> kokoro-CI: kokoro <noreply+kokoro@google.com> Auto-Submit: Ethan Lee <ethanalee@google.com> Reviewed-by: Jonathan Amsterdam <jba@google.com>
Diffstat (limited to 'internal/api/api_test.go')
-rw-r--r--internal/api/api_test.go28
1 files changed, 26 insertions, 2 deletions
diff --git a/internal/api/api_test.go b/internal/api/api_test.go
index daf49910..15659c37 100644
--- a/internal/api/api_test.go
+++ b/internal/api/api_test.go
@@ -387,8 +387,18 @@ func TestServeModulePackages(t *testing.T) {
ds.MustInsertModule(ctx, &internal.Module{
ModuleInfo: internal.ModuleInfo{ModulePath: modulePath, Version: version},
Units: []*internal.Unit{
- {UnitMeta: internal.UnitMeta{Path: modulePath, Name: "pkg1"}},
- {UnitMeta: internal.UnitMeta{Path: modulePath + "/sub", Name: "pkg2"}},
+ {
+ UnitMeta: internal.UnitMeta{Path: modulePath, Name: "pkg1"},
+ Documentation: []*internal.Documentation{
+ {Synopsis: "synopsis for pkg1"},
+ },
+ },
+ {
+ UnitMeta: internal.UnitMeta{Path: modulePath + "/sub", Name: "pkg2"},
+ Documentation: []*internal.Documentation{
+ {Synopsis: "synopsis for pkg2"},
+ },
+ },
},
})
for _, test := range []struct {
@@ -408,6 +418,20 @@ func TestServeModulePackages(t *testing.T) {
wantTotal: 2,
},
{
+ name: "filtering",
+ url: "/v1/packages/example.com?version=v1.0.0&filter=sub",
+ wantStatus: http.StatusOK,
+ wantCount: 1,
+ wantTotal: 1,
+ },
+ {
+ name: "filtering synopsis",
+ url: "/v1/packages/example.com?version=v1.0.0&filter=pkg2",
+ wantStatus: http.StatusOK,
+ wantCount: 1,
+ wantTotal: 1,
+ },
+ {
name: "limit and token",
url: "/v1/packages/example.com?version=v1.0.0&limit=1",
wantStatus: http.StatusOK,