internal/frontend: add latest-version info to ServerTest modules
In a later CL, the latest-major-version banner will need to use the
latest_module_versions table. So add latest-version information to the
modules inserted as part of the server test.
Change-Id: I1ebbcd40c109c2bcd86b37e6c92871c4f627be31
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/308029
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Julie Qiu <julie@golang.org>
diff --git a/internal/frontend/server_test.go b/internal/frontend/server_test.go
index 38c47a5..646da3e 100644
--- a/internal/frontend/server_test.go
+++ b/internal/frontend/server_test.go
@@ -344,7 +344,7 @@
u.Readme = nil
}
}
- postgres.MustInsertModule(ctx, t, testDB, m)
+ postgres.MustInsertModuleLatest(ctx, t, testDB, m)
}
}
}
diff --git a/internal/postgres/test_helper.go b/internal/postgres/test_helper.go
index dae32ee..a47b788 100644
--- a/internal/postgres/test_helper.go
+++ b/internal/postgres/test_helper.go
@@ -203,6 +203,13 @@
MustInsertModuleLMV(ctx, t, db, m, nil)
}
+// MustInsertModule inserts m into db, calling t.Fatal on error.
+// It also updates the latest-version information for m.
+func MustInsertModuleLatest(ctx context.Context, t *testing.T, db *DB, m *internal.Module) {
+ lmv := addLatest(ctx, t, db, m.ModulePath, m.Version, "")
+ MustInsertModuleLMV(ctx, t, db, m, lmv)
+}
+
func MustInsertModuleLMV(ctx context.Context, t *testing.T, db *DB, m *internal.Module, lmv *internal.LatestModuleVersions) {
t.Helper()
if _, err := db.InsertModule(ctx, m, lmv); err != nil {
@@ -210,6 +217,21 @@
}
}
+func addLatest(ctx context.Context, t *testing.T, db *DB, modulePath, version, modFile string) *internal.LatestModuleVersions {
+ if modFile == "" {
+ modFile = "module " + modulePath
+ }
+ info, err := internal.NewLatestModuleVersions(modulePath, version, version, "", []byte(modFile))
+ if err != nil {
+ t.Fatal(err)
+ }
+ lmv, err := db.UpdateLatestModuleVersions(ctx, info)
+ if err != nil {
+ t.Fatal(err)
+ }
+ return lmv
+}
+
// InsertSampleDirectory tree inserts a set of packages for testing
// GetUnit and frontend.FetchDirectoryDetails.
func InsertSampleDirectoryTree(ctx context.Context, t *testing.T, testDB *DB) {
diff --git a/internal/postgres/version_test.go b/internal/postgres/version_test.go
index fbf4ea4..4493447 100644
--- a/internal/postgres/version_test.go
+++ b/internal/postgres/version_test.go
@@ -415,21 +415,6 @@
}
}
-func addLatest(ctx context.Context, t *testing.T, db *DB, modulePath, version, modFile string) *internal.LatestModuleVersions {
- if modFile == "" {
- modFile = "module " + modulePath
- }
- info, err := internal.NewLatestModuleVersions(modulePath, version, version, "", []byte(modFile))
- if err != nil {
- t.Fatal(err)
- }
- lmv, err := db.UpdateLatestModuleVersions(ctx, info)
- if err != nil {
- t.Fatal(err)
- }
- return lmv
-}
-
func TestGetLatestGoodVersion(t *testing.T) {
t.Parallel()
testDB, release := acquire(t)