aboutsummaryrefslogtreecommitdiff
path: root/internal/postgres
diff options
context:
space:
mode:
authorEthan Lee <ethanalee@google.com>2026-03-18 20:31:16 +0000
committerGopher Robot <gobot@golang.org>2026-03-25 08:29:54 -0700
commitc57126f9757fb25c781a59cb9ecc97b0af63727a (patch)
tree48b516ffb19fc89d36ed25094c3a8f74a11b754a /internal/postgres
parent86d1c7b3f2f2d36dbaf488d847c09e1655356ca7 (diff)
downloadgo-x-pkgsite-c57126f9757fb25c781a59cb9ecc97b0af63727a.tar.xz
all: add LatestVersion to ModuleInfo
- Add LatestVersion field to internal.ModuleInfo and update tests accordingly. - Changed some test formatting to improve readability. Change-Id: I1238e54614ef276d219b31d125cd2cad6b5a66f7 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/756901 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/postgres')
-rw-r--r--internal/postgres/details_test.go11
-rw-r--r--internal/postgres/insert_module_test.go4
-rw-r--r--internal/postgres/unit_test.go15
-rw-r--r--internal/postgres/version_test.go17
4 files changed, 44 insertions, 3 deletions
diff --git a/internal/postgres/details_test.go b/internal/postgres/details_test.go
index 53f55dd2..b2d83d66 100644
--- a/internal/postgres/details_test.go
+++ b/internal/postgres/details_test.go
@@ -180,6 +180,11 @@ func TestPostgres_GetModuleInfo(t *testing.T) {
},
}
+ latestGoodVersions := map[string]string{
+ "mod.1": "v1.1.0",
+ "mod.2": "v1.1.0",
+ }
+
for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
for _, v := range test.modules {
@@ -200,7 +205,11 @@ func TestPostgres_GetModuleInfo(t *testing.T) {
t.Fatal("wantIndex too large")
}
wantVI := &test.modules[test.wantIndex].ModuleInfo
- if diff := cmp.Diff(wantVI, gotVI, cmpopts.EquateEmpty(), cmp.AllowUnexported(source.Info{})); diff != "" {
+ wantVI.LatestVersion = latestGoodVersions[wantVI.ModulePath]
+ if diff := cmp.Diff(wantVI, gotVI,
+ cmpopts.EquateEmpty(),
+ cmp.AllowUnexported(source.Info{}),
+ ); diff != "" {
t.Errorf("mismatch (-want +got):\n%s", diff)
}
})
diff --git a/internal/postgres/insert_module_test.go b/internal/postgres/insert_module_test.go
index 37dd8b7a..3ae278a7 100644
--- a/internal/postgres/insert_module_test.go
+++ b/internal/postgres/insert_module_test.go
@@ -108,7 +108,9 @@ func checkModule(ctx context.Context, t *testing.T, db *DB, want *internal.Modul
if err != nil {
t.Fatal(err)
}
- if diff := cmp.Diff(want.ModuleInfo, *got, cmp.AllowUnexported(source.Info{})); diff != "" {
+ if diff := cmp.Diff(want.ModuleInfo, *got,
+ cmp.AllowUnexported(source.Info{}),
+ ); diff != "" {
t.Fatalf("testDB.GetModuleInfo(%q, %q) mismatch (-want +got):\n%s", want.ModulePath, want.Version, diff)
}
diff --git a/internal/postgres/unit_test.go b/internal/postgres/unit_test.go
index a35d5658..2decf185 100644
--- a/internal/postgres/unit_test.go
+++ b/internal/postgres/unit_test.go
@@ -92,6 +92,7 @@ func testGetUnitMeta(t *testing.T, ctx context.Context) {
ModulePath: modPath,
Version: version,
IsRedistributable: true,
+ LatestVersion: "v1.1.0",
},
Name: name,
}
@@ -192,6 +193,19 @@ func testGetUnitMeta(t *testing.T, ctx context.Context) {
test.want.Name,
true,
)
+ latestGood := map[string]string{
+ "m.com": "v1.1.0",
+ "m.com/a": "v1.1.0",
+ "m.com/b": "v2.0.0+incompatible",
+ "cloud.google.com/go": "v0.74.0",
+ "cloud.google.com/go/pubsublite": "v0.4.0",
+ "cloud.google.com/go/compute/metadata": "v0.0.0-20181115181204-d50f0e9b2506",
+ }
+ want.LatestVersion = latestGood[want.ModulePath]
+ if want.LatestVersion == "" {
+ // Fallback to version if not in map (e.g. stdlib)
+ want.LatestVersion = want.Version
+ }
want.IsRedistributable = true
want.CommitTime = sample.CommitTime
want.Retracted = test.want.Retracted
@@ -819,6 +833,7 @@ func unitNoLicenses(fullPath, modulePath, version, name string, readme *internal
ModulePath: modulePath,
Version: version,
IsRedistributable: true,
+ LatestVersion: version,
},
Path: fullPath,
Name: name,
diff --git a/internal/postgres/version_test.go b/internal/postgres/version_test.go
index 66c0453e..3f4eaebc 100644
--- a/internal/postgres/version_test.go
+++ b/internal/postgres/version_test.go
@@ -229,6 +229,18 @@ func TestGetVersions(t *testing.T) {
},
}
+ latestVersions := map[string]string{
+ stdlib.ModulePath: "v1.14.6", // v1.15.0-beta.1 is pre-release
+ taggedModuleV3: "v3.1.0", // v3.2.0-beta is pre-release
+ taggedModuleV2: "v2.0.1",
+ taggedAndPseudoModule: "v1.5.2", // v1.5.3-pre1 is pre-release
+ pseudoModule: "v0.0.0-20200101120012-000000000000",
+ otherModule: "v3.0.0",
+ incompatibleModule: "v0.0.0", // v2.0.0+incompatible is incompatible
+ rootModule: "v0.11.6",
+ nestedModule: "v1.0.4",
+ }
+
for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
for _, w := range test.want {
@@ -237,13 +249,16 @@ func TestGetVersions(t *testing.T) {
w.IsRedistributable = mod.IsRedistributable
w.HasGoMod = mod.HasGoMod
w.SourceInfo = mod.SourceInfo
+ w.LatestVersion = latestVersions[w.ModulePath]
}
got, err := testDB.GetVersionsForPath(ctx, test.path)
if err != nil {
t.Fatal(err)
}
- if diff := cmp.Diff(test.want, got, cmp.AllowUnexported(source.Info{})); diff != "" {
+ if diff := cmp.Diff(test.want, got,
+ cmp.AllowUnexported(source.Info{}),
+ ); diff != "" {
t.Errorf("testDB.GetVersionsForPath(%q) mismatch (-want +got):\n%s", test.path, diff)
}
})