diff options
| author | Ethan Lee <ethanalee@google.com> | 2026-03-18 20:31:16 +0000 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2026-03-25 08:29:54 -0700 |
| commit | c57126f9757fb25c781a59cb9ecc97b0af63727a (patch) | |
| tree | 48b516ffb19fc89d36ed25094c3a8f74a11b754a /internal/api | |
| parent | 86d1c7b3f2f2d36dbaf488d847c09e1655356ca7 (diff) | |
| download | go-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/api')
| -rw-r--r-- | internal/api/api.go | 1 | ||||
| -rw-r--r-- | internal/api/api_test.go | 68 |
2 files changed, 60 insertions, 9 deletions
diff --git a/internal/api/api.go b/internal/api/api.go index d1419c40..4f4fcf7b 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -198,6 +198,7 @@ func ServePackage(w http.ResponseWriter, r *http.Request, ds internal.DataSource 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/api/api_test.go b/internal/api/api_test.go index 16a92278..595a3d25 100644 --- a/internal/api/api_test.go +++ b/internal/api/api_test.go @@ -30,12 +30,20 @@ func TestServePackage(t *testing.T) { ) ds.MustInsertModule(ctx, &internal.Module{ - ModuleInfo: internal.ModuleInfo{ModulePath: "example.com", Version: version}, + ModuleInfo: internal.ModuleInfo{ + ModulePath: "example.com", + Version: version, + LatestVersion: "v1.2.4", + }, Units: []*internal.Unit{{ UnitMeta: internal.UnitMeta{ - Path: "example.com/pkg", - ModuleInfo: internal.ModuleInfo{ModulePath: "example.com", Version: version}, - Name: "pkg", + Path: "example.com/pkg", + ModuleInfo: internal.ModuleInfo{ + ModulePath: "example.com", + Version: version, + LatestVersion: "v1.2.4", + }, + Name: "pkg", }, Documentation: []*internal.Documentation{sample.Documentation("linux", "amd64", sample.DocContents)}, }}, @@ -46,8 +54,9 @@ func TestServePackage(t *testing.T) { UnitMeta: internal.UnitMeta{ Path: pkgPath, ModuleInfo: internal.ModuleInfo{ - ModulePath: mp, - Version: version, + ModulePath: mp, + Version: version, + LatestVersion: version, }, Name: "b", }, @@ -61,13 +70,38 @@ func TestServePackage(t *testing.T) { } ds.MustInsertModule(ctx, &internal.Module{ ModuleInfo: internal.ModuleInfo{ - ModulePath: mp, - Version: version, + ModulePath: mp, + Version: version, + LatestVersion: version, }, Units: []*internal.Unit{u}, }) } + ds.MustInsertModule(ctx, &internal.Module{ + ModuleInfo: internal.ModuleInfo{ + ModulePath: "example.com", + Version: "v1.2.4", + LatestVersion: "v1.2.4", + }, + Units: []*internal.Unit{{ + UnitMeta: internal.UnitMeta{ + Path: "example.com/pkg", + ModuleInfo: internal.ModuleInfo{ + ModulePath: "example.com", + Version: "v1.2.4", + LatestVersion: "v1.2.4", + }, + Name: "pkg", + }, + Documentation: []*internal.Documentation{{ + GOOS: "linux", + GOARCH: "amd64", + Synopsis: "Basic synopsis", + }}, + }}, + }) + for _, test := range []struct { name string url string @@ -83,6 +117,7 @@ func TestServePackage(t *testing.T) { ModulePath: "example.com", ModuleVersion: version, Synopsis: "This is a package synopsis for GOOS=linux, GOARCH=amd64", + IsLatest: false, GOOS: "linux", GOARCH: "amd64", }, @@ -109,6 +144,7 @@ func TestServePackage(t *testing.T) { ModulePath: modulePath1, ModuleVersion: version, Synopsis: "Synopsis for " + modulePath1, + IsLatest: true, GOOS: "linux", GOARCH: "amd64", }, @@ -122,6 +158,21 @@ func TestServePackage(t *testing.T) { ModulePath: "example.com", ModuleVersion: version, Synopsis: "This is a package synopsis for GOOS=linux, GOARCH=amd64", + IsLatest: false, + GOOS: "linux", + GOARCH: "amd64", + }, + }, + { + name: "latest version", + url: "/v1/package/example.com/pkg?version=v1.2.4", + wantStatus: http.StatusOK, + want: &Package{ + Path: "example.com/pkg", + ModulePath: "example.com", + ModuleVersion: "v1.2.4", + Synopsis: "Basic synopsis", + IsLatest: true, GOOS: "linux", GOARCH: "amd64", }, @@ -161,7 +212,6 @@ func TestServePackage(t *testing.T) { if err := json.Unmarshal(w.Body.Bytes(), &got); err != nil { t.Fatalf("json.Unmarshal Package: %v", err) } - got.IsLatest = false if diff := cmp.Diff(want, &got); diff != "" { t.Errorf("mismatch (-want +got):\n%s", diff) } |
