internal/postgres: remove MustInsertModule from remaining tests
Change-Id: Ife8d5918c63cfc509696aaa273186752fac0652e
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/308269
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
diff --git a/internal/postgres/test_helper.go b/internal/postgres/test_helper.go
index a10dcbd..50fb7e5 100644
--- a/internal/postgres/test_helper.go
+++ b/internal/postgres/test_helper.go
@@ -206,7 +206,11 @@
// 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, "")
+ MustInsertModuleGoMod(ctx, t, db, m, "module "+m.ModulePath)
+}
+
+func MustInsertModuleGoMod(ctx context.Context, t *testing.T, db *DB, m *internal.Module, goMod string) {
+ lmv := addLatest(ctx, t, db, m.ModulePath, m.Version, goMod)
MustInsertModuleLMV(ctx, t, db, m, lmv)
}
diff --git a/internal/postgres/unit.go b/internal/postgres/unit.go
index 5d48ebe..ef41601 100644
--- a/internal/postgres/unit.go
+++ b/internal/postgres/unit.go
@@ -154,6 +154,7 @@
if requestedModulePath == internal.UnknownModulePath {
modPaths = internal.CandidateModulePaths(fullPath)
}
+ fmt.Printf("#### candidate paths: %v\n", modPaths)
// Get latest-version information for all possible modules, from longest
// to shortest path.
lmvs, err := db.getMultiLatestModuleVersions(ctx, modPaths)
@@ -161,6 +162,7 @@
return "", "", nil, err
}
for _, lmv = range lmvs {
+ fmt.Printf("#### lmv: %+v\n", lmv)
// Collect all the versions of this module that contain fullPath.
query := squirrel.Select("m.version").
From("modules m").
@@ -176,6 +178,7 @@
if err != nil {
return "", "", nil, err
}
+ fmt.Printf("#### allVersions = %v\n", allVersions)
// Remove retracted versions.
unretractedVersions := version.RemoveIf(allVersions, lmv.IsRetracted)
// If there are no unretracted versions, move on. If we fall out of the
@@ -192,6 +195,7 @@
unretractedVersions = version.RemoveIf(unretractedVersions, version.IsIncompatible)
}
latestVersion = version.LatestOf(unretractedVersions)
+ fmt.Printf("################ got latestVersion %q\n", latestVersion)
break
}
if latestVersion != "" {
diff --git a/internal/postgres/unit_test.go b/internal/postgres/unit_test.go
index 0e0e437..fa3d270 100644
--- a/internal/postgres/unit_test.go
+++ b/internal/postgres/unit_test.go
@@ -43,21 +43,22 @@
for _, testModule := range []struct {
module, version, packageSuffix string
isMaster bool
+ goMod string
}{
- {"m.com", "v1.0.0", "a", false},
- {"m.com", "v1.0.1", "dir/a", false},
- {"m.com", "v1.1.0", "a/b", false},
- {"m.com", "v1.2.0-pre", "a", true},
- {"m.com", "v2.0.0+incompatible", "a", false},
- {"m.com/a", "v1.1.0", "b", false},
- {"m.com/b", "v2.0.0+incompatible", "a", true},
- {"cloud.google.com/go", "v0.69.0", "pubsublite", false},
- {"cloud.google.com/go/pubsublite", "v0.4.0", "", false},
- {"cloud.google.com/go", "v0.74.0", "compute/metadata", false},
- {"cloud.google.com/go/compute/metadata", "v0.0.0-20181115181204-d50f0e9b2506", "", false},
+ {"m.com", "v1.0.0", "a", false, ""},
+ {"m.com", "v1.0.1", "dir/a", false, ""},
+ {"m.com", "v2.0.0+incompatible", "a", false, ""},
+ {"m.com", "v1.1.0", "a/b", false, "module m.com\nretract v1.0.1 // bad"},
+ {"m.com", "v1.2.0-pre", "a", true, ""},
+ {"m.com/a", "v1.1.0", "b", false, ""},
+ {"m.com/b", "v2.0.0+incompatible", "a", true, ""},
+ {"cloud.google.com/go", "v0.69.0", "pubsublite", false, ""},
+ {"cloud.google.com/go/pubsublite", "v0.4.0", "", false, ""},
+ {"cloud.google.com/go", "v0.74.0", "compute/metadata", false, ""},
+ {"cloud.google.com/go/compute/metadata", "v0.0.0-20181115181204-d50f0e9b2506", "", false, ""},
} {
m := sample.Module(testModule.module, testModule.version, testModule.packageSuffix)
- MustInsertModule(ctx, t, testDB, m)
+ MustInsertModuleGoMod(ctx, t, testDB, m, testModule.goMod)
requested := m.Version
if testModule.isMaster {
requested = "master"
@@ -71,11 +72,6 @@
}
}
- addLatest(ctx, t, testDB, "m.com", "v1.1.0", "module m.com\nretract v1.0.1 // bad")
- addLatest(ctx, t, testDB, "m.com/a", "v1.1.0", "module m.com/a")
- addLatest(ctx, t, testDB, "cloud.google.com/go/pubsublite", "v0.0.0", "module cloud.google.com/go/pubsublite")
- addLatest(ctx, t, testDB, "cloud.google.com/go", "v0.74.0", "module cloud.google.com/go")
-
type teststruct struct {
name string
path, module, version string
@@ -283,11 +279,14 @@
for _, p := range test.packages {
mod, ver, pkg := parseModuleVersionPackage(p)
m := sample.Module(mod, ver, pkg)
- MustInsertModule(ctx, t, testDB, m)
- }
- for _, l := range test.latests {
- modFile := fmt.Sprintf("module %s\n%s", l.module, l.goMod)
- addLatest(ctx, t, testDB, l.module, l.version, modFile)
+ goMod := "module " + mod
+ for _, l := range test.latests {
+ if l.module == mod && l.version == ver {
+ goMod += "\n" + l.goMod
+ break
+ }
+ }
+ MustInsertModuleGoMod(ctx, t, testDB, m, goMod)
}
gotLegacy, err := testDB.GetUnitMeta(ctx, test.path, internal.UnknownModulePath, internal.LatestVersion)
if err != nil {
diff --git a/internal/postgres/version_test.go b/internal/postgres/version_test.go
index 325678a..e4c2702 100644
--- a/internal/postgres/version_test.go
+++ b/internal/postgres/version_test.go
@@ -63,13 +63,15 @@
defer cancel()
for _, m := range testModules {
- MustInsertModule(ctx, t, testDB, m)
+ goMod := "module " + m.ModulePath
+ if m.ModulePath == rootModule {
+ goMod = `
+ module golang.org/foo/bar // Deprecated: use other
+ retract v1.0.3 // security flaw
+ `
+ }
+ MustInsertModuleGoMod(ctx, t, testDB, m, goMod)
}
- // Add latest version info for rootModule.
- addLatest(ctx, t, testDB, rootModule, "v1.1.0", `
- module golang.org/foo/bar // Deprecated: use other
- retract v1.0.3 // security flaw
- `)
stdModuleVersions := []*internal.ModuleInfo{
{