aboutsummaryrefslogtreecommitdiff
path: root/internal/postgres
diff options
context:
space:
mode:
authorJonathan Amsterdam <jba@google.com>2021-04-07 14:54:25 -0400
committerJonathan Amsterdam <jba@google.com>2021-04-08 16:28:39 +0000
commitd5da038b60d9e6ee245c4cd69adad526aeb7d9b3 (patch)
tree2d2dc420caf6372227bac8d9346687b582b1eb6b /internal/postgres
parent3abcfcf90868a5d6d2ca737f590fae6a0d4e2a83 (diff)
downloadgo-x-pkgsite-d5da038b60d9e6ee245c4cd69adad526aeb7d9b3.tar.xz
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>
Diffstat (limited to 'internal/postgres')
-rw-r--r--internal/postgres/test_helper.go6
-rw-r--r--internal/postgres/unit.go4
-rw-r--r--internal/postgres/unit_test.go43
-rw-r--r--internal/postgres/version_test.go14
4 files changed, 38 insertions, 29 deletions
diff --git a/internal/postgres/test_helper.go b/internal/postgres/test_helper.go
index a10dcbd3..50fb7e59 100644
--- a/internal/postgres/test_helper.go
+++ b/internal/postgres/test_helper.go
@@ -206,7 +206,11 @@ func MustInsertModule(ctx context.Context, t *testing.T, db *DB, m *internal.Mod
// 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 5d48ebef..ef41601e 100644
--- a/internal/postgres/unit.go
+++ b/internal/postgres/unit.go
@@ -154,6 +154,7 @@ func (db *DB) getLatestUnitVersion(ctx context.Context, fullPath, requestedModul
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 @@ func (db *DB) getLatestUnitVersion(ctx context.Context, fullPath, requestedModul
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 @@ func (db *DB) getLatestUnitVersion(ctx context.Context, fullPath, requestedModul
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 @@ func (db *DB) getLatestUnitVersion(ctx context.Context, fullPath, requestedModul
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 0e0e4374..fa3d270b 100644
--- a/internal/postgres/unit_test.go
+++ b/internal/postgres/unit_test.go
@@ -43,21 +43,22 @@ func testGetUnitMeta(t *testing.T, ctx context.Context) {
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 @@ func testGetUnitMeta(t *testing.T, ctx context.Context) {
}
}
- 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 @@ func TestGetUnitMetaDiffs(t *testing.T) {
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 325678ac..e4c2702e 100644
--- a/internal/postgres/version_test.go
+++ b/internal/postgres/version_test.go
@@ -63,13 +63,15 @@ func TestGetVersions(t *testing.T) {
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{
{