aboutsummaryrefslogtreecommitdiff
path: root/internal/api/api_test.go
diff options
context:
space:
mode:
authorEthan Lee <ethanalee@google.com>2026-04-07 14:44:16 +0000
committerEthan Lee <ethanalee@google.com>2026-04-07 09:23:15 -0700
commit3c8abd6a69a5031ca55e55d16e725476f1d69cba (patch)
treec089fea9b2c6168836cadb7ff46d95e82c060760 /internal/api/api_test.go
parentd1eedfe77fdd85e4ec9dcef7e4a4411116eddbb2 (diff)
downloadgo-x-pkgsite-3c8abd6a69a5031ca55e55d16e725476f1d69cba.tar.xz
internal/api: add support for readme and licenses in ServeModule
- Utilize conditional fieldset in GetUnit to efficiently retrieve readme and license fields. - Modify Module type to include HasGoMod. Change-Id: Id22ac3f2485392749742332701d2e913f047b3da Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/763401 kokoro-CI: kokoro <noreply+kokoro@google.com> Auto-Submit: Ethan Lee <ethanalee@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Jonathan Amsterdam <jba@google.com>
Diffstat (limited to 'internal/api/api_test.go')
-rw-r--r--internal/api/api_test.go80
1 files changed, 66 insertions, 14 deletions
diff --git a/internal/api/api_test.go b/internal/api/api_test.go
index 15659c37..36066f46 100644
--- a/internal/api/api_test.go
+++ b/internal/api/api_test.go
@@ -230,20 +230,34 @@ func TestServeModule(t *testing.T) {
version = "v1.2.3"
)
+ mi1 := sample.ModuleInfo(modulePath, version)
+ mi1.LatestVersion = "v1.2.4"
+ mi1.HasGoMod = true
+
ds.MustInsertModule(ctx, &internal.Module{
- ModuleInfo: internal.ModuleInfo{
- ModulePath: modulePath,
- Version: version,
- },
+ ModuleInfo: *mi1,
+ Licenses: sample.Licenses(),
Units: []*internal.Unit{{
UnitMeta: internal.UnitMeta{
- Path: modulePath,
- ModuleInfo: internal.ModuleInfo{
- ModulePath: modulePath,
- Version: version,
- },
+ Path: modulePath,
+ ModuleInfo: *mi1,
+ },
+ Readme: &internal.Readme{Filepath: "README.md", Contents: "Hello world"},
+ Licenses: sample.LicenseMetadata(),
+ }},
+ })
+
+ mi2 := sample.ModuleInfo(modulePath, "v1.2.4")
+ mi2.LatestVersion = "v1.2.4"
+ mi2.HasGoMod = true
+
+ ds.MustInsertModule(ctx, &internal.Module{
+ ModuleInfo: *mi2,
+ Units: []*internal.Unit{{
+ UnitMeta: internal.UnitMeta{
+ Path: modulePath,
+ ModuleInfo: *mi2,
},
- Readme: &internal.Readme{Filepath: "README.md", Contents: "Hello world"},
}},
})
@@ -258,8 +272,24 @@ func TestServeModule(t *testing.T) {
url: "/v1/module/example.com?version=v1.2.3",
wantStatus: http.StatusOK,
want: &Module{
- Path: modulePath,
- Version: version,
+ Path: modulePath,
+ Version: version,
+ IsRedistributable: true,
+ HasGoMod: true,
+ RepoURL: "https://example.com",
+ },
+ },
+ {
+ name: "latest module metadata",
+ url: "/v1/module/example.com?version=v1.2.4",
+ wantStatus: http.StatusOK,
+ want: &Module{
+ Path: modulePath,
+ Version: "v1.2.4",
+ IsLatest: true,
+ IsRedistributable: true,
+ HasGoMod: true,
+ RepoURL: "https://example.com",
},
},
{
@@ -273,14 +303,36 @@ func TestServeModule(t *testing.T) {
url: "/v1/module/example.com?version=v1.2.3&readme=true",
wantStatus: http.StatusOK,
want: &Module{
- Path: modulePath,
- Version: version,
+ Path: modulePath,
+ Version: version,
+ IsRedistributable: true,
+ HasGoMod: true,
+ RepoURL: "https://example.com",
Readme: &Readme{
Filepath: "README.md",
Contents: "Hello world",
},
},
},
+ {
+ name: "module with licenses",
+ url: "/v1/module/example.com?version=v1.2.3&licenses=true",
+ wantStatus: http.StatusOK,
+ want: &Module{
+ Path: modulePath,
+ Version: version,
+ IsRedistributable: true,
+ HasGoMod: true,
+ RepoURL: "https://example.com",
+ Licenses: []License{
+ {
+ Types: []string{"MIT"},
+ FilePath: "LICENSE",
+ Contents: "Lorem Ipsum",
+ },
+ },
+ },
+ },
} {
t.Run(test.name, func(t *testing.T) {
r := httptest.NewRequest("GET", test.url, nil)