diff --git a/internal/api/api.go b/internal/api/api.go
index d27e49b..289c06e 100644
--- a/internal/api/api.go
+++ b/internal/api/api.go
@@ -148,6 +148,7 @@
ModuleVersion: unit.Version,
Synopsis: synopsis,
IsStandardLibrary: stdlib.Contains(unit.ModulePath),
+ IsLatest: unit.Version == unit.LatestVersion,
GOOS: goos,
GOARCH: goarch,
Docs: docs,
diff --git a/internal/discovery.go b/internal/discovery.go
index 16e17d0..88b48c3 100644
--- a/internal/discovery.go
+++ b/internal/discovery.go
@@ -52,6 +52,8 @@
HasGoMod bool
SourceInfo *source.Info
+ // LatestVersion is the latest good version of the module.
+ LatestVersion string
// Deprecated describes whether the module is deprecated.
Deprecated bool
// DeprecationComment is the comment describing the deprecation, if any.
diff --git a/internal/fetchdatasource/fetchdatasource_test.go b/internal/fetchdatasource/fetchdatasource_test.go
index 05cb121..41260db 100644
--- a/internal/fetchdatasource/fetchdatasource_test.go
+++ b/internal/fetchdatasource/fetchdatasource_test.go
@@ -202,7 +202,7 @@
t.Fatal(err)
}
test.want.Path = test.path
- if diff := cmp.Diff(test.want, got, cmpopts.IgnoreFields(internal.ModuleInfo{}, "SourceInfo")); diff != "" {
+ if diff := cmp.Diff(test.want, got, cmpopts.IgnoreFields(internal.ModuleInfo{}, "SourceInfo", "LatestVersion")); diff != "" {
t.Errorf("mismatch (-want +got):\n%s", diff)
}
})
diff --git a/internal/latest.go b/internal/latest.go
index 14ccf16..8b820b2 100644
--- a/internal/latest.go
+++ b/internal/latest.go
@@ -64,6 +64,7 @@
// PopulateModuleInfo uses the LatestModuleVersions to populate fields of the given module.
func (li *LatestModuleVersions) PopulateModuleInfo(mi *ModuleInfo) {
+ mi.LatestVersion = li.GoodVersion
mi.Deprecated = li.Deprecated
mi.DeprecationComment = li.deprecationComment
mi.Retracted, mi.RetractionRationale = isRetracted(li.GoModFile, mi.Version)
diff --git a/internal/postgres/details_test.go b/internal/postgres/details_test.go
index 53f55dd..453ef75 100644
--- a/internal/postgres/details_test.go
+++ b/internal/postgres/details_test.go
@@ -200,7 +200,11 @@
t.Fatal("wantIndex too large")
}
wantVI := &test.modules[test.wantIndex].ModuleInfo
- if diff := cmp.Diff(wantVI, gotVI, cmpopts.EquateEmpty(), cmp.AllowUnexported(source.Info{})); diff != "" {
+ if diff := cmp.Diff(wantVI, gotVI,
+ cmpopts.EquateEmpty(),
+ cmpopts.IgnoreFields(internal.ModuleInfo{}, "LatestVersion"),
+ 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 37dd8b7..7393cb0 100644
--- a/internal/postgres/insert_module_test.go
+++ b/internal/postgres/insert_module_test.go
@@ -108,7 +108,10 @@
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{}),
+ cmpopts.IgnoreFields(internal.ModuleInfo{}, "LatestVersion"),
+ ); 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 e8dc304..f00f7d1 100644
--- a/internal/postgres/unit_test.go
+++ b/internal/postgres/unit_test.go
@@ -78,7 +78,8 @@
opts := []cmp.Option{
cmpopts.EquateEmpty(),
cmpopts.IgnoreFields(licenses.Metadata{}, "Coverage"),
- cmpopts.IgnoreFields(internal.UnitMeta{}, "HasGoMod"),
+ cmpopts.IgnoreFields(internal.UnitMeta{}, "HasGoMod", "LatestVersion"),
+ cmpopts.IgnoreFields(internal.ModuleInfo{}, "LatestVersion"),
cmp.AllowUnexported(source.Info{}, safehtml.HTML{}),
}
if diff := cmp.Diff(test.want, got, opts...); diff != "" {
diff --git a/internal/postgres/version_test.go b/internal/postgres/version_test.go
index 66c0453..926ad18 100644
--- a/internal/postgres/version_test.go
+++ b/internal/postgres/version_test.go
@@ -11,6 +11,7 @@
"testing"
"github.com/google/go-cmp/cmp"
+ "github.com/google/go-cmp/cmp/cmpopts"
"golang.org/x/pkgsite/internal"
"golang.org/x/pkgsite/internal/source"
"golang.org/x/pkgsite/internal/stdlib"
@@ -243,7 +244,10 @@
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,
+ cmpopts.IgnoreFields(internal.ModuleInfo{}, "LatestVersion"),
+ cmp.AllowUnexported(source.Info{}),
+ ); diff != "" {
t.Errorf("testDB.GetVersionsForPath(%q) mismatch (-want +got):\n%s", test.path, diff)
}
})
diff --git a/internal/worker/fetch_test.go b/internal/worker/fetch_test.go
index f26c7ac..c39f50c 100644
--- a/internal/worker/fetch_test.go
+++ b/internal/worker/fetch_test.go
@@ -58,6 +58,7 @@
CommitTime: testProxyCommitTime,
SourceInfo: source.NewGitHubInfo("https://example.com/multi", "", sample.VersionString),
IsRedistributable: true,
+ LatestVersion: sample.VersionString,
},
Path: "example.com/multi/bar",
Name: "bar",
@@ -114,6 +115,7 @@
CommitTime: testProxyCommitTime,
SourceInfo: source.NewGitHubInfo("https://example.com/nonredist", "", sample.VersionString),
IsRedistributable: true,
+ LatestVersion: sample.VersionString,
},
Path: "example.com/nonredist/bar/baz",
Name: "baz",
@@ -144,6 +146,7 @@
CommitTime: testProxyCommitTime,
SourceInfo: source.NewGitHubInfo("https://example.com/nonredist", "", sample.VersionString),
IsRedistributable: true,
+ LatestVersion: sample.VersionString,
},
Path: "example.com/nonredist/unk",
Name: "unk",
@@ -168,6 +171,7 @@
CommitTime: testProxyCommitTime,
SourceInfo: source.NewGitHubInfo("https://"+buildConstraintsModulePath, "", sample.VersionString),
IsRedistributable: true,
+ LatestVersion: "v1.0.0",
},
Path: buildConstraintsModulePath + "/cpu",
Name: "cpu",
@@ -209,7 +213,11 @@
if err != nil {
t.Fatal(err)
}
- if diff := cmp.Diff(test.want.UnitMeta, *got, cmpopts.EquateEmpty(), cmp.AllowUnexported(source.Info{})); diff != "" {
+ if diff := cmp.Diff(test.want.UnitMeta, *got,
+ cmpopts.EquateEmpty(),
+ cmp.AllowUnexported(source.Info{}),
+ cmpopts.IgnoreFields(internal.ModuleInfo{}, "LatestVersion"),
+ ); diff != "" {
t.Fatalf("testDB.GetUnitMeta(ctx, %q, %q) mismatch (-want +got):\n%s", test.modulePath, test.version, diff)
}
@@ -223,10 +231,10 @@
if diff := cmp.Diff(test.want, gotPkg,
cmpopts.EquateEmpty(),
cmp.AllowUnexported(source.Info{}),
- cmpopts.IgnoreFields(internal.Unit{}, "Documentation", "BuildContexts"),
- cmpopts.IgnoreFields(internal.Unit{}, "SymbolHistory"),
- cmpopts.IgnoreFields(internal.Unit{}, "Subdirectories")); diff != "" {
- t.Errorf("mismatch on readme (-want +got):\n%s", diff)
+ cmpopts.IgnoreFields(internal.Unit{}, "Documentation", "BuildContexts", "SymbolHistory", "Subdirectories"),
+ cmpopts.IgnoreFields(internal.ModuleInfo{}, "LatestVersion"),
+ ); diff != "" {
+ t.Errorf("mismatch on unit (-want +got):\n%s", diff)
}
if got, want := gotPkg.Documentation, test.want.Documentation; got == nil || want == nil {
if !cmp.Equal(got, want) {
diff --git a/internal/worker/refetch_test.go b/internal/worker/refetch_test.go
index 35f66a4..fad2ce5 100644
--- a/internal/worker/refetch_test.go
+++ b/internal/worker/refetch_test.go
@@ -92,6 +92,7 @@
CommitTime: time.Date(2019, 1, 30, 0, 0, 0, 0, time.UTC),
IsRedistributable: true,
SourceInfo: source.NewGitHubInfo("https://"+sample.ModulePath, "", sample.VersionString),
+ LatestVersion: version,
},
Path: sample.ModulePath + "/bar",
Name: "bar",
@@ -127,7 +128,8 @@
if diff := cmp.Diff(want.UnitMeta, *got,
cmp.AllowUnexported(source.Info{}),
cmpopts.IgnoreFields(licenses.Metadata{}, "Coverage"),
- cmpopts.IgnoreFields(internal.UnitMeta{}, "HasGoMod")); diff != "" {
+ cmpopts.IgnoreFields(internal.UnitMeta{}, "HasGoMod"),
+ cmpopts.IgnoreFields(internal.ModuleInfo{}, "LatestVersion")); diff != "" {
t.Fatalf("testDB.GetUnitMeta(ctx, %q, %q) mismatch (-want +got):\n%s", want.ModulePath, want.Version, diff)
}
@@ -139,7 +141,8 @@
cmp.AllowUnexported(source.Info{}),
cmpopts.IgnoreFields(internal.Unit{}, "Documentation", "BuildContexts"),
cmpopts.IgnoreFields(licenses.Metadata{}, "Coverage"),
- cmpopts.IgnoreFields(internal.UnitMeta{}, "HasGoMod")); diff != "" {
+ cmpopts.IgnoreFields(internal.UnitMeta{}, "HasGoMod"),
+ cmpopts.IgnoreFields(internal.ModuleInfo{}, "LatestVersion")); diff != "" {
t.Errorf("mismatch on readme (-want +got):\n%s", diff)
}
if got, want := gotPkg.Documentation, want.Documentation; got == nil || want == nil {