diff --git a/internal/frontend/404_test.go b/internal/frontend/404_test.go index 37db6a2e..6876052a 100644 --- a/internal/frontend/404_test.go +++ b/internal/frontend/404_test.go @@ -160,7 +160,7 @@ func TestPreviousFetchStatusAndResponse_PathExistsAtNonV1(t *testing.T) { ctx := context.Background() defer postgres.ResetTestDB(testDB, t) - postgres.MustInsertModuleLatest(ctx, t, testDB, sample.Module(sample.ModulePath+"/v4", "v4.0.0", "foo")) + postgres.MustInsertModule(ctx, t, testDB, sample.Module(sample.ModulePath+"/v4", "v4.0.0", "foo")) for _, mod := range []struct { path, version string diff --git a/internal/frontend/directory_test.go b/internal/frontend/directory_test.go index 0d713e51..632511ae 100644 --- a/internal/frontend/directory_test.go +++ b/internal/frontend/directory_test.go @@ -30,7 +30,7 @@ func TestGetNestedModules(t *testing.T) { sample.Module("cloud.google.com/go/storage/v9/module", "v9.0.0", sample.Suffix), sample.Module("cloud.google.com/go/v2", "v2.0.0", "storage", "spanner", "pubsub"), } { - postgres.MustInsertModuleLatest(ctx, t, testDB, m) + postgres.MustInsertModule(ctx, t, testDB, m) } for _, test := range []struct { diff --git a/internal/frontend/fetch_test.go b/internal/frontend/fetch_test.go index 9714e689..40237535 100644 --- a/internal/frontend/fetch_test.go +++ b/internal/frontend/fetch_test.go @@ -170,7 +170,7 @@ func TestFetchPathAlreadyExists(t *testing.T) { t.Run(strconv.Itoa(test.status), func(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testFetchTimeout) defer cancel() - postgres.MustInsertModuleLatest(ctx, t, testDB, sample.DefaultModule()) + postgres.MustInsertModule(ctx, t, testDB, sample.DefaultModule()) if err := testDB.UpsertVersionMap(ctx, &internal.VersionMap{ ModulePath: sample.ModulePath, RequestedVersion: sample.VersionString, diff --git a/internal/frontend/imports_test.go b/internal/frontend/imports_test.go index 8f6d0e95..bc300119 100644 --- a/internal/frontend/imports_test.go +++ b/internal/frontend/imports_test.go @@ -54,7 +54,7 @@ func TestFetchImportsDetails(t *testing.T) { pkg := module.Units[1] pkg.Imports = test.imports - postgres.MustInsertModuleLatest(ctx, t, testDB, module) + postgres.MustInsertModule(ctx, t, testDB, module) got, err := fetchImportsDetails(ctx, testDB, pkg.Path, pkg.ModulePath, pkg.Version) if err != nil { @@ -98,7 +98,7 @@ func TestFetchImportedByDetails(t *testing.T) { } for _, m := range testModules { - postgres.MustInsertModuleLatest(ctx, t, testDB, m) + postgres.MustInsertModule(ctx, t, testDB, m) } tests := []struct { @@ -152,11 +152,11 @@ func TestFetchImportedByDetails_ExceedsLimit(t *testing.T) { defer func() { importedByLimit = old }() m := sample.Module("m.com/a", sample.VersionString, "foo") - postgres.MustInsertModuleLatest(ctx, t, testDB, m) + postgres.MustInsertModule(ctx, t, testDB, m) for _, mod := range []string{"m1.com/a", "m2.com/a", "m3.com/a"} { m2 := sample.Module(mod, sample.VersionString, "p") m2.Packages()[0].Imports = []string{"m.com/a/foo"} - postgres.MustInsertModuleLatest(ctx, t, testDB, m2) + postgres.MustInsertModule(ctx, t, testDB, m2) } wantDetails := &ImportedByDetails{ ModulePath: "m.com/a", diff --git a/internal/frontend/license_test.go b/internal/frontend/license_test.go index e7b7699b..af091407 100644 --- a/internal/frontend/license_test.go +++ b/internal/frontend/license_test.go @@ -80,9 +80,9 @@ func TestFetchLicensesDetails(t *testing.T) { defer postgres.ResetTestDB(testDB, t) ctx := context.Background() - postgres.MustInsertModuleLatest(ctx, t, testDB, testModule) - postgres.MustInsertModuleLatest(ctx, t, testDB, stdlibModule) - postgres.MustInsertModuleLatest(ctx, t, testDB, crlfModule) + postgres.MustInsertModule(ctx, t, testDB, testModule) + postgres.MustInsertModule(ctx, t, testDB, stdlibModule) + postgres.MustInsertModule(ctx, t, testDB, crlfModule) for _, test := range []struct { err error name, fullPath, modulePath, version string diff --git a/internal/frontend/main_test.go b/internal/frontend/main_test.go index 69eea7d5..092c09ee 100644 --- a/internal/frontend/main_test.go +++ b/internal/frontend/main_test.go @@ -34,7 +34,7 @@ func TestGetImportedByCount(t *testing.T) { mod2 := newModule(p2, []string{p1}, 1) mod3 := newModule(p3, []string{p1, p2}, 0) for _, m := range []*internal.Module{mod1, mod2, mod3} { - postgres.MustInsertModuleLatest(ctx, t, testDB, m) + postgres.MustInsertModule(ctx, t, testDB, m) } for _, test := range []struct { diff --git a/internal/frontend/package_test.go b/internal/frontend/package_test.go index 3a8cc8e4..1b26cfd7 100644 --- a/internal/frontend/package_test.go +++ b/internal/frontend/package_test.go @@ -21,7 +21,7 @@ func TestStdlibPathForShortcut(t *testing.T) { "text/template", "html/template", // two matches for "template" ) ctx := context.Background() - postgres.MustInsertModuleLatest(ctx, t, testDB, m) + postgres.MustInsertModule(ctx, t, testDB, m) for _, test := range []struct { path string diff --git a/internal/frontend/search_test.go b/internal/frontend/search_test.go index 55ddf796..728013bd 100644 --- a/internal/frontend/search_test.go +++ b/internal/frontend/search_test.go @@ -94,7 +94,7 @@ func TestFetchSearchPage(t *testing.T) { } ) for _, m := range []*internal.Module{moduleFoo, moduleBar} { - postgres.MustInsertModuleLatest(ctx, t, testDB, m) + postgres.MustInsertModule(ctx, t, testDB, m) } for _, test := range []struct { @@ -212,7 +212,7 @@ func TestSearchRequestRedirectPath(t *testing.T) { modules := []*internal.Module{golangTools, std} for _, v := range modules { - postgres.MustInsertModuleLatest(ctx, t, testDB, v) + postgres.MustInsertModule(ctx, t, testDB, v) } for _, test := range []struct { name string diff --git a/internal/frontend/server_test.go b/internal/frontend/server_test.go index 2bfe2f61..5d220557 100644 --- a/internal/frontend/server_test.go +++ b/internal/frontend/server_test.go @@ -344,7 +344,7 @@ func insertTestModules(ctx context.Context, t *testing.T, mods []testModule) { u.Readme = nil } } - postgres.MustInsertModuleLatest(ctx, t, testDB, m) + postgres.MustInsertModule(ctx, t, testDB, m) } } } @@ -1248,7 +1248,7 @@ func TestServer404Redirect_NoLoop(t *testing.T) { goModPath := "module.path/alternative/pkg" defer postgres.ResetTestDB(testDB, t) sampleModule := sample.DefaultModule() - postgres.MustInsertModuleLatest(ctx, t, testDB, sampleModule) + postgres.MustInsertModule(ctx, t, testDB, sampleModule) alternativeModule := &internal.VersionMap{ ModulePath: altPath, GoModPath: goModPath, @@ -1305,7 +1305,7 @@ func TestServer404Redirect(t *testing.T) { defer postgres.ResetTestDB(testDB, t) sampleModule := sample.DefaultModule() - postgres.MustInsertModuleLatest(ctx, t, testDB, sampleModule) + postgres.MustInsertModule(ctx, t, testDB, sampleModule) alternativeModule := &internal.VersionMap{ ModulePath: "module.path/alternative", GoModPath: sample.ModulePath, @@ -1319,7 +1319,7 @@ func TestServer404Redirect(t *testing.T) { v1modpath := "notinv1.mod" v1path := "notinv1.mod/foo" - postgres.MustInsertModuleLatest(ctx, t, testDB, sample.Module(v1modpath+"/v4", "v4.0.0", "foo")) + postgres.MustInsertModule(ctx, t, testDB, sample.Module(v1modpath+"/v4", "v4.0.0", "foo")) for _, mod := range []struct { path, version string status int @@ -1591,8 +1591,8 @@ func TestEmptyDirectoryBetweenNestedModulesRedirect(t *testing.T) { defer cancel() defer postgres.ResetTestDB(testDB, t) - postgres.MustInsertModuleLatest(ctx, t, testDB, sample.Module(sample.ModulePath, sample.VersionString, "")) - postgres.MustInsertModuleLatest(ctx, t, testDB, sample.Module(sample.ModulePath+"/missing/dir/c", sample.VersionString, "")) + postgres.MustInsertModule(ctx, t, testDB, sample.Module(sample.ModulePath, sample.VersionString, "")) + postgres.MustInsertModule(ctx, t, testDB, sample.Module(sample.ModulePath+"/missing/dir/c", sample.VersionString, "")) missingPath := sample.ModulePath + "/missing" notInsertedPath := sample.ModulePath + "/missing/dir" diff --git a/internal/frontend/versions_test.go b/internal/frontend/versions_test.go index a3fb6336..258ef3ee 100644 --- a/internal/frontend/versions_test.go +++ b/internal/frontend/versions_test.go @@ -166,7 +166,7 @@ func TestFetchPackageVersionsDetails(t *testing.T) { defer postgres.ResetTestDB(testDB, t) for _, v := range tc.modules { - postgres.MustInsertModuleLatest(ctx, t, testDB, v) + postgres.MustInsertModule(ctx, t, testDB, v) } got, err := fetchVersionsDetails(ctx, testDB, tc.pkg.Path, tc.pkg.ModulePath) diff --git a/internal/postgres/delete_test.go b/internal/postgres/delete_test.go index 71b14d6c..f0e5fc7e 100644 --- a/internal/postgres/delete_test.go +++ b/internal/postgres/delete_test.go @@ -26,7 +26,7 @@ func TestDeletePseudoversionsExcept(t *testing.T) { "v0.0.0-20190904010203-89fb59e2e920", } for _, v := range versions { - MustInsertModuleLatest(ctx, t, testDB, sample.Module(sample.ModulePath, v, "")) + MustInsertModule(ctx, t, testDB, sample.Module(sample.ModulePath, v, "")) } if err := testDB.DeletePseudoversionsExcept(ctx, sample.ModulePath, pseudo1); err != nil { t.Fatal(err) diff --git a/internal/postgres/details_test.go b/internal/postgres/details_test.go index 70752844..3ba376cf 100644 --- a/internal/postgres/details_test.go +++ b/internal/postgres/details_test.go @@ -73,7 +73,7 @@ func TestGetNestedModules(t *testing.T) { defer release() for _, v := range test.modules { - MustInsertModuleLatest(ctx, t, testDB, v) + MustInsertModule(ctx, t, testDB, v) } gotModules, err := testDB.GetNestedModules(ctx, test.path) @@ -120,7 +120,7 @@ func TestGetNestedModules_Excluded(t *testing.T) { }, } for _, m := range test.modules { - MustInsertModuleLatest(ctx, t, testDB, m) + MustInsertModule(ctx, t, testDB, m) } if err := testDB.InsertExcludedPrefix(ctx, "cloud.google.com/go/storage", "postgres", "test"); err != nil { t.Fatal(err) @@ -185,7 +185,7 @@ func TestPostgres_GetModuleInfo(t *testing.T) { for _, test := range testCases { t.Run(test.name, func(t *testing.T) { for _, v := range test.modules { - MustInsertModuleLatest(ctx, t, testDB, v) + MustInsertModule(ctx, t, testDB, v) } gotVI, err := testDB.GetModuleInfo(ctx, test.path, test.version) @@ -270,7 +270,7 @@ func TestGetImportedBy(t *testing.T) { defer release() for _, v := range testModules { - MustInsertModuleLatest(ctx, t, testDB, v) + MustInsertModule(ctx, t, testDB, v) } gotImportedBy, err := testDB.GetImportedBy(ctx, test.path, test.modulePath, 100) diff --git a/internal/postgres/insert_module_test.go b/internal/postgres/insert_module_test.go index ad6b3492..291bb4c3 100644 --- a/internal/postgres/insert_module_test.go +++ b/internal/postgres/insert_module_test.go @@ -80,9 +80,9 @@ func TestInsertModule(t *testing.T) { testDB, release := acquire(t) defer release() - MustInsertModuleLatest(ctx, t, testDB, test.module) + MustInsertModule(ctx, t, testDB, test.module) // Test that insertion of duplicate primary key won't fail. - MustInsertModuleLatest(ctx, t, testDB, test.module) + MustInsertModule(ctx, t, testDB, test.module) checkModule(ctx, t, testDB, test.module) }) } @@ -158,7 +158,7 @@ func TestInsertModuleLicenseCheck(t *testing.T) { mod.IsRedistributable = false mod.Units[0].IsRedistributable = false - MustInsertModuleLatest(ctx, t, db, mod) + MustInsertModule(ctx, t, db, mod) // New model u, err := db.GetUnit(ctx, newUnitMeta(mod.ModulePath, mod.ModulePath, mod.Version), internal.AllFields) @@ -190,7 +190,7 @@ func TestUpsertModule(t *testing.T) { m := sample.Module("upsert.org", "v1.2.3", "dir/p") // Insert the module. - MustInsertModuleLatest(ctx, t, testDB, m) + MustInsertModule(ctx, t, testDB, m) // Change the module, and re-insert. m.IsRedistributable = !m.IsRedistributable lic := *m.Licenses[0] @@ -198,7 +198,7 @@ func TestUpsertModule(t *testing.T) { sample.ReplaceLicense(m, &lic) m.Units[0].Readme.Contents += " and more" - MustInsertModuleLatest(ctx, t, testDB, m) + MustInsertModule(ctx, t, testDB, m) // The changes should have been saved. checkModule(ctx, t, testDB, m) } @@ -303,7 +303,7 @@ func TestInsertModuleNewCoverage(t *testing.T) { Contents: []byte(`Lorem Ipsum`), }, } - MustInsertModuleLatest(ctx, t, testDB, m) + MustInsertModule(ctx, t, testDB, m) u, err := testDB.GetUnit(ctx, newUnitMeta(m.ModulePath, m.ModulePath, m.Version), internal.AllFields) if err != nil { t.Fatal(err) @@ -338,7 +338,7 @@ func TestPostgres_ReadAndWriteModuleOtherColumns(t *testing.T) { seriesPath: "github.com/user/repo/path", } - MustInsertModuleLatest(ctx, t, testDB, v) + MustInsertModule(ctx, t, testDB, v) query := ` SELECT sort_version, series_path @@ -450,7 +450,7 @@ func TestDeleteModule(t *testing.T) { v := sample.DefaultModule() - MustInsertModuleLatest(ctx, t, testDB, v) + MustInsertModule(ctx, t, testDB, v) if _, err := testDB.GetModuleInfo(ctx, v.ModulePath, v.Version); err != nil { t.Fatal(err) } @@ -513,7 +513,7 @@ func TestPostgres_NewerAlternative(t *testing.T) { t.Fatal(err) } m := sample.Module(mvs.ModulePath, okVersion, "p") - MustInsertModuleLatest(ctx, t, testDB, m) + MustInsertModule(ctx, t, testDB, m) if _, _, found := GetFromSearchDocuments(ctx, t, testDB, m.Packages()[0].Path); found { t.Fatal("found package after inserting") } diff --git a/internal/postgres/licenses_test.go b/internal/postgres/licenses_test.go index 380eabfa..9ebcd861 100644 --- a/internal/postgres/licenses_test.go +++ b/internal/postgres/licenses_test.go @@ -44,8 +44,8 @@ func TestGetLicenses(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout*5) defer cancel() - MustInsertModuleLatest(ctx, t, testDB, testModule) - MustInsertModuleLatest(ctx, t, testDB, stdlibModule) + MustInsertModule(ctx, t, testDB, testModule) + MustInsertModule(ctx, t, testDB, stdlibModule) for _, test := range []struct { err error name, fullPath, modulePath, version string @@ -142,7 +142,7 @@ func TestGetModuleLicenses(t *testing.T) { }) } - MustInsertModuleLatest(ctx, t, testDB, testModule) + MustInsertModule(ctx, t, testDB, testModule) var moduleID int query := ` @@ -176,7 +176,7 @@ func TestGetLicensesBypass(t *testing.T) { // Insert with non-redistributable license contents. m := nonRedistributableModule() - MustInsertModuleLatest(ctx, t, bypassDB, m) + MustInsertModule(ctx, t, bypassDB, m) // check reads and the second license in the module and compares it with want. check := func(bypass bool, want *licenses.License) { diff --git a/internal/postgres/path_test.go b/internal/postgres/path_test.go index 72418872..61f0cfd4 100644 --- a/internal/postgres/path_test.go +++ b/internal/postgres/path_test.go @@ -72,7 +72,7 @@ func TestGetLatestMajorPathForV1Path(t *testing.T) { for _, mv := range test.modvers { mod, ver, _ := parseModuleVersionPackage(mv) m := sample.Module(mod, ver, suffix) - MustInsertModuleLatest(ctx, t, testDB, m) + MustInsertModule(ctx, t, testDB, m) } t.Run("module", func(t *testing.T) { check(test.v1ModulePath, test.wantModulePath) diff --git a/internal/postgres/search_test.go b/internal/postgres/search_test.go index 8d635670..7d7b2d7a 100644 --- a/internal/postgres/search_test.go +++ b/internal/postgres/search_test.go @@ -297,7 +297,7 @@ func TestSearch(t *testing.T) { testDB, release := acquire(t) defer release() for _, m := range test.modules { - MustInsertModuleLatest(ctx, t, testDB, m) + MustInsertModule(ctx, t, testDB, m) } if _, err := testDB.UpdateSearchDocumentsImportedByCount(ctx); err != nil { t.Fatal(err) @@ -385,7 +385,7 @@ func TestSearchErrors(t *testing.T) { defer release() modules := importGraph("foo.com/A", "", 0) for _, v := range modules { - MustInsertModuleLatest(ctx, t, testDB, v) + MustInsertModule(ctx, t, testDB, v) } if _, err := testDB.UpdateSearchDocumentsImportedByCount(ctx); err != nil { t.Fatal(err) @@ -550,7 +550,7 @@ func TestInsertSearchDocumentAndSearch(t *testing.T) { pkg.Licenses = sample.LicenseMetadata() m := sample.Module(modulePath, sample.VersionString) sample.AddUnit(m, pkg) - MustInsertModuleLatest(ctx, t, testDB, m) + MustInsertModule(ctx, t, testDB, m) } if test.limit < 1 { @@ -606,7 +606,7 @@ func TestSearchPenalties(t *testing.T) { v.Packages()[0].IsRedistributable = m.redist v.IsRedistributable = m.redist v.HasGoMod = m.hasGoMod - MustInsertModuleLatest(ctx, t, testDB, v) + MustInsertModule(ctx, t, testDB, v) } for method, searcher := range searchers { @@ -640,7 +640,7 @@ func TestExcludedFromSearch(t *testing.T) { // Insert a module with two packages. const domain = "exclude.com" sm := sample.Module(domain, "v1.2.3", "pkg", "ex/clude") - MustInsertModuleLatest(ctx, t, testDB, sm) + MustInsertModule(ctx, t, testDB, sm) // Exclude a prefix that matches one of the packages. if err := testDB.InsertExcludedPrefix(ctx, domain+"/ex", "no user", "no reason"); err != nil { t.Fatal(err) @@ -669,7 +669,7 @@ func TestSearchBypass(t *testing.T) { bypassDB := NewBypassingLicenseCheck(testDB.db) m := nonRedistributableModule() - MustInsertModuleLatest(ctx, t, bypassDB, m) + MustInsertModule(ctx, t, bypassDB, m) for _, test := range []struct { db *DB @@ -703,7 +703,7 @@ func TestSearchLicenseDedup(t *testing.T) { FilePath: "pkg/LICENSE.md", }, }) - MustInsertModuleLatest(ctx, t, testDB, m) + MustInsertModule(ctx, t, testDB, m) got, err := testDB.Search(ctx, m.ModulePath, 10, 0, 100) if err != nil { t.Fatal(err) @@ -791,7 +791,7 @@ func TestUpsertSearchDocument(t *testing.T) { m := sample.Module(sample.ModulePath, version, "A") m.HasGoMod = gomod m.Packages()[0].Documentation[0].Synopsis = "syn-" + version - MustInsertModuleLatest(ctx, t, testDB, m) + MustInsertModule(ctx, t, testDB, m) } const v1 = "v1.0.0" @@ -844,7 +844,7 @@ func TestUpsertSearchDocumentVersionHasGoMod(t *testing.T) { for _, hasGoMod := range []bool{true, false} { m := sample.Module(fmt.Sprintf("foo.com/%t", hasGoMod), "v1.2.3", "bar") m.HasGoMod = hasGoMod - MustInsertModuleLatest(ctx, t, testDB, m) + MustInsertModule(ctx, t, testDB, m) } for _, hasGoMod := range []bool{true, false} { @@ -875,7 +875,7 @@ func TestUpdateSearchDocumentsImportedByCount(t *testing.T) { for _, imp := range imports { pkg.Imports = append(pkg.Imports, fmt.Sprintf("mod.com/%s/%[1]s", imp)) } - MustInsertModuleLatest(ctx, t, db, m) + MustInsertModule(ctx, t, db, m) return m } @@ -982,7 +982,7 @@ func TestUpdateSearchDocumentsImportedByCount(t *testing.T) { // It should not get inserted into search_documents. mAlt := sample.Module(alternativeModulePath, "v1.0.0", "A") mAlt.Packages()[0].Imports = []string{"B"} - MustInsertModuleLatest(ctx, t, testDB, mAlt) + MustInsertModule(ctx, t, testDB, mAlt) // Although B is imported by two packages, only one is in search_documents, so its // imported-by count is 1. updateImportedByCount(testDB) @@ -1013,7 +1013,7 @@ func TestGetPackagesForSearchDocumentUpsert(t *testing.T) { moduleN := nonRedistributableModule() bypassDB := NewBypassingLicenseCheck(testDB.db) for _, m := range []*internal.Module{moduleA, moduleN} { - MustInsertModuleLatest(ctx, t, bypassDB, m) + MustInsertModule(ctx, t, bypassDB, m) } // We are asking for all packages in search_documents updated before now, which is @@ -1152,7 +1152,7 @@ func TestDeleteOlderVersionFromSearch(t *testing.T) { } insert := func(m module) { sm := sample.Module(m.path, m.version, m.pkg) - MustInsertModuleLatest(ctx, t, testDB, sm) + MustInsertModule(ctx, t, testDB, sm) } check := func(m module) { diff --git a/internal/postgres/stdlib_test.go b/internal/postgres/stdlib_test.go index 32f41eca..ce5f2198 100644 --- a/internal/postgres/stdlib_test.go +++ b/internal/postgres/stdlib_test.go @@ -46,7 +46,7 @@ func TestGetStdlibPaths(t *testing.T) { for _, p := range m.Packages() { p.Imports = nil } - MustInsertModuleLatest(ctx, t, testDB, m) + MustInsertModule(ctx, t, testDB, m) } got, err := testDB.GetStdlibPathsWithSuffix(ctx, "json") diff --git a/internal/postgres/symbol_test.go b/internal/postgres/symbol_test.go index 82634bff..0ea7b79e 100644 --- a/internal/postgres/symbol_test.go +++ b/internal/postgres/symbol_test.go @@ -38,7 +38,7 @@ func TestInsertSymbolNamesAndHistory(t *testing.T) { sample.Type, } mod.Packages()[0].Documentation[0].API = api - MustInsertModuleLatest(ctx, t, testDB, mod) + MustInsertModule(ctx, t, testDB, mod) got, err := collectStrings(ctx, testDB.db, `SELECT name FROM symbol_names;`) if err != nil { @@ -86,7 +86,7 @@ func TestInsertSymbolHistory_Basic(t *testing.T) { sample.Type, } mod.Packages()[0].Documentation[0].API = api - MustInsertModuleLatest(ctx, t, testDB, mod) + MustInsertModule(ctx, t, testDB, mod) compareUnitSymbols(ctx, t, testDB, mod.Packages()[0].Path, mod.ModulePath, mod.Version, map[internal.BuildContext][]*internal.Symbol{internal.BuildContextAll: api}) @@ -136,9 +136,9 @@ func TestInsertSymbolHistory_MultiVersions(t *testing.T) { mod12 := moduleWithSymbols(t, "v1.2.0", []*internal.Symbol{&typB}) // Insert most recent, then oldest, then middle version. - MustInsertModuleLatest(ctx, t, testDB, mod12) - MustInsertModuleLatest(ctx, t, testDB, mod10) - MustInsertModuleLatest(ctx, t, testDB, mod11) + MustInsertModule(ctx, t, testDB, mod12) + MustInsertModule(ctx, t, testDB, mod10) + MustInsertModule(ctx, t, testDB, mod11) createwant := func(docs []*internal.Documentation) map[internal.BuildContext][]*internal.Symbol { want := map[internal.BuildContext][]*internal.Symbol{} @@ -254,9 +254,9 @@ func TestInsertSymbolHistory_MultiGOOS(t *testing.T) { mod12.Packages()[0].Documentation = docs2 // Insert most recent, then oldest, then middle version. - MustInsertModuleLatest(ctx, t, testDB, mod12) - MustInsertModuleLatest(ctx, t, testDB, mod10) - MustInsertModuleLatest(ctx, t, testDB, mod11) + MustInsertModule(ctx, t, testDB, mod12) + MustInsertModule(ctx, t, testDB, mod10) + MustInsertModule(ctx, t, testDB, mod11) createwant := func(docs []*internal.Documentation) map[internal.BuildContext][]*internal.Symbol { want := map[internal.BuildContext][]*internal.Symbol{} diff --git a/internal/postgres/test_helper.go b/internal/postgres/test_helper.go index 3fc7eb54..2c359fa0 100644 --- a/internal/postgres/test_helper.go +++ b/internal/postgres/test_helper.go @@ -199,31 +199,22 @@ func RunDBTestsInParallel(dbBaseName string, numDBs int, m *testing.M, acquirep os.Exit(code) } -// MustInsertModule inserts m into db, calling t.Fatal on error. -func MustInsertModule(ctx context.Context, t *testing.T, db *DB, m *internal.Module) { - 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) { - MustInsertModuleGoMod(ctx, t, db, m, "module "+m.ModulePath) +func MustInsertModule(ctx context.Context, t *testing.T, db *DB, m *internal.Module) { + MustInsertModuleGoMod(ctx, t, db, m, "") } func MustInsertModuleGoMod(ctx context.Context, t *testing.T, db *DB, m *internal.Module, goMod string) { + t.Helper() + var lmv *internal.LatestModuleVersions if goMod == "-" { if err := db.UpdateLatestModuleVersionsStatus(ctx, m.ModulePath, 404); err != nil { t.Fatal(err) } - MustInsertModuleLMV(ctx, t, db, m, nil) } else { - lmv := addLatest(ctx, t, db, m.ModulePath, m.Version, goMod) - MustInsertModuleLMV(ctx, t, db, m, lmv) + lmv = addLatest(ctx, t, db, m.ModulePath, m.Version, goMod) } -} - -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 { t.Fatal(err) } @@ -315,7 +306,7 @@ func InsertSampleDirectoryTree(ctx context.Context, t *testing.T, testDB *DB) { }, } { m := sample.Module(data.modulePath, data.version, data.suffixes...) - MustInsertModuleLatest(ctx, t, testDB, m) + MustInsertModule(ctx, t, testDB, m) } } diff --git a/internal/postgres/unit_test.go b/internal/postgres/unit_test.go index 69b0bc9b..cf4f7ea4 100644 --- a/internal/postgres/unit_test.go +++ b/internal/postgres/unit_test.go @@ -331,7 +331,7 @@ func TestGetUnitMetaBypass(t *testing.T) { m := sample.Module(testModule.module, testModule.version, testModule.packageSuffix) makeModuleNonRedistributable(m) - MustInsertModuleLatest(ctx, t, bypassDB, m) + MustInsertModule(ctx, t, bypassDB, m) requested := m.Version if testModule.isMaster { requested = "master" @@ -699,7 +699,7 @@ func TestGetUnit(t *testing.T) { Filepath: "PKG_README.md", Contents: "pkg readme", } - MustInsertModuleLatest(ctx, t, testDB, m) + MustInsertModule(ctx, t, testDB, m) // Add a module that has documentation for two Go build contexts. m = sample.Module("a.com/twodoc", "v1.2.3", "p") @@ -709,7 +709,7 @@ func TestGetUnit(t *testing.T) { sample.Documentation("windows", "amd64", `package p; var W int`), } pkg.Documentation = docs2 - MustInsertModuleLatest(ctx, t, testDB, m) + MustInsertModule(ctx, t, testDB, m) for _, test := range []struct { name, path, modulePath, version string @@ -881,7 +881,7 @@ func TestGetUnit_SubdirectoriesShowNonRedistPackages(t *testing.T) { m := sample.DefaultModule() m.IsRedistributable = false m.Packages()[0].IsRedistributable = false - MustInsertModuleLatest(ctx, t, testDB, m) + MustInsertModule(ctx, t, testDB, m) } func TestGetUnitFieldSet(t *testing.T) { @@ -898,7 +898,7 @@ func TestGetUnitFieldSet(t *testing.T) { // Add a module that has READMEs in a directory and a package. m := sample.Module("a.com/m", "v1.2.3", "dir/p") m.Packages()[0].Readme = readme - MustInsertModuleLatest(ctx, t, testDB, m) + MustInsertModule(ctx, t, testDB, m) cleanFields := func(u *internal.Unit, fields internal.FieldSet) { // Add/remove fields based on the FieldSet specified. @@ -1022,7 +1022,7 @@ func TestGetUnitBypass(t *testing.T) { bypassDB := NewBypassingLicenseCheck(testDB.db) m := nonRedistributableModule() - MustInsertModuleLatest(ctx, t, bypassDB, m) + MustInsertModule(ctx, t, bypassDB, m) for _, test := range []struct { db *DB diff --git a/internal/postgres/version_map_test.go b/internal/postgres/version_map_test.go index 4b8e0820..1532e729 100644 --- a/internal/postgres/version_map_test.go +++ b/internal/postgres/version_map_test.go @@ -23,7 +23,7 @@ func TestReadAndWriteVersionMap(t *testing.T) { defer cancel() m := sample.Module("golang.org/x/tools", sample.VersionString, "go/packages") - MustInsertModuleLatest(ctx, t, testDB, m) + MustInsertModule(ctx, t, testDB, m) vm := &internal.VersionMap{ ModulePath: m.ModulePath, diff --git a/internal/postgres/version_test.go b/internal/postgres/version_test.go index c3779c17..0f81dd47 100644 --- a/internal/postgres/version_test.go +++ b/internal/postgres/version_test.go @@ -274,7 +274,7 @@ func TestGetLatestInfo(t *testing.T) { sample.Module("gopkg.in/M.v3", "v3.0.0-20200602140019-6ec2bf8d378b", ""), sample.Module("c.com/M", "v0.0.0-20200602140019-6ec2bf8d378b", ""), } { - MustInsertModuleLatest(ctx, t, testDB, m) + MustInsertModule(ctx, t, testDB, m) } for _, test := range []struct { @@ -436,7 +436,7 @@ func TestGetLatestGoodVersion(t *testing.T) { t.Fatal(err) } for _, v := range []string{"v2.0.0+incompatible", "v1.4.0-pre", "v1.3.0", "v1.2.0", "v1.1.0"} { - MustInsertModuleLatest(ctx, t, testDB, sample.Module(modulePath, v, "pkg")) + MustInsertModule(ctx, t, testDB, sample.Module(modulePath, v, "pkg")) } for _, test := range []struct { @@ -648,12 +648,12 @@ func TestLatestModuleVersionsGood(t *testing.T) { // Add two good versions. const v1 = "v1.1.0" - MustInsertModuleLatest(ctx, t, testDB, sample.Module(modulePath, v1, "pkg")) + MustInsertModule(ctx, t, testDB, sample.Module(modulePath, v1, "pkg")) check(v1) // Good version should be updated. const v2 = "v1.2.0" - MustInsertModuleLatest(ctx, t, testDB, sample.Module(modulePath, v2, "pkg")) + MustInsertModule(ctx, t, testDB, sample.Module(modulePath, v2, "pkg")) check(v2) // New latest-version info retracts v2 (and itself); good version should switch to v1. diff --git a/internal/postgres/versionstate_test.go b/internal/postgres/versionstate_test.go index b04b4239..103a6aa3 100644 --- a/internal/postgres/versionstate_test.go +++ b/internal/postgres/versionstate_test.go @@ -223,7 +223,7 @@ func TestUpsertModuleVersionStates(t *testing.T) { defer release() if test.insertModuleBeforeMVS && test.shouldInsertModule { - MustInsertModuleLatest(ctx, t, testDB, m) + MustInsertModule(ctx, t, testDB, m) } mvsu := &ModuleVersionStateForUpsert{ @@ -250,7 +250,7 @@ func TestUpsertModuleVersionStates(t *testing.T) { } if !test.insertModuleBeforeMVS && test.shouldInsertModule { - MustInsertModuleLatest(ctx, t, testDB, m) + MustInsertModule(ctx, t, testDB, m) } if !test.shouldInsertModule { @@ -349,7 +349,7 @@ func TestHasGoMod(t *testing.T) { if test.modulesHasRow { m := sample.Module(modulePath, version, "") m.HasGoMod = test.modulesValue - MustInsertModuleLatest(ctx, t, testDB, m) + MustInsertModule(ctx, t, testDB, m) } got, err := testDB.HasGoMod(ctx, modulePath, version) diff --git a/internal/testing/integration/frontend_test.go b/internal/testing/integration/frontend_test.go index 01b9c576..0ccce04c 100644 --- a/internal/testing/integration/frontend_test.go +++ b/internal/testing/integration/frontend_test.go @@ -103,7 +103,7 @@ func fetchAndInsertModule(ctx context.Context, t *testing.T, tm *proxy.Module, p if res.Error != nil { t.Fatal(res.Error) } - postgres.MustInsertModuleLatest(ctx, t, testDB, res.Module) + postgres.MustInsertModule(ctx, t, testDB, res.Module) } func validateResponse(t *testing.T, method, testURL string, wantCode int, wantHTML htmlcheck.Checker) {