internal/testing/sample: prefix legacy functions with Legacy
For golang/go#39629
Change-Id: I3953c39e419ac8b74ac7f61ac6ffa9ec39e288aa
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/258599
Trust: Julie Qiu <julie@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
diff --git a/internal/frontend/fetch_test.go b/internal/frontend/fetch_test.go
index 7c10d87..60c2c82 100644
--- a/internal/frontend/fetch_test.go
+++ b/internal/frontend/fetch_test.go
@@ -148,7 +148,7 @@
t.Run(strconv.Itoa(test.status), func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), testFetchTimeout)
defer cancel()
- if err := testDB.InsertModule(ctx, sample.DefaultModule()); err != nil {
+ if err := testDB.InsertModule(ctx, sample.LegacyDefaultModule()); err != nil {
t.Fatal(err)
}
if err := testDB.UpsertVersionMap(ctx, &internal.VersionMap{
diff --git a/internal/frontend/imports_test.go b/internal/frontend/imports_test.go
index 310c01d..5cd695b 100644
--- a/internal/frontend/imports_test.go
+++ b/internal/frontend/imports_test.go
@@ -49,7 +49,7 @@
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
defer cancel()
- module := sample.Module(sample.ModulePath, sample.VersionString, sample.Suffix)
+ module := sample.LegacyModule(sample.ModulePath, sample.VersionString, sample.Suffix)
// The first unit is the module and the second one is the package.
pkg := module.Units[1]
pkg.Imports = tc.imports
@@ -79,9 +79,9 @@
defer cancel()
newModule := func(modPath string, pkgs ...*internal.LegacyPackage) *internal.Module {
- m := sample.Module(modPath, sample.VersionString)
+ m := sample.LegacyModule(modPath, sample.VersionString)
for _, p := range pkgs {
- sample.AddPackage(m, p)
+ sample.LegacyAddPackage(m, p)
}
return m
}
diff --git a/internal/frontend/license_test.go b/internal/frontend/license_test.go
index cf34ce1..b48e73d 100644
--- a/internal/frontend/license_test.go
+++ b/internal/frontend/license_test.go
@@ -44,10 +44,10 @@
}
func TestFetchLicensesDetails(t *testing.T) {
- testModule := sample.Module(sample.ModulePath, "v1.2.3", "A/B")
- stdlibModule := sample.Module(stdlib.ModulePath, "v1.13.0", "cmd/go")
+ testModule := sample.LegacyModule(sample.ModulePath, "v1.2.3", "A/B")
+ stdlibModule := sample.LegacyModule(stdlib.ModulePath, "v1.13.0", "cmd/go")
crlfPath := "github.com/crlf/module_name"
- crlfModule := sample.Module(crlfPath, "v1.2.3", "A")
+ crlfModule := sample.LegacyModule(crlfPath, "v1.2.3", "A")
mit := &licenses.Metadata{Types: []string{"MIT"}, FilePath: "LICENSE"}
bsd := &licenses.Metadata{Types: []string{"BSD-3-Clause"}, FilePath: "A/B/LICENSE"}
diff --git a/internal/frontend/overview_test.go b/internal/frontend/overview_test.go
index 718aeda..690a498 100644
--- a/internal/frontend/overview_test.go
+++ b/internal/frontend/overview_test.go
@@ -30,7 +30,7 @@
wantDetails *OverviewDetails
}{
name: "want expected overview details",
- module: sample.DefaultModule(),
+ module: sample.LegacyDefaultModule(),
wantDetails: &OverviewDetails{
ModulePath: sample.ModulePath,
RepositoryURL: sample.RepositoryURL,
@@ -142,7 +142,7 @@
} {
t.Run(test.name, func(t *testing.T) {
defer postgres.ResetTestDB(testDB, t)
- m := sample.Module(
+ m := sample.LegacyModule(
test.dir.ModulePath,
test.dir.Version,
internal.Suffix(test.dir.Path, test.dir.ModulePath))
diff --git a/internal/frontend/package_test.go b/internal/frontend/package_test.go
index b840888..c0993dd 100644
--- a/internal/frontend/package_test.go
+++ b/internal/frontend/package_test.go
@@ -16,7 +16,7 @@
func TestStdlibPathForShortcut(t *testing.T) {
defer postgres.ResetTestDB(testDB, t)
- m := sample.Module(stdlib.ModulePath, "v1.2.3",
+ m := sample.LegacyModule(stdlib.ModulePath, "v1.2.3",
"encoding/json", // one match for "json"
"text/template", "html/template", // two matches for "template"
)
diff --git a/internal/frontend/search_test.go b/internal/frontend/search_test.go
index 401dc09..3b3129f 100644
--- a/internal/frontend/search_test.go
+++ b/internal/frontend/search_test.go
@@ -212,8 +212,8 @@
defer cancel()
defer postgres.ResetTestDB(testDB, t)
- golangTools := sample.Module("golang.org/x/tools", sample.VersionString, "internal/lsp")
- std := sample.Module("std", sample.VersionString,
+ golangTools := sample.LegacyModule("golang.org/x/tools", sample.VersionString, "internal/lsp")
+ std := sample.LegacyModule("std", sample.VersionString,
"cmd/go", "cmd/go/internal/auth", "fmt")
modules := []*internal.Module{golangTools, std}
diff --git a/internal/frontend/server_test.go b/internal/frontend/server_test.go
index 8fcafe5..f128eb9 100644
--- a/internal/frontend/server_test.go
+++ b/internal/frontend/server_test.go
@@ -166,14 +166,14 @@
ps = append(ps, p)
}
for _, ver := range mod.versions {
- m := sample.Module(mod.path, ver)
+ m := sample.LegacyModule(mod.path, ver)
m.SourceInfo = source.NewGitHubInfo(sample.RepositoryURL, "", ver)
m.IsRedistributable = mod.redistributable
if !m.IsRedistributable {
m.Licenses = nil
}
for _, p := range ps {
- sample.AddPackage(m, p)
+ sample.LegacyAddPackage(m, p)
}
for _, u := range m.Units {
if !mod.redistributable {
@@ -977,7 +977,7 @@
defer cancel()
defer postgres.ResetTestDB(testDB, t)
- sampleModule := sample.DefaultModule()
+ sampleModule := sample.LegacyDefaultModule()
if err := testDB.InsertModule(ctx, sampleModule); err != nil {
t.Fatal(err)
}
diff --git a/internal/frontend/versions_test.go b/internal/frontend/versions_test.go
index 9965ca9..3cb6f79 100644
--- a/internal/frontend/versions_test.go
+++ b/internal/frontend/versions_test.go
@@ -23,11 +23,11 @@
func sampleModule(modulePath, version string, versionType version.Type, packages ...*internal.LegacyPackage) *internal.Module {
if len(packages) == 0 {
- return sample.Module(modulePath, version, sample.Suffix)
+ return sample.LegacyModule(modulePath, version, sample.Suffix)
}
- m := sample.Module(modulePath, version)
+ m := sample.LegacyModule(modulePath, version)
for _, p := range packages {
- sample.AddPackage(m, p)
+ sample.LegacyAddPackage(m, p)
}
return m
}
diff --git a/internal/postgres/details_test.go b/internal/postgres/details_test.go
index 733727c..5ffebb8 100644
--- a/internal/postgres/details_test.go
+++ b/internal/postgres/details_test.go
@@ -32,10 +32,10 @@
name: "Nested Modules in cloud.google.com/go that have the same module prefix path",
path: "cloud.google.com/go",
modules: []*internal.Module{
- sample.Module("cloud.google.com/go", "v0.46.2", "storage", "spanner", "pubsub"),
- sample.Module("cloud.google.com/go/storage", "v1.10.0", sample.Suffix),
- sample.Module("cloud.google.com/go/spanner", "v1.9.0", sample.Suffix),
- sample.Module("cloud.google.com/go/pubsub", "v1.6.1", sample.Suffix),
+ sample.LegacyModule("cloud.google.com/go", "v0.46.2", "storage", "spanner", "pubsub"),
+ sample.LegacyModule("cloud.google.com/go/storage", "v1.10.0", sample.Suffix),
+ sample.LegacyModule("cloud.google.com/go/spanner", "v1.9.0", sample.Suffix),
+ sample.LegacyModule("cloud.google.com/go/pubsub", "v1.6.1", sample.Suffix),
},
wantModulePaths: []string{
"cloud.google.com/go/pubsub",
@@ -47,10 +47,10 @@
name: "Nested Modules in cloud.google.com/go that have multiple major versions",
path: "cloud.google.com/go",
modules: []*internal.Module{
- sample.Module("cloud.google.com/go", "v0.46.2", "storage", "spanner", "pubsub"),
- sample.Module("cloud.google.com/go/storage", "v1.10.0", sample.Suffix),
- sample.Module("cloud.google.com/go/storage/v9", "v9.0.0", sample.Suffix),
- sample.Module("cloud.google.com/go/storage/v11", "v11.0.0", sample.Suffix),
+ sample.LegacyModule("cloud.google.com/go", "v0.46.2", "storage", "spanner", "pubsub"),
+ sample.LegacyModule("cloud.google.com/go/storage", "v1.10.0", sample.Suffix),
+ sample.LegacyModule("cloud.google.com/go/storage/v9", "v9.0.0", sample.Suffix),
+ sample.LegacyModule("cloud.google.com/go/storage/v11", "v11.0.0", sample.Suffix),
},
wantModulePaths: []string{
"cloud.google.com/go/storage/v11",
@@ -95,11 +95,11 @@
name: "Nested Modules in cloud.google.com/go that have the same module prefix path",
path: "cloud.google.com/go",
modules: []*internal.Module{
- sample.Module("cloud.google.com/go", "v0.46.2", "storage", "spanner", "pubsub"),
+ sample.LegacyModule("cloud.google.com/go", "v0.46.2", "storage", "spanner", "pubsub"),
// cloud.google.com/storage will be excluded below.
- sample.Module("cloud.google.com/go/storage", "v1.10.0", sample.Suffix),
- sample.Module("cloud.google.com/go/pubsub", "v1.6.1", sample.Suffix),
- sample.Module("cloud.google.com/go/spanner", "v1.9.0", sample.Suffix),
+ sample.LegacyModule("cloud.google.com/go/storage", "v1.10.0", sample.Suffix),
+ sample.LegacyModule("cloud.google.com/go/pubsub", "v1.6.1", sample.Suffix),
+ sample.LegacyModule("cloud.google.com/go/spanner", "v1.9.0", sample.Suffix),
},
wantModulePaths: []string{
"cloud.google.com/go/pubsub",
@@ -145,9 +145,9 @@
path: "mod.1",
version: "v1.0.2",
modules: []*internal.Module{
- sample.Module("mod.1", "v1.1.0", sample.Suffix),
- sample.Module("mod.1", "v1.0.2", sample.Suffix),
- sample.Module("mod.1", "v1.0.0", sample.Suffix),
+ sample.LegacyModule("mod.1", "v1.1.0", sample.Suffix),
+ sample.LegacyModule("mod.1", "v1.0.2", sample.Suffix),
+ sample.LegacyModule("mod.1", "v1.0.0", sample.Suffix),
},
wantIndex: 1,
},
@@ -156,9 +156,9 @@
path: "mod.2",
version: "v1.0.3",
modules: []*internal.Module{
- sample.Module("mod.2", "v1.1.0", sample.Suffix),
- sample.Module("mod.2", "v1.0.2", sample.Suffix),
- sample.Module("mod.2", "v1.0.0", sample.Suffix),
+ sample.LegacyModule("mod.2", "v1.1.0", sample.Suffix),
+ sample.LegacyModule("mod.2", "v1.0.2", sample.Suffix),
+ sample.LegacyModule("mod.2", "v1.0.0", sample.Suffix),
},
wantErr: derrors.NotFound,
},
@@ -201,9 +201,9 @@
func TestGetImportedBy(t *testing.T) {
var (
- m1 = sample.Module("path.to/foo", "v1.1.0", "bar")
- m2 = sample.Module("path2.to/foo", "v1.2.0", "bar2")
- m3 = sample.Module("path3.to/foo", "v1.3.0", "bar3")
+ m1 = sample.LegacyModule("path.to/foo", "v1.1.0", "bar")
+ m2 = sample.LegacyModule("path2.to/foo", "v1.2.0", "bar2")
+ m3 = sample.LegacyModule("path3.to/foo", "v1.3.0", "bar3")
testModules = []*internal.Module{m1, m2, m3}
pkg1 = m1.LegacyPackages[0]
diff --git a/internal/postgres/insert_module_test.go b/internal/postgres/insert_module_test.go
index cd64eaa..ac2500f 100644
--- a/internal/postgres/insert_module_test.go
+++ b/internal/postgres/insert_module_test.go
@@ -39,16 +39,16 @@
}{
{
name: "valid test",
- module: sample.DefaultModule(),
+ module: sample.LegacyDefaultModule(),
},
{
name: "valid test with internal package",
- module: sample.Module(sample.ModulePath, sample.VersionString, "internal/foo"),
+ module: sample.LegacyModule(sample.ModulePath, sample.VersionString, "internal/foo"),
},
{
name: "valid test with go.mod missing",
module: func() *internal.Module {
- m := sample.DefaultModule()
+ m := sample.LegacyDefaultModule()
m.HasGoMod = false
return m
}(),
@@ -56,7 +56,7 @@
{
name: "stdlib",
module: func() *internal.Module {
- m := sample.Module("std", "v1.12.5")
+ m := sample.LegacyModule("std", "v1.12.5")
p := &internal.LegacyPackage{
Name: "context",
Path: "context",
@@ -65,7 +65,7 @@
IsRedistributable: true,
DocumentationHTML: testconversions.MakeHTMLForTest("This is the documentation HTML"),
}
- return sample.AddPackage(m, p)
+ return sample.LegacyAddPackage(m, p)
}(),
},
} {
@@ -166,7 +166,7 @@
}
}
- mod := sample.Module(sample.ModulePath, sample.VersionString, "")
+ mod := sample.LegacyModule(sample.ModulePath, sample.VersionString, "")
checkHasRedistData(mod.LegacyReadmeContents, mod.LegacyPackages[0].DocumentationHTML, true)
checkHasRedistData(mod.Units[0].Readme.Contents, mod.Units[0].Documentation.HTML, true)
mod.IsRedistributable = false
@@ -203,7 +203,7 @@
func TestUpsertModule(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
defer cancel()
- m := sample.Module("upsert.org", "v1.2.3")
+ m := sample.LegacyModule("upsert.org", "v1.2.3")
p := &internal.LegacyPackage{
Name: "p",
Path: "upsert.org/dir/p",
@@ -212,7 +212,7 @@
IsRedistributable: true,
DocumentationHTML: testconversions.MakeHTMLForTest("This is the documentation HTML"),
}
- sample.AddPackage(m, p)
+ sample.LegacyAddPackage(m, p)
// Insert the module.
if err := testDB.InsertModule(ctx, m); err != nil {
@@ -256,20 +256,20 @@
},
{
name: "nonexistent version",
- module: sample.DefaultModule(),
+ module: sample.LegacyDefaultModule(),
wantModulePath: sample.ModulePath,
wantVersion: "v1.2.3",
},
{
name: "nonexistent module",
- module: sample.DefaultModule(),
+ module: sample.LegacyDefaultModule(),
wantModulePath: "nonexistent_module_path",
wantVersion: "v1.0.0",
wantPkgPath: sample.PackagePath,
},
{
name: "missing module path",
- module: sample.Module("", sample.VersionString),
+ module: sample.LegacyModule("", sample.VersionString),
wantVersion: sample.VersionString,
wantModulePath: sample.ModulePath,
wantWriteErr: derrors.DBModuleInsertInvalid,
@@ -277,7 +277,7 @@
{
name: "missing version",
module: func() *internal.Module {
- m := sample.DefaultModule()
+ m := sample.LegacyDefaultModule()
m.Version = ""
return m
}(),
@@ -288,7 +288,7 @@
{
name: "empty commit time",
module: func() *internal.Module {
- v := sample.DefaultModule()
+ v := sample.LegacyDefaultModule()
v.CommitTime = time.Time{}
return v
}(),
@@ -318,7 +318,7 @@
sortVersion, seriesPath string
}
- v := sample.Module("github.com/user/repo/path/v2", "v1.2.3-beta.4.a", sample.Suffix)
+ v := sample.LegacyModule("github.com/user/repo/path/v2", "v1.2.3-beta.4.a", sample.Suffix)
want := other{
sortVersion: "1,2,3,~beta,4,~a",
seriesPath: "github.com/user/repo/path",
@@ -373,7 +373,7 @@
modulePath: sample.ModulePath + "/v3",
},
} {
- m := sample.DefaultModule()
+ m := sample.LegacyDefaultModule()
m.Version = mod.version
m.ModulePath = mod.modulePath
@@ -420,7 +420,7 @@
defer cancel()
defer ResetTestDB(testDB, t)
- v := sample.DefaultModule()
+ v := sample.LegacyDefaultModule()
if err := testDB.InsertModule(ctx, v); err != nil {
t.Fatal(err)
@@ -477,7 +477,7 @@
if err != nil {
t.Fatal(err)
}
- m := sample.Module(modulePath, okVersion, "p")
+ m := sample.LegacyModule(modulePath, okVersion, "p")
if err := testDB.InsertModule(ctx, m); err != nil {
t.Fatal(err)
}
diff --git a/internal/postgres/licenses_test.go b/internal/postgres/licenses_test.go
index 825608a..71130d2 100644
--- a/internal/postgres/licenses_test.go
+++ b/internal/postgres/licenses_test.go
@@ -19,8 +19,8 @@
)
func TestGetLicenses(t *testing.T) {
- testModule := sample.Module(sample.ModulePath, "v1.2.3", "A/B")
- stdlibModule := sample.Module(stdlib.ModulePath, "v1.13.0", "cmd/go")
+ testModule := sample.LegacyModule(sample.ModulePath, "v1.2.3", "A/B")
+ stdlibModule := sample.LegacyModule(stdlib.ModulePath, "v1.13.0", "cmd/go")
mit := &licenses.Metadata{Types: []string{"MIT"}, FilePath: "LICENSE"}
bsd := &licenses.Metadata{Types: []string{"BSD-3-Clause"}, FilePath: "A/B/LICENSE"}
@@ -123,7 +123,7 @@
func TestGetModuleLicenses(t *testing.T) {
modulePath := "test.module"
- testModule := sample.Module(modulePath, "v1.2.3", "", "foo", "bar")
+ testModule := sample.LegacyModule(modulePath, "v1.2.3", "", "foo", "bar")
testModule.LegacyPackages[0].Licenses = []*licenses.Metadata{{Types: []string{"ISC"}, FilePath: "LICENSE"}}
testModule.LegacyPackages[1].Licenses = []*licenses.Metadata{{Types: []string{"MIT"}, FilePath: "foo/LICENSE"}}
testModule.LegacyPackages[2].Licenses = []*licenses.Metadata{{Types: []string{"GPL2"}, FilePath: "bar/LICENSE.txt"}}
@@ -198,7 +198,7 @@
}
func nonRedistributableModule() *internal.Module {
- m := sample.Module(sample.ModulePath, "v1.2.3", "")
+ m := sample.LegacyModule(sample.ModulePath, "v1.2.3", "")
sample.AddLicense(m, sample.NonRedistributableLicense)
m.IsRedistributable = false
m.LegacyPackages[0].IsRedistributable = false
diff --git a/internal/postgres/package_test.go b/internal/postgres/package_test.go
index 9618e53..bcd87ef 100644
--- a/internal/postgres/package_test.go
+++ b/internal/postgres/package_test.go
@@ -38,7 +38,7 @@
insertModule := func(pkgPath, modulePath, version string) {
t.Helper()
- m := sample.Module(modulePath, version, suffix(pkgPath, modulePath))
+ m := sample.LegacyModule(modulePath, version, suffix(pkgPath, modulePath))
if err := testDB.InsertModule(ctx, m); err != nil {
t.Fatal(err)
}
diff --git a/internal/postgres/parent_directories_test.go b/internal/postgres/parent_directories_test.go
index 67090e4..b027f2b 100644
--- a/internal/postgres/parent_directories_test.go
+++ b/internal/postgres/parent_directories_test.go
@@ -74,7 +74,7 @@
default:
suffix = tc.path[len(tc.modulePath)+1:]
}
- m := sample.Module(tc.modulePath, sample.VersionString, suffix)
+ m := sample.LegacyModule(tc.modulePath, sample.VersionString, suffix)
if err := testDB.InsertModule(ctx, m); err != nil {
t.Fatal(err)
}
diff --git a/internal/postgres/path_test.go b/internal/postgres/path_test.go
index 44c2ff9..b783ae3 100644
--- a/internal/postgres/path_test.go
+++ b/internal/postgres/path_test.go
@@ -243,7 +243,7 @@
},
},
} {
- m := sample.Module(stdlib.ModulePath, data.version, data.suffixes...)
+ m := sample.LegacyModule(stdlib.ModulePath, data.version, data.suffixes...)
for _, p := range m.LegacyPackages {
p.Imports = nil
}
diff --git a/internal/postgres/search_test.go b/internal/postgres/search_test.go
index 899604f..3f1cf1c 100644
--- a/internal/postgres/search_test.go
+++ b/internal/postgres/search_test.go
@@ -153,18 +153,18 @@
// one popular package. For performance purposes, all importers are added to
// a single importing module.
func importGraph(popularPath, importerModule string, importerCount int) []*internal.Module {
- m := sample.Module(popularPath, "v1.2.3", "")
+ m := sample.LegacyModule(popularPath, "v1.2.3", "")
m.Packages()[0].Imports = nil
// Try to improve the ts_rank of the 'foo' search term.
m.Packages()[0].Documentation.Synopsis = "foo"
m.Units[0].Readme.Contents = "foo"
mods := []*internal.Module{m}
if importerCount > 0 {
- m := sample.Module(importerModule, "v1.2.3")
+ m := sample.LegacyModule(importerModule, "v1.2.3")
for i := 0; i < importerCount; i++ {
p := sample.LegacyPackage(importerModule, fmt.Sprintf("importer%d", i))
p.Imports = []string{popularPath}
- sample.AddPackage(m, p)
+ sample.LegacyAddPackage(m, p)
}
mods = append(mods, m)
}
@@ -527,8 +527,8 @@
for modulePath, pkg := range tc.packages {
pkg.Licenses = sample.LicenseMetadata
- m := sample.Module(modulePath, sample.VersionString)
- sample.AddPackage(m, pkg)
+ m := sample.LegacyModule(modulePath, sample.VersionString)
+ sample.LegacyAddPackage(m, pkg)
if err := testDB.InsertModule(ctx, m); err != nil {
t.Fatal(err)
}
@@ -582,7 +582,7 @@
}
for path, m := range modules {
- v := sample.Module(path, sample.VersionString, "p")
+ v := sample.LegacyModule(path, sample.VersionString, "p")
v.LegacyPackages[0].IsRedistributable = m.redist
v.IsRedistributable = m.redist
v.HasGoMod = m.hasGoMod
@@ -619,7 +619,7 @@
// Insert a module with two packages.
const domain = "exclude.com"
- sm := sample.Module(domain, "v1.2.3", "pkg", "exclude")
+ sm := sample.LegacyModule(domain, "v1.2.3", "pkg", "exclude")
if err := testDB.InsertModule(ctx, sm); err != nil {
t.Fatal(err)
}
@@ -740,7 +740,7 @@
}
insertModule := func(version string, gomod bool) {
- v := sample.Module(sample.ModulePath, version, "A")
+ v := sample.LegacyModule(sample.ModulePath, version, "A")
v.HasGoMod = gomod
v.LegacyPackages[0].Synopsis = "syn-" + version
if err := testDB.InsertModule(ctx, v); err != nil {
@@ -785,7 +785,7 @@
defer cancel()
for _, hasGoMod := range []bool{true, false} {
- m := sample.Module(fmt.Sprintf("foo.com/%t", hasGoMod), "v1.2.3", "bar")
+ m := sample.LegacyModule(fmt.Sprintf("foo.com/%t", hasGoMod), "v1.2.3", "bar")
m.HasGoMod = hasGoMod
if err := testDB.InsertModule(ctx, m); err != nil {
t.Fatal(err)
@@ -811,7 +811,7 @@
// insert package with suffix at version, return the module
insertPackageVersion := func(t *testing.T, suffix, version string, imports []string) *internal.Module {
t.Helper()
- m := sample.Module("mod.com/"+suffix, version, suffix)
+ m := sample.LegacyModule("mod.com/"+suffix, version, suffix)
// Units[0] is the module itself.
pkg := m.Units[1]
pkg.Imports = nil
@@ -918,7 +918,7 @@
// Now we see an earlier version of that package, without a go.mod file, so we insert it.
// It should not get inserted into search_documents.
- mAlt := sample.Module(alternativeModulePath, "v1.0.0", "A")
+ mAlt := sample.LegacyModule(alternativeModulePath, "v1.0.0", "A")
mAlt.LegacyPackages[0].Imports = []string{"B"}
if err := testDB.InsertModule(ctx, mAlt); err != nil {
t.Fatal(err)
@@ -936,7 +936,7 @@
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
defer cancel()
- moduleA := sample.Module("mod.com", "v1.2.3",
+ moduleA := sample.LegacyModule("mod.com", "v1.2.3",
"A", "A/notinternal", "A/internal", "A/internal/B")
// moduleA.Units[1] is mod.com/A.
@@ -1080,7 +1080,7 @@
wantDeleted bool
}
insert := func(m module) {
- sm := sample.Module(m.path, m.version, m.pkg)
+ sm := sample.LegacyModule(m.path, m.version, m.pkg)
if err := testDB.InsertModule(ctx, sm); err != nil {
t.Fatal(err)
}
diff --git a/internal/postgres/test_helper.go b/internal/postgres/test_helper.go
index 74b5909..606340e 100644
--- a/internal/postgres/test_helper.go
+++ b/internal/postgres/test_helper.go
@@ -213,7 +213,7 @@
},
},
} {
- m := sample.Module(data.modulePath, data.version, data.suffixes...)
+ m := sample.LegacyModule(data.modulePath, data.version, data.suffixes...)
for _, p := range m.LegacyPackages {
p.Imports = nil
}
diff --git a/internal/postgres/unit_test.go b/internal/postgres/unit_test.go
index cdc83e5..bc3174f 100644
--- a/internal/postgres/unit_test.go
+++ b/internal/postgres/unit_test.go
@@ -28,7 +28,7 @@
InsertSampleDirectoryTree(ctx, t, testDB)
// Add a module that has READMEs in a directory and a package.
- m := sample.Module("a.com/m", "v1.2.3", "dir/p")
+ m := sample.LegacyModule("a.com/m", "v1.2.3", "dir/p")
d := findDirectory(m, "a.com/m/dir")
d.Readme = &internal.Readme{
Filepath: "DIR_README.md",
@@ -200,7 +200,7 @@
defer ResetTestDB(testDB, 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 := sample.LegacyModule("a.com/m", "v1.2.3", "dir/p")
if err := testDB.InsertModule(ctx, m); err != nil {
t.Fatal(err)
}
diff --git a/internal/postgres/version_map_test.go b/internal/postgres/version_map_test.go
index 6869fcd..7f1529a 100644
--- a/internal/postgres/version_map_test.go
+++ b/internal/postgres/version_map_test.go
@@ -19,7 +19,7 @@
defer cancel()
defer ResetTestDB(testDB, t)
- m := sample.Module("golang.org/x/tools", sample.VersionString, "go/packages")
+ m := sample.LegacyModule("golang.org/x/tools", sample.VersionString, "go/packages")
err := testDB.InsertModule(ctx, m)
if err != nil {
t.Fatal(err)
diff --git a/internal/postgres/version_test.go b/internal/postgres/version_test.go
index 47b34ec..5c07196 100644
--- a/internal/postgres/version_test.go
+++ b/internal/postgres/version_test.go
@@ -32,31 +32,31 @@
rootModule = "golang.org/foo/bar"
nestedModule = "golang.org/foo/bar/api"
testModules = []*internal.Module{
- sample.Module(stdlib.ModulePath, "v1.15.0-beta.1", "cmd/go"),
- sample.Module(stdlib.ModulePath, "v1.14.6", "cmd/go"),
- sample.Module(taggedModuleV3, "v3.2.0-beta", "bar"),
- sample.Module(taggedModuleV3, "v3.2.0-alpha.2", "bar"),
- sample.Module(taggedModuleV3, "v3.2.0-alpha.1", "bar"),
- sample.Module(taggedModuleV3, "v3.1.0", "bar"),
- sample.Module(taggedModuleV3, "v3.0.0", "bar"),
- sample.Module(taggedModuleV2, "v2.0.1", "bar"),
- sample.Module(taggedAndPseudoModule, "v1.5.3-pre1", "bar"),
- sample.Module(taggedAndPseudoModule, "v1.5.2", "bar"),
- sample.Module(taggedAndPseudoModule, "v0.0.0-20200101120000-000000000000", "bar"),
- sample.Module(otherModule, "v3.0.0", "thing"),
- sample.Module(incompatibleModule, "v2.0.0+incompatible", "module"),
- sample.Module(incompatibleModule, "v0.0.0", "module"),
- sample.Module(rootModule, "v1.0.3", "api"),
- sample.Module(rootModule, "v0.11.6", "api"),
- sample.Module(nestedModule, "v1.0.4", "api"),
- sample.Module(nestedModule, "v1.0.3", "api"),
+ sample.LegacyModule(stdlib.ModulePath, "v1.15.0-beta.1", "cmd/go"),
+ sample.LegacyModule(stdlib.ModulePath, "v1.14.6", "cmd/go"),
+ sample.LegacyModule(taggedModuleV3, "v3.2.0-beta", "bar"),
+ sample.LegacyModule(taggedModuleV3, "v3.2.0-alpha.2", "bar"),
+ sample.LegacyModule(taggedModuleV3, "v3.2.0-alpha.1", "bar"),
+ sample.LegacyModule(taggedModuleV3, "v3.1.0", "bar"),
+ sample.LegacyModule(taggedModuleV3, "v3.0.0", "bar"),
+ sample.LegacyModule(taggedModuleV2, "v2.0.1", "bar"),
+ sample.LegacyModule(taggedAndPseudoModule, "v1.5.3-pre1", "bar"),
+ sample.LegacyModule(taggedAndPseudoModule, "v1.5.2", "bar"),
+ sample.LegacyModule(taggedAndPseudoModule, "v0.0.0-20200101120000-000000000000", "bar"),
+ sample.LegacyModule(otherModule, "v3.0.0", "thing"),
+ sample.LegacyModule(incompatibleModule, "v2.0.0+incompatible", "module"),
+ sample.LegacyModule(incompatibleModule, "v0.0.0", "module"),
+ sample.LegacyModule(rootModule, "v1.0.3", "api"),
+ sample.LegacyModule(rootModule, "v0.11.6", "api"),
+ sample.LegacyModule(nestedModule, "v1.0.4", "api"),
+ sample.LegacyModule(nestedModule, "v1.0.3", "api"),
}
)
// Add 12 pseudo versions to the test modules. Below we only
// expect to return the 10 most recent.
for i := 1; i <= 12; i++ {
- testModules = append(testModules, sample.Module(pseudoModule, fmt.Sprintf("v0.0.0-202001011200%02d-000000000000", i), "blog"))
+ testModules = append(testModules, sample.LegacyModule(pseudoModule, fmt.Sprintf("v0.0.0-202001011200%02d-000000000000", i), "blog"))
}
defer ResetTestDB(testDB, t)
@@ -241,7 +241,7 @@
"foo.com/bar/v3",
"bar.com/foo",
} {
- m := sample.Module(modulePath, sample.VersionString, sample.Suffix)
+ m := sample.LegacyModule(modulePath, sample.VersionString, sample.Suffix)
if err := testDB.InsertModule(ctx, m); err != nil {
t.Fatal(err)
}
diff --git a/internal/postgres/versionstate_test.go b/internal/postgres/versionstate_test.go
index 4d5be4b..76d9773 100644
--- a/internal/postgres/versionstate_test.go
+++ b/internal/postgres/versionstate_test.go
@@ -147,7 +147,7 @@
ctx, cancel := context.WithTimeout(context.Background(), testTimeout*2)
defer cancel()
- m := sample.DefaultModule()
+ m := sample.LegacyDefaultModule()
appVersion := time.Now().String()
for _, test := range []struct {
diff --git a/internal/testing/sample/legacy.go b/internal/testing/sample/legacy.go
index 6aa91d8..a04254a 100644
--- a/internal/testing/sample/legacy.go
+++ b/internal/testing/sample/legacy.go
@@ -12,7 +12,6 @@
"strings"
"golang.org/x/pkgsite/internal"
- "golang.org/x/pkgsite/internal/licenses"
"golang.org/x/pkgsite/internal/stdlib"
)
@@ -48,29 +47,29 @@
}
}
-func DefaultModule() *internal.Module {
- return AddPackage(
- Module(ModulePath, VersionString),
+func LegacyDefaultModule() *internal.Module {
+ return LegacyAddPackage(
+ LegacyModule(ModulePath, VersionString),
LegacyPackage(ModulePath, Suffix))
}
-// Module creates a Module with the given path and version.
+// LegacyModule creates a Module with the given path and version.
// The list of suffixes is used to create LegacyPackages within the module.
-func Module(modulePath, version string, suffixes ...string) *internal.Module {
+func LegacyModule(modulePath, version string, suffixes ...string) *internal.Module {
mi := LegacyModuleInfo(modulePath, version)
m := &internal.Module{
LegacyModuleInfo: *mi,
LegacyPackages: nil,
Licenses: Licenses,
}
- m.Units = []*internal.Unit{UnitForModuleRoot(mi, LicenseMetadata)}
+ m.Units = []*internal.Unit{legacyUnitForModuleRoot(mi)}
for _, s := range suffixes {
lp := LegacyPackage(modulePath, s)
if s != "" {
- AddPackage(m, lp)
+ LegacyAddPackage(m, lp)
} else {
m.LegacyPackages = append(m.LegacyPackages, lp)
- u := UnitForPackage(lp, modulePath, version)
+ u := legacyUnitForPackage(lp, modulePath, version)
m.Units[0].Documentation = u.Documentation
m.Units[0].Name = u.Name
}
@@ -78,13 +77,13 @@
return m
}
-func AddPackage(m *internal.Module, p *internal.LegacyPackage) *internal.Module {
+func LegacyAddPackage(m *internal.Module, p *internal.LegacyPackage) *internal.Module {
if m.ModulePath != stdlib.ModulePath && !strings.HasPrefix(p.Path, m.ModulePath) {
panic(fmt.Sprintf("package path %q not a prefix of module path %q",
p.Path, m.ModulePath))
}
m.LegacyPackages = append(m.LegacyPackages, p)
- AddUnit(m, UnitForPackage(p, m.ModulePath, m.Version))
+ AddUnit(m, legacyUnitForPackage(p, m.ModulePath, m.Version))
minLen := len(m.ModulePath)
if m.ModulePath == stdlib.ModulePath {
minLen = 1
@@ -104,7 +103,7 @@
return m
}
-func UnitForModuleRoot(m *internal.LegacyModuleInfo, licenses []*licenses.Metadata) *internal.Unit {
+func legacyUnitForModuleRoot(m *internal.LegacyModuleInfo) *internal.Unit {
u := &internal.Unit{
UnitMeta: *UnitMeta(m.ModulePath, m.ModulePath, m.Version, "", m.IsRedistributable),
LicenseContents: Licenses,
@@ -118,7 +117,7 @@
return u
}
-func UnitForPackage(pkg *internal.LegacyPackage, modulePath, version string) *internal.Unit {
+func legacyUnitForPackage(pkg *internal.LegacyPackage, modulePath, version string) *internal.Unit {
return &internal.Unit{
UnitMeta: *UnitMeta(pkg.Path, modulePath, version, pkg.Name, pkg.IsRedistributable),
Imports: pkg.Imports,
diff --git a/internal/worker/completion_test.go b/internal/worker/completion_test.go
index 11489b6..6eaa4c0 100644
--- a/internal/worker/completion_test.go
+++ b/internal/worker/completion_test.go
@@ -29,8 +29,8 @@
// package in v2 imports the package in v1. By setting our 'popular cutoff'
// to 1, we can force the package in v1 to be considered popular.
rc := redis.NewClient(&redis.Options{Addr: mr.Addr()})
- m1 := sample.Module("github.com/something", sample.VersionString, "apples/bananas")
- m2 := sample.Module("github.com/something/else", sample.VersionString, "oranges/bananas")
+ m1 := sample.LegacyModule("github.com/something", sample.VersionString, "apples/bananas")
+ m2 := sample.LegacyModule("github.com/something/else", sample.VersionString, "oranges/bananas")
m2.Units[1].Imports = []string{m1.Units[1].Path}
if err := testDB.InsertModule(ctx, m1); err != nil {
t.Fatal(err)