зеркало из https://github.com/golang/pkgsite.git
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>
This commit is contained in:
Родитель
c3aa9cbca1
Коммит
77f3533e99
|
@ -344,7 +344,7 @@ func insertTestModules(ctx context.Context, t *testing.T, mods []testModule) {
|
|||
u.Readme = nil
|
||||
}
|
||||
}
|
||||
postgres.MustInsertModule(ctx, t, testDB, m)
|
||||
postgres.MustInsertModuleLatest(ctx, t, testDB, m)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -203,6 +203,13 @@ func MustInsertModule(ctx context.Context, t *testing.T, db *DB, m *internal.Mod
|
|||
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 MustInsertModuleLMV(ctx context.Context, t *testing.T, db *DB, m *internal.
|
|||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
|
|
|
@ -415,21 +415,6 @@ func TestRawIsMoreRecent(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
Загрузка…
Ссылка в новой задаче