internal: prefix legacy structs with Legacy

The following structs have been renamed with a Legacy prefix:

* internal.Directory
* internal.Package
* internal.VersionedPackage
* sample.Package

The following fields on internal.ModuleInfo have also been changed:

* ReadmeFilePath
* ReadmeFileContents

This is done to help us distinguish between legacy and method
structs/methods while migrating code to the new data model.

Change-Id: Ibedf71d4db6323ef5aa05d73a0240537ea6073d3
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/765160
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
This commit is contained in:
Julie Qiu 2020-06-08 11:28:48 -04:00 коммит произвёл Julie Qiu
Родитель 3914aa0bd4
Коммит d667981893
39 изменённых файлов: 472 добавлений и 465 удалений

Просмотреть файл

@ -58,18 +58,18 @@ type DataSource interface {
// nested) subdirectory of the given directory path. When multiple
// package paths satisfy this query, it should prefer the module with
// the longest path.
GetDirectory(ctx context.Context, dirPath, modulePath, version string, fields FieldSet) (_ *Directory, err error)
GetDirectory(ctx context.Context, dirPath, modulePath, version string, fields FieldSet) (_ *LegacyDirectory, err error)
// GetModuleLicenses returns all top-level Licenses for the given modulePath
// and version. (i.e., Licenses contained in the module root directory)
GetModuleLicenses(ctx context.Context, modulePath, version string) ([]*licenses.License, error)
// GetPackage returns the VersionedPackage corresponding to the given package
// GetPackage returns the LegacyVersionedPackage corresponding to the given package
// pkgPath, modulePath, and version. When multiple package paths satisfy this query, it
// should prefer the module with the longest path.
GetPackage(ctx context.Context, pkgPath, modulePath, version string) (*VersionedPackage, error)
GetPackage(ctx context.Context, pkgPath, modulePath, version string) (*LegacyVersionedPackage, error)
// GetPackageLicenses returns all Licenses that apply to pkgPath, within the
// module version specified by modulePath and version.
GetPackageLicenses(ctx context.Context, pkgPath, modulePath, version string) ([]*licenses.License, error)
// GetPackagesInModule returns Packages contained in the module version
// GetPackagesInModule returns LegacyPackages contained in the module version
// specified by modulePath and version.
GetPackagesInModule(ctx context.Context, modulePath, version string) ([]*Package, error)
GetPackagesInModule(ctx context.Context, modulePath, version string) ([]*LegacyPackage, error)
}

Просмотреть файл

@ -32,15 +32,15 @@ const (
// ModuleInfo holds metadata associated with a module.
type ModuleInfo struct {
ModulePath string
Version string
CommitTime time.Time
ReadmeFilePath string
ReadmeContents string
VersionType version.Type
IsRedistributable bool
HasGoMod bool // whether the module zip has a go.mod file
SourceInfo *source.Info
ModulePath string
Version string
CommitTime time.Time
VersionType version.Type
IsRedistributable bool
HasGoMod bool // whether the module zip has a go.mod file
SourceInfo *source.Info
LegacyReadmeFilePath string
LegacyReadmeContents string
}
// VersionMap holds metadata associated with module queries for a version.
@ -65,7 +65,8 @@ type VersionMap struct {
//
// Examples:
// The module paths "a/b" and "a/b/v2" both have series path "a/b".
// The module paths "gopkg.in/yaml.v1" and "gopkg.in/yaml.v2" both have series path "gopkg.in/yaml".
// The module paths "gopkg.in/yaml.v1" and "gopkg.in/yaml.v2" both have series
// path "gopkg.in/yaml".
func (v *ModuleInfo) SeriesPath() string {
return SeriesPathForModule(v.ModulePath)
}
@ -89,45 +90,12 @@ func V1Path(modulePath, suffix string) string {
// A Module is a specific, reproducible build of a module.
type Module struct {
ModuleInfo
Packages []*Package
// Licenses holds all licenses within this module version, including those
// that may be contained in nested subdirectories.
Licenses []*licenses.License
Licenses []*licenses.License
Directories []*DirectoryNew
}
// A Package is a group of one or more Go source files with the same package
// header. Packages are part of a module.
type Package struct {
Path string
Name string
Synopsis string
IsRedistributable bool
Licenses []*licenses.Metadata // metadata of applicable version licenses
Imports []string
DocumentationHTML string
// The values of the GOOS and GOARCH environment variables used to parse the package.
GOOS string
GOARCH string
// V1Path is the package path of a package with major version 1 in a given series.
V1Path string
}
// VersionedPackage is a Package along with its corresponding module
// information.
type VersionedPackage struct {
Package
ModuleInfo
}
// Directory represents a folder in a module version, and all of the packages
// inside that folder.
type Directory struct {
ModuleInfo
Path string
Packages []*Package
LegacyPackages []*LegacyPackage
}
// VersionedDirectory is a DirectoryNew along with its corresponding module
@ -138,19 +106,20 @@ type VersionedDirectory struct {
}
// DirectoryNew is a folder in a module version, and all of the packages
// inside that folder. It will replace Directory once everything has been migrated.
// inside that folder. It will replace LegacyDirectory once everything has been
// migrated.
type DirectoryNew struct {
Path string
V1Path string
IsRedistributable bool
Licenses []*licenses.Metadata // metadata of applicable version licenses
Licenses []*licenses.Metadata // metadata of applicable licenses
Readme *Readme
Package *PackageNew
}
// PackageNew is a group of one or more Go source files with the same package
// header. A PackageNew is part of a directory.
// It will replace Package once everything has been migrated.
// It will replace LegacyPackage once everything has been migrated.
type PackageNew struct {
Name string
Path string
@ -161,7 +130,8 @@ type PackageNew struct {
// Documentation is the rendered documentation for a given package
// for a specific GOOS and GOARCH.
type Documentation struct {
// The values of the GOOS and GOARCH environment variables used to parse the package.
// The values of the GOOS and GOARCH environment variables used to parse the
// package.
GOOS string
GOARCH string
Synopsis string
@ -248,10 +218,11 @@ type SearchResult struct {
// Score is used to sort items in an array of SearchResult.
Score float64
// NumImportedBy is the number of packages that import Package.
// NumImportedBy is the number of packages that import PackagePath.
NumImportedBy uint64
// NumResults is the total number of packages that were returned for this search.
// NumResults is the total number of packages that were returned for this
// search.
NumResults uint64
// Approximate reports whether NumResults is an approximate count. NumResults
// can be approximate if search scanned only a subset of documents, and
@ -267,10 +238,11 @@ type SearchResult struct {
// every field.
//
// FieldSet bits are unique across the entire project, because some types are
// concatenations (via embedding) of others. For example, a VersionedPackage
// contains the fields of both a ModuleInfo and a Package, so we can't use the
// same bits for both ModuleInfo's ReadmeContents field and Package's
// DocumentationHTML field.
// concatenations (via embedding) of others. For example, a
// LegacyVersionedPackage contains the fields of both a ModuleInfo and a
// LegacyPackage, so we can't use the
// same bits for both ModuleInfo's LegacyReadmeContents field and
// LegacyPackage's DocumentationHTML field.
type FieldSet int64
// MinimalFields is the empty FieldSet.
@ -289,3 +261,38 @@ const (
WithReadmeContents FieldSet = 1 << iota
WithDocumentationHTML
)
// LegacyDirectory represents a folder in a module version, and all of the
// packages inside that folder.
type LegacyDirectory struct {
ModuleInfo
Path string
Packages []*LegacyPackage
}
// A LegacyPackage is a group of one or more Go source files with the same
// package header. LegacyPackages are part of a module.
type LegacyPackage struct {
Path string
Name string
Synopsis string
IsRedistributable bool
Licenses []*licenses.Metadata // metadata of applicable licenses
Imports []string
DocumentationHTML string
// The values of the GOOS and GOARCH environment variables used to parse the
// package.
GOOS string
GOARCH string
// V1Path is the package path of a package with major version 1 in a given
// series.
V1Path string
}
// LegacyVersionedPackage is a LegacyPackage along with its corresponding module
// information.
type LegacyVersionedPackage struct {
LegacyPackage
ModuleInfo
}

Просмотреть файл

@ -16,11 +16,11 @@ import (
// moduleDirectories returns all of the directories in a given module, along
// with the contents for those directories.
func moduleDirectories(modulePath string,
pkgs []*internal.Package,
pkgs []*internal.LegacyPackage,
readmes []*internal.Readme,
d *licenses.Detector) []*internal.DirectoryNew {
pkgLookup := map[string]*internal.Package{}
pkgLookup := map[string]*internal.LegacyPackage{}
for _, pkg := range pkgs {
pkgLookup[pkg.Path] = pkg
}
@ -76,7 +76,7 @@ func moduleDirectories(modulePath string,
}
// directoryPaths returns the directory paths in a module.
func directoryPaths(modulePath string, packages []*internal.Package) []string {
func directoryPaths(modulePath string, packages []*internal.LegacyPackage) []string {
shouldContinue := func(p string) bool {
if modulePath == stdlib.ModulePath {
return p != "."

Просмотреть файл

@ -57,9 +57,9 @@ func TestDirectoryPaths(t *testing.T) {
},
} {
t.Run(test.name, func(t *testing.T) {
var packages []*internal.Package
var packages []*internal.LegacyPackage
for _, suffix := range test.packageSuffixes {
packages = append(packages, sample.Package(test.modulePath, suffix))
packages = append(packages, sample.LegacyPackage(test.modulePath, suffix))
}
got := directoryPaths(test.modulePath, packages)
sort.Strings(got)

Просмотреть файл

@ -188,19 +188,19 @@ func processZipFile(ctx context.Context, modulePath string, versionType version.
}
return &internal.Module{
ModuleInfo: internal.ModuleInfo{
ModulePath: modulePath,
Version: resolvedVersion,
CommitTime: commitTime,
ReadmeFilePath: readmeFilePath,
ReadmeContents: readmeContents,
VersionType: versionType,
IsRedistributable: d.ModuleIsRedistributable(),
HasGoMod: hasGoMod,
SourceInfo: sourceInfo,
ModulePath: modulePath,
Version: resolvedVersion,
CommitTime: commitTime,
LegacyReadmeFilePath: readmeFilePath,
LegacyReadmeContents: readmeContents,
VersionType: versionType,
IsRedistributable: d.ModuleIsRedistributable(),
HasGoMod: hasGoMod,
SourceInfo: sourceInfo,
},
Packages: packages,
Licenses: allLicenses,
Directories: moduleDirectories(modulePath, packages, readmes, d),
LegacyPackages: packages,
Licenses: allLicenses,
Directories: moduleDirectories(modulePath, packages, readmes, d),
}, packageVersionStates, nil
}
@ -256,7 +256,7 @@ func isReadme(file string) bool {
// * a maximum file size (MaxFileSize)
// * the particular set of build contexts we consider (goEnvs)
// * whether the import path is valid.
func extractPackagesFromZip(ctx context.Context, modulePath, resolvedVersion string, r *zip.Reader, d *licenses.Detector, sourceInfo *source.Info) (_ []*internal.Package, _ []*internal.PackageVersionState, err error) {
func extractPackagesFromZip(ctx context.Context, modulePath, resolvedVersion string, r *zip.Reader, d *licenses.Detector, sourceInfo *source.Info) (_ []*internal.LegacyPackage, _ []*internal.PackageVersionState, err error) {
ctx, span := trace.StartSpan(ctx, "fetch.extractPackagesFromZip")
defer span.End()
defer func() {
@ -369,7 +369,7 @@ func extractPackagesFromZip(ctx context.Context, modulePath, resolvedVersion str
// If we got this far, the file metadata was okay.
// Start reading the file contents now to extract information
// about Go packages.
var pkgs []*internal.Package
var pkgs []*internal.LegacyPackage
for innerPath, goFiles := range dirs {
if incompleteDirs[innerPath] {
// Something went wrong when processing this directory, so we skip.
@ -438,7 +438,7 @@ func extractPackagesFromZip(ctx context.Context, modulePath, resolvedVersion str
// The logic of the go tool for ignoring directories is documented at
// https://golang.org/cmd/go/#hdr-Package_lists_and_patterns:
//
// Directory and file names that begin with "." or "_" are ignored
// LegacyDirectory and file names that begin with "." or "_" are ignored
// by the go tool, as are directories named "testdata".
//
func ignoredByGoTool(importPath string) bool {
@ -502,7 +502,7 @@ var goEnvs = []struct{ GOOS, GOARCH string }{
// several build contexts in turn. The first build context in the list to produce
// a non-empty package is used. If none of them result in a package, then
// loadPackage returns nil, nil.
func loadPackage(ctx context.Context, zipGoFiles []*zip.File, innerPath, modulePath string, sourceInfo *source.Info) (*internal.Package, error) {
func loadPackage(ctx context.Context, zipGoFiles []*zip.File, innerPath, modulePath string, sourceInfo *source.Info) (*internal.LegacyPackage, error) {
ctx, span := trace.StartSpan(ctx, "fetch.loadPackage")
defer span.End()
for _, env := range goEnvs {
@ -529,15 +529,15 @@ var httpPost = http.Post
// zipGoFiles must contain only .go files that have been verified
// to be of reasonable size.
//
// The returned Package.Licenses field is not populated.
// The returned LegacyPackage.Licenses field is not populated.
//
// It returns a nil Package if the directory doesn't contain a Go package
// It returns a nil LegacyPackage if the directory doesn't contain a Go package
// or all .go files have been excluded by constraints.
// A *LargePackageError error is returned if the rendered
// package documentation HTML exceeds a limit.
// A *BadPackageError error is returned if the directory
// contains .go files but do not make up a valid package.
func loadPackageWithBuildContext(ctx context.Context, goos, goarch string, zipGoFiles []*zip.File, innerPath, modulePath string, sourceInfo *source.Info) (_ *internal.Package, err error) {
func loadPackageWithBuildContext(ctx context.Context, goos, goarch string, zipGoFiles []*zip.File, innerPath, modulePath string, sourceInfo *source.Info) (_ *internal.LegacyPackage, err error) {
defer derrors.Wrap(&err, "loadPackageWithBuildContext(%q, %q, zipGoFiles, %q, %q, %+v)",
goos, goarch, innerPath, modulePath, sourceInfo)
// Apply build constraints to get a map from matching file names to their contents.
@ -674,7 +674,7 @@ func loadPackageWithBuildContext(ctx context.Context, goos, goarch string, zipGo
if modulePath == stdlib.ModulePath {
importPath = innerPath
}
return &internal.Package{
return &internal.LegacyPackage{
Path: importPath,
Name: packageName,
Synopsis: doc.Synopsis(d.Doc),

Просмотреть файл

@ -96,7 +96,7 @@ func TestFetchModule(t *testing.T) {
sortFetchResult(fr)
sortFetchResult(got)
opts := []cmp.Option{
cmpopts.IgnoreFields(internal.Package{}, "DocumentationHTML"),
cmpopts.IgnoreFields(internal.LegacyPackage{}, "DocumentationHTML"),
cmpopts.IgnoreFields(internal.Documentation{}, "HTML"),
cmpopts.IgnoreFields(internal.PackageVersionState{}, "Error"),
cmp.AllowUnexported(source.Info{}),

Просмотреть файл

@ -32,10 +32,10 @@ var moduleOnePackage = &testModule{
fr: &FetchResult{
Module: &internal.Module{
ModuleInfo: internal.ModuleInfo{
ModulePath: "github.com/basic",
ReadmeFilePath: "README.md",
ReadmeContents: "THIS IS A README",
HasGoMod: false,
ModulePath: "github.com/basic",
LegacyReadmeFilePath: "README.md",
LegacyReadmeContents: "THIS IS A README",
HasGoMod: false,
},
Directories: []*internal.DirectoryNew{
{
@ -99,11 +99,11 @@ var moduleMultiPackage = &testModule{
fr: &FetchResult{
Module: &internal.Module{
ModuleInfo: internal.ModuleInfo{
ModulePath: "github.com/my/module",
HasGoMod: true,
ReadmeFilePath: "README.md",
ReadmeContents: "README FILE FOR TESTING.",
SourceInfo: source.NewGitHubInfo("https://github.com/my/module", "", "v1.0.0"),
ModulePath: "github.com/my/module",
HasGoMod: true,
LegacyReadmeFilePath: "README.md",
LegacyReadmeContents: "README FILE FOR TESTING.",
SourceInfo: source.NewGitHubInfo("https://github.com/my/module", "", "v1.0.0"),
},
Directories: []*internal.DirectoryNew{
{
@ -372,10 +372,10 @@ var moduleNonRedist = &testModule{
fr: &FetchResult{
Module: &internal.Module{
ModuleInfo: internal.ModuleInfo{
ModulePath: "nonredistributable.mod/module",
ReadmeFilePath: "README.md",
ReadmeContents: "README FILE FOR TESTING.",
HasGoMod: true,
ModulePath: "nonredistributable.mod/module",
LegacyReadmeFilePath: "README.md",
LegacyReadmeContents: "README FILE FOR TESTING.",
HasGoMod: true,
},
Directories: []*internal.DirectoryNew{
{
@ -548,10 +548,10 @@ var moduleWasm = &testModule{
fr: &FetchResult{
Module: &internal.Module{
ModuleInfo: internal.ModuleInfo{
ModulePath: "github.com/my/module/js",
ReadmeFilePath: "README.md",
ReadmeContents: "THIS IS A README",
SourceInfo: source.NewGitHubInfo("https://github.com/my/module", "js", "js/v1.0.0"),
ModulePath: "github.com/my/module/js",
LegacyReadmeFilePath: "README.md",
LegacyReadmeContents: "THIS IS A README",
SourceInfo: source.NewGitHubInfo("https://github.com/my/module", "js", "js/v1.0.0"),
},
Directories: []*internal.DirectoryNew{
{
@ -598,13 +598,13 @@ var moduleStd = &testModule{
fr: &FetchResult{
Module: &internal.Module{
ModuleInfo: internal.ModuleInfo{
ModulePath: "std",
Version: "v1.12.5",
CommitTime: stdlib.TestCommitTime,
ReadmeFilePath: "README.md",
ReadmeContents: "# The Go Programming Language\n",
HasGoMod: true,
SourceInfo: source.NewGitHubInfo("https://github.com/golang/go", "src", "go1.12.5"),
ModulePath: "std",
Version: "v1.12.5",
CommitTime: stdlib.TestCommitTime,
LegacyReadmeFilePath: "README.md",
LegacyReadmeContents: "# The Go Programming Language\n",
HasGoMod: true,
SourceInfo: source.NewGitHubInfo("https://github.com/golang/go", "src", "go1.12.5"),
},
Directories: []*internal.DirectoryNew{
{

Просмотреть файл

@ -66,7 +66,7 @@ func cleanFetchResult(fr *FetchResult, detector *licenses.Detector) *FetchResult
dir.Package.Documentation.GOARCH = "amd64"
}
dir.Package.Path = dir.Path
fr.Module.Packages = append(fr.Module.Packages, &internal.Package{
fr.Module.LegacyPackages = append(fr.Module.LegacyPackages, &internal.LegacyPackage{
Path: dir.Path,
V1Path: dir.V1Path,
Licenses: dir.Licenses,
@ -117,8 +117,8 @@ func licenseDetector(ctx context.Context, t *testing.T, modulePath, version stri
}
func sortFetchResult(fr *FetchResult) {
sort.Slice(fr.Module.Packages, func(i, j int) bool {
return fr.Module.Packages[i].Path < fr.Module.Packages[j].Path
sort.Slice(fr.Module.LegacyPackages, func(i, j int) bool {
return fr.Module.LegacyPackages[i].Path < fr.Module.LegacyPackages[j].Path
})
sort.Slice(fr.Module.Directories, func(i, j int) bool {
return fr.Module.Directories[i].Path < fr.Module.Directories[j].Path
@ -134,7 +134,7 @@ func sortFetchResult(fr *FetchResult) {
return dir.Licenses[i].FilePath < dir.Licenses[j].FilePath
})
}
for _, pkg := range fr.Module.Packages {
for _, pkg := range fr.Module.LegacyPackages {
sort.Slice(pkg.Licenses, func(i, j int) bool {
return pkg.Licenses[i].FilePath < pkg.Licenses[j].FilePath
})
@ -148,11 +148,11 @@ func validateDocumentationHTML(t *testing.T, got, want *internal.Module) {
t.Fatalf("Recovered in checkDocumentationHTML: %v \n; diff = %s", r, cmp.Diff(want, got))
}
}()
for i := 0; i < len(want.Packages); i++ {
wantHTML := want.Packages[i].DocumentationHTML
gotHTML := got.Packages[i].DocumentationHTML
for i := 0; i < len(want.LegacyPackages); i++ {
wantHTML := want.LegacyPackages[i].DocumentationHTML
gotHTML := got.LegacyPackages[i].DocumentationHTML
if len(wantHTML) != 0 && !strings.Contains(gotHTML, wantHTML) {
t.Errorf("documentation for got.Module.Packages[%d].DocumentationHTML does not contain wanted documentation substring:\n want (substring): %q\n got: %q\n", i, wantHTML, gotHTML)
t.Errorf("documentation for got.Module.LegacyPackages[%d].DocumentationHTML does not contain wanted documentation substring:\n want (substring): %q\n got: %q\n", i, wantHTML, gotHTML)
}
}
for i := 0; i < len(want.Directories); i++ {

Просмотреть файл

@ -26,7 +26,7 @@ type DirectoryPage struct {
BreadcrumbPath template.HTML
}
// Directory contains information for an individual directory.
// LegacyDirectory contains information for an individual directory.
type Directory struct {
Module
Path string
@ -34,7 +34,7 @@ type Directory struct {
URL string
}
func (s *Server) serveDirectoryPage(ctx context.Context, w http.ResponseWriter, r *http.Request, dbDir *internal.Directory, requestedVersion string) (err error) {
func (s *Server) serveDirectoryPage(ctx context.Context, w http.ResponseWriter, r *http.Request, dbDir *internal.LegacyDirectory, requestedVersion string) (err error) {
defer derrors.Wrap(&err, "serveDirectoryPage for %s@%s", dbDir.Path, requestedVersion)
tab := r.FormValue("tab")
settings, ok := directoryTabLookup[tab]
@ -74,7 +74,7 @@ func (s *Server) serveDirectoryPage(ctx context.Context, w http.ResponseWriter,
}
// fetchDirectoryDetails fetches data for the directory specified by path and
// version from the database and returns a Directory.
// version from the database and returns a LegacyDirectory.
//
// includeDirPath indicates whether a package is included if its import path is
// the same as dirPath.
@ -96,7 +96,7 @@ func fetchDirectoryDetails(ctx context.Context, ds internal.DataSource, dirPath
if err != nil {
return nil, err
}
return createDirectory(&internal.Directory{
return createDirectory(&internal.LegacyDirectory{
ModuleInfo: *mi,
Path: dirPath,
Packages: pkgs,
@ -105,7 +105,7 @@ func fetchDirectoryDetails(ctx context.Context, ds internal.DataSource, dirPath
dbDir, err := ds.GetDirectory(ctx, dirPath, mi.ModulePath, mi.Version, internal.AllFields)
if errors.Is(err, derrors.NotFound) {
return createDirectory(&internal.Directory{
return createDirectory(&internal.LegacyDirectory{
ModuleInfo: *mi,
Path: dirPath,
Packages: nil,
@ -117,7 +117,7 @@ func fetchDirectoryDetails(ctx context.Context, ds internal.DataSource, dirPath
return createDirectory(dbDir, licmetas, includeDirPath)
}
// createDirectory constructs a *Directory from the provided dbDir and licmetas.
// createDirectory constructs a *LegacyDirectory from the provided dbDir and licmetas.
//
// includeDirPath indicates whether a package is included if its import path is
// the same as dirPath.
@ -126,7 +126,7 @@ func fetchDirectoryDetails(ctx context.Context, ds internal.DataSource, dirPath
// the module path. However, on the package and directory view's
// "Subdirectories" tab, we do not want to include packages whose import paths
// are the same as the dirPath.
func createDirectory(dbDir *internal.Directory, licmetas []*licenses.Metadata, includeDirPath bool) (_ *Directory, err error) {
func createDirectory(dbDir *internal.LegacyDirectory, licmetas []*licenses.Metadata, includeDirPath bool) (_ *Directory, err error) {
defer derrors.Wrap(&err, "createDirectory(%q, %q, %t)", dbDir.Path, dbDir.Version, includeDirPath)
var packages []*Package

Просмотреть файл

@ -32,7 +32,7 @@ func TestFetchDirectoryDetails(t *testing.T) {
mi := sample.ModuleInfo(modulePath, version)
var wantPkgs []*Package
for _, suffix := range suffixes {
sp := sample.Package(modulePath, suffix)
sp := sample.LegacyPackage(modulePath, suffix)
pkg, err := createPackage(sp, mi, false)
if err != nil {
t.Fatal(err)

Просмотреть файл

@ -28,7 +28,7 @@ type DocumentationDetails struct {
var addDocQueryParam = true
// fetchDocumentationDetails returns a DocumentationDetails constructed from pkg.
func fetchDocumentationDetails(pkg *internal.VersionedPackage) *DocumentationDetails {
func fetchDocumentationDetails(pkg *internal.LegacyVersionedPackage) *DocumentationDetails {
docHTML := pkg.DocumentationHTML
if addDocQueryParam {
docHTML = hackUpDocumentation(docHTML)

Просмотреть файл

@ -49,7 +49,7 @@ type Module struct {
// latestRequested indicates whether the user requested the latest
// version of the package. If so, the returned Package.URL will have the
// structure /<path> instead of /<path>@<version>.
func createPackage(pkg *internal.Package, mi *internal.ModuleInfo, latestRequested bool) (_ *Package, err error) {
func createPackage(pkg *internal.LegacyPackage, mi *internal.ModuleInfo, latestRequested bool) (_ *Package, err error) {
defer derrors.Wrap(&err, "createPackage(%v, %v)", pkg, mi)
if pkg == nil || mi == nil {
@ -161,7 +161,7 @@ func constructPackageURL(pkgPath, modulePath, linkVersion string) string {
}
// effectiveName returns either the command name or package name.
func effectiveName(pkg *internal.Package) string {
func effectiveName(pkg *internal.LegacyPackage) string {
if pkg.Name != "main" {
return pkg.Name
}
@ -193,7 +193,7 @@ func effectiveNameNew(pkg *internal.PackageNew) string {
// packageHTMLTitle constructs the details page title for pkg.
// The string will appear in the <title> element (and thus
// the browser tab).
func packageHTMLTitle(pkg *internal.Package) string {
func packageHTMLTitle(pkg *internal.LegacyPackage) string {
if pkg.Name != "main" {
return pkg.Name + " package"
}
@ -212,7 +212,7 @@ func packageHTMLTitleNew(pkg *internal.PackageNew) string {
// packageTitle returns the package title as it will
// appear in the heading at the top of the page.
func packageTitle(pkg *internal.Package) string {
func packageTitle(pkg *internal.LegacyPackage) string {
if pkg.Name != "main" {
return "package " + pkg.Name
}

Просмотреть файл

@ -94,20 +94,20 @@ func TestElapsedTime(t *testing.T) {
}
func TestCreatePackageHeader(t *testing.T) {
vpkg := func(modulePath, suffix, name string) *internal.VersionedPackage {
vp := &internal.VersionedPackage{
ModuleInfo: *sample.ModuleInfo(modulePath, sample.VersionString),
Package: *sample.Package(modulePath, suffix),
vpkg := func(modulePath, suffix, name string) *internal.LegacyVersionedPackage {
vp := &internal.LegacyVersionedPackage{
ModuleInfo: *sample.ModuleInfo(modulePath, sample.VersionString),
LegacyPackage: *sample.LegacyPackage(modulePath, suffix),
}
if name != "" {
vp.Package.Name = name
vp.LegacyPackage.Name = name
}
return vp
}
for _, tc := range []struct {
label string
pkg *internal.VersionedPackage
pkg *internal.LegacyVersionedPackage
wantPkg *Package
}{
{
@ -138,7 +138,7 @@ func TestCreatePackageHeader(t *testing.T) {
},
} {
t.Run(tc.label, func(t *testing.T) {
got, err := createPackage(&tc.pkg.Package, &tc.pkg.ModuleInfo, false)
got, err := createPackage(&tc.pkg.LegacyPackage, &tc.pkg.ModuleInfo, false)
if err != nil {
t.Fatal(err)
}

Просмотреть файл

@ -50,7 +50,7 @@ func TestFetchImportsDetails(t *testing.T) {
defer cancel()
module := sample.Module(sample.ModulePath, sample.VersionString, sample.Suffix)
module.Packages[0].Imports = tc.imports
module.LegacyPackages[0].Imports = tc.imports
if err := testDB.InsertModule(ctx, module); err != nil {
t.Fatal(err)
@ -60,24 +60,24 @@ func TestFetchImportsDetails(t *testing.T) {
got, err := fetchImportsDetails(ctx, testDB, pkg.Path, pkg.ModulePath, pkg.Version)
if err != nil {
t.Fatalf("fetchImportsDetails(ctx, db, %q, %q) = %v err = %v, want %v",
module.Packages[0].Path, module.Version, got, err, tc.wantDetails)
module.LegacyPackages[0].Path, module.Version, got, err, tc.wantDetails)
}
tc.wantDetails.ModulePath = module.ModuleInfo.ModulePath
if diff := cmp.Diff(tc.wantDetails, got); diff != "" {
t.Errorf("fetchImportsDetails(ctx, %q, %q) mismatch (-want +got):\n%s", module.Packages[0].Path, module.Version, diff)
t.Errorf("fetchImportsDetails(ctx, %q, %q) mismatch (-want +got):\n%s", module.LegacyPackages[0].Path, module.Version, diff)
}
})
}
}
// firstVersionedPackage is a helper function that returns an
// *internal.VersionedPackage corresponding to the first package in the
// *internal.LegacyVersionedPackage corresponding to the first package in the
// version.
func firstVersionedPackage(m *internal.Module) *internal.VersionedPackage {
return &internal.VersionedPackage{
Package: *m.Packages[0],
ModuleInfo: m.ModuleInfo,
func firstVersionedPackage(m *internal.Module) *internal.LegacyVersionedPackage {
return &internal.LegacyVersionedPackage{
LegacyPackage: *m.LegacyPackages[0],
ModuleInfo: m.ModuleInfo,
}
}
@ -87,7 +87,7 @@ func TestFetchImportedByDetails(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
defer cancel()
newModule := func(modPath string, pkgs ...*internal.Package) *internal.Module {
newModule := func(modPath string, pkgs ...*internal.LegacyPackage) *internal.Module {
m := sample.Module(modPath, sample.VersionString)
for _, p := range pkgs {
sample.AddPackage(m, p)
@ -95,11 +95,11 @@ func TestFetchImportedByDetails(t *testing.T) {
return m
}
pkg1 := sample.Package("path.to/foo", "bar")
pkg2 := sample.Package("path2.to/foo", "bar2")
pkg1 := sample.LegacyPackage("path.to/foo", "bar")
pkg2 := sample.LegacyPackage("path2.to/foo", "bar2")
pkg2.Imports = []string{pkg1.Path}
pkg3 := sample.Package("path3.to/foo", "bar3")
pkg3 := sample.LegacyPackage("path3.to/foo", "bar3")
pkg3.Imports = []string{pkg2.Path, pkg1.Path}
testModules := []*internal.Module{
@ -115,7 +115,7 @@ func TestFetchImportedByDetails(t *testing.T) {
}
for _, tc := range []struct {
pkg *internal.Package
pkg *internal.LegacyPackage
wantDetails *ImportedByDetails
}{
{

Просмотреть файл

@ -48,17 +48,17 @@ func constructOverviewDetails(mi *internal.ModuleInfo, isRedistributable bool, v
Redistributable: isRedistributable,
}
if overview.Redistributable {
overview.ReadMeSource = fileSource(mi.ModulePath, mi.Version, mi.ReadmeFilePath)
overview.ReadMeSource = fileSource(mi.ModulePath, mi.Version, mi.LegacyReadmeFilePath)
overview.ReadMe = readmeHTML(mi)
}
return overview
}
// fetchPackageOverviewDetails uses data for the given package to return an OverviewDetails.
func fetchPackageOverviewDetails(pkg *internal.VersionedPackage, versionedLinks bool) *OverviewDetails {
od := constructOverviewDetails(&pkg.ModuleInfo, pkg.Package.IsRedistributable, versionedLinks)
func fetchPackageOverviewDetails(pkg *internal.LegacyVersionedPackage, versionedLinks bool) *OverviewDetails {
od := constructOverviewDetails(&pkg.ModuleInfo, pkg.LegacyPackage.IsRedistributable, versionedLinks)
od.PackageSourceURL = pkg.SourceInfo.DirectoryURL(packageSubdir(pkg.Path, pkg.ModulePath))
if !pkg.Package.IsRedistributable {
if !pkg.LegacyPackage.IsRedistributable {
od.Redistributable = false
}
return od
@ -90,11 +90,11 @@ func packageSubdir(pkgPath, modulePath string) string {
// a template.HTML. If readmeFilePath indicates that this is a markdown file,
// it will also render the markdown contents using blackfriday.
func readmeHTML(mi *internal.ModuleInfo) template.HTML {
if len(mi.ReadmeContents) == 0 {
if len(mi.LegacyReadmeContents) == 0 {
return ""
}
if !isMarkdown(mi.ReadmeFilePath) {
return template.HTML(fmt.Sprintf(`<pre class="readme">%s</pre>`, html.EscapeString(string(mi.ReadmeContents))))
if !isMarkdown(mi.LegacyReadmeFilePath) {
return template.HTML(fmt.Sprintf(`<pre class="readme">%s</pre>`, html.EscapeString(string(mi.LegacyReadmeContents))))
}
// bluemonday.UGCPolicy allows a broad selection of HTML elements and
@ -114,7 +114,7 @@ func readmeHTML(mi *internal.ModuleInfo) template.HTML {
// Render HTML similar to blackfriday.Run(), but here we implement a custom
// Walk function in order to modify image paths in the rendered HTML.
b := &bytes.Buffer{}
rootNode := parser.Parse([]byte(mi.ReadmeContents))
rootNode := parser.Parse([]byte(mi.LegacyReadmeContents))
rootNode.Walk(func(node *blackfriday.Node, entering bool) blackfriday.WalkStatus {
if node.Type == blackfriday.Image || node.Type == blackfriday.Link {
translateRelativeLink(node, mi)
@ -149,7 +149,7 @@ func translateRelativeLink(node *blackfriday.Node, mi *internal.ModuleInfo) {
return
}
// Paths are relative to the README location.
destPath := path.Join(path.Dir(mi.ReadmeFilePath), path.Clean(destURL.Path))
destPath := path.Join(path.Dir(mi.LegacyReadmeFilePath), path.Clean(destURL.Path))
var newURL string
if node.Type == blackfriday.Image {
newURL = mi.SourceInfo.RawURL(destPath)

Просмотреть файл

@ -47,7 +47,7 @@ func TestFetchOverviewDetails(t *testing.T) {
got := constructOverviewDetails(&tc.module.ModuleInfo, true, true)
if diff := cmp.Diff(tc.wantDetails, got); diff != "" {
t.Errorf("constructOverviewDetails(%q, %q) mismatch (-want +got):\n%s", tc.module.Packages[0].Path, tc.module.Version, diff)
t.Errorf("constructOverviewDetails(%q, %q) mismatch (-want +got):\n%s", tc.module.LegacyPackages[0].Path, tc.module.Version, diff)
}
}
@ -135,8 +135,8 @@ func TestReadmeHTML(t *testing.T) {
{
name: "valid markdown readme",
mi: &internal.ModuleInfo{
ReadmeFilePath: "README.md",
ReadmeContents: "This package collects pithy sayings.\n\n" +
LegacyReadmeFilePath: "README.md",
LegacyReadmeContents: "This package collects pithy sayings.\n\n" +
"It's part of a demonstration of\n" +
"[package versioning in Go](https://research.swtch.com/vgo1).",
},
@ -147,8 +147,8 @@ func TestReadmeHTML(t *testing.T) {
{
name: "valid markdown readme with alternative case and extension",
mi: &internal.ModuleInfo{
ReadmeFilePath: "README.MARKDOWN",
ReadmeContents: "This package collects pithy sayings.\n\n" +
LegacyReadmeFilePath: "README.MARKDOWN",
LegacyReadmeContents: "This package collects pithy sayings.\n\n" +
"It's part of a demonstration of\n" +
"[package versioning in Go](https://research.swtch.com/vgo1).",
},
@ -159,8 +159,8 @@ func TestReadmeHTML(t *testing.T) {
{
name: "not markdown readme",
mi: &internal.ModuleInfo{
ReadmeFilePath: "README.rst",
ReadmeContents: "This package collects pithy sayings.\n\n" +
LegacyReadmeFilePath: "README.rst",
LegacyReadmeContents: "This package collects pithy sayings.\n\n" +
"It's part of a demonstration of\n" +
"[package versioning in Go](https://research.swtch.com/vgo1).",
},
@ -174,67 +174,67 @@ func TestReadmeHTML(t *testing.T) {
{
name: "sanitized readme",
mi: &internal.ModuleInfo{
ReadmeFilePath: "README",
ReadmeContents: `<a onblur="alert(secret)" href="http://www.google.com">Google</a>`,
LegacyReadmeFilePath: "README",
LegacyReadmeContents: `<a onblur="alert(secret)" href="http://www.google.com">Google</a>`,
},
want: template.HTML(`<pre class="readme">&lt;a onblur=&#34;alert(secret)&#34; href=&#34;http://www.google.com&#34;&gt;Google&lt;/a&gt;</pre>`),
},
{
name: "relative image markdown is made absolute for GitHub",
mi: &internal.ModuleInfo{
ReadmeFilePath: "README.md",
ReadmeContents: "![Go logo](doc/logo.png)",
SourceInfo: source.NewGitHubInfo("http://github.com/golang/go", "", "master"),
LegacyReadmeFilePath: "README.md",
LegacyReadmeContents: "![Go logo](doc/logo.png)",
SourceInfo: source.NewGitHubInfo("http://github.com/golang/go", "", "master"),
},
want: template.HTML("<p><img src=\"https://raw.githubusercontent.com/golang/go/master/doc/logo.png\" alt=\"Go logo\"/></p>\n"),
},
{
name: "relative image markdown is made absolute for GitLab",
mi: &internal.ModuleInfo{
ReadmeFilePath: "README.md",
ReadmeContents: "![Gitaly benchmark timings.](doc/img/rugged-new-timings.png)",
SourceInfo: source.NewGitLabInfo("http://gitlab.com/gitlab-org/gitaly", "", "v1.0.0"),
LegacyReadmeFilePath: "README.md",
LegacyReadmeContents: "![Gitaly benchmark timings.](doc/img/rugged-new-timings.png)",
SourceInfo: source.NewGitLabInfo("http://gitlab.com/gitlab-org/gitaly", "", "v1.0.0"),
},
want: template.HTML("<p><img src=\"http://gitlab.com/gitlab-org/gitaly/raw/v1.0.0/doc/img/rugged-new-timings.png\" alt=\"Gitaly benchmark timings.\"/></p>\n"),
},
{
name: "relative image markdown is left alone for unknown origins",
mi: &internal.ModuleInfo{
ReadmeFilePath: "README.md",
ReadmeContents: "![Go logo](doc/logo.png)",
LegacyReadmeFilePath: "README.md",
LegacyReadmeContents: "![Go logo](doc/logo.png)",
},
want: template.HTML("<p><img src=\"doc/logo.png\" alt=\"Go logo\"/></p>\n"),
},
{
name: "module versions are referenced in relative images",
mi: &internal.ModuleInfo{
ReadmeFilePath: "README.md",
ReadmeContents: "![Hugo logo](doc/logo.png)",
Version: "v0.56.3",
VersionType: version.TypeRelease,
SourceInfo: source.NewGitHubInfo("http://github.com/gohugoio/hugo", "", "v0.56.3"),
LegacyReadmeFilePath: "README.md",
LegacyReadmeContents: "![Hugo logo](doc/logo.png)",
Version: "v0.56.3",
VersionType: version.TypeRelease,
SourceInfo: source.NewGitHubInfo("http://github.com/gohugoio/hugo", "", "v0.56.3"),
},
want: template.HTML("<p><img src=\"https://raw.githubusercontent.com/gohugoio/hugo/v0.56.3/doc/logo.png\" alt=\"Hugo logo\"/></p>\n"),
},
{
name: "image URLs relative to README directory",
mi: &internal.ModuleInfo{
ReadmeFilePath: "dir/sub/README.md",
ReadmeContents: "![alt](img/thing.png)",
Version: "v1.2.3",
VersionType: version.TypeRelease,
SourceInfo: source.NewGitHubInfo("https://github.com/some/repo", "", "v1.2.3"),
LegacyReadmeFilePath: "dir/sub/README.md",
LegacyReadmeContents: "![alt](img/thing.png)",
Version: "v1.2.3",
VersionType: version.TypeRelease,
SourceInfo: source.NewGitHubInfo("https://github.com/some/repo", "", "v1.2.3"),
},
want: template.HTML(`<p><img src="https://raw.githubusercontent.com/some/repo/v1.2.3/dir/sub/img/thing.png" alt="alt"/></p>` + "\n"),
},
{
name: "non-image links relative to README directory",
mi: &internal.ModuleInfo{
ReadmeFilePath: "dir/sub/README.md",
ReadmeContents: "[something](doc/thing.md)",
Version: "v1.2.3",
VersionType: version.TypeRelease,
SourceInfo: source.NewGitHubInfo("https://github.com/some/repo", "", "v1.2.3"),
LegacyReadmeFilePath: "dir/sub/README.md",
LegacyReadmeContents: "[something](doc/thing.md)",
Version: "v1.2.3",
VersionType: version.TypeRelease,
SourceInfo: source.NewGitHubInfo("https://github.com/some/repo", "", "v1.2.3"),
},
want: template.HTML(`<p><a href="https://github.com/some/repo/blob/v1.2.3/dir/sub/doc/thing.md" rel="nofollow">something</a></p>` + "\n"),
},

Просмотреть файл

@ -100,13 +100,13 @@ func (s *Server) servePackagePage(w http.ResponseWriter, r *http.Request, pkgPat
return pathNotFoundError(ctx, "package", pkgPath, version)
}
func (s *Server) servePackagePageWithPackage(ctx context.Context, w http.ResponseWriter, r *http.Request, pkg *internal.VersionedPackage, requestedVersion string) (err error) {
func (s *Server) servePackagePageWithPackage(ctx context.Context, w http.ResponseWriter, r *http.Request, pkg *internal.LegacyVersionedPackage, requestedVersion string) (err error) {
defer func() {
if _, ok := err.(*serverError); !ok {
derrors.Wrap(&err, "servePackagePageWithPackage(w, r, %q, %q, %q)", pkg.Path, pkg.ModulePath, requestedVersion)
}
}()
pkgHeader, err := createPackage(&pkg.Package, &pkg.ModuleInfo, requestedVersion == internal.LatestVersion)
pkgHeader, err := createPackage(&pkg.LegacyPackage, &pkg.ModuleInfo, requestedVersion == internal.LatestVersion)
if err != nil {
return fmt.Errorf("creating package header for %s@%s: %v", pkg.Path, pkg.Version, err)
}
@ -115,7 +115,7 @@ func (s *Server) servePackagePageWithPackage(ctx context.Context, w http.Respons
settings, ok := packageTabLookup[tab]
if !ok {
var tab string
if pkg.Package.IsRedistributable {
if pkg.LegacyPackage.IsRedistributable {
tab = "doc"
} else {
tab = "overview"
@ -123,7 +123,7 @@ func (s *Server) servePackagePageWithPackage(ctx context.Context, w http.Respons
http.Redirect(w, r, fmt.Sprintf(r.URL.Path+"?tab=%s", tab), http.StatusFound)
return nil
}
canShowDetails := pkg.Package.IsRedistributable || settings.AlwaysShowDetails
canShowDetails := pkg.LegacyPackage.IsRedistributable || settings.AlwaysShowDetails
var details interface{}
if canShowDetails {
@ -134,8 +134,8 @@ func (s *Server) servePackagePageWithPackage(ctx context.Context, w http.Respons
}
}
page := &DetailsPage{
basePage: s.newBasePage(r, packageHTMLTitle(&pkg.Package)),
Title: packageTitle(&pkg.Package),
basePage: s.newBasePage(r, packageHTMLTitle(&pkg.LegacyPackage)),
Title: packageTitle(&pkg.LegacyPackage),
Settings: settings,
Header: pkgHeader,
BreadcrumbPath: breadcrumbPath(pkgHeader.Path, pkgHeader.Module.ModulePath,

Просмотреть файл

@ -25,14 +25,14 @@ func TestFetchSearchPage(t *testing.T) {
now = sample.NowTruncated()
moduleFoo = &internal.Module{
ModuleInfo: internal.ModuleInfo{
ModulePath: "github.com/mod/foo",
Version: "v1.0.0",
ReadmeContents: "readme",
CommitTime: now,
VersionType: version.TypeRelease,
IsRedistributable: true,
ModulePath: "github.com/mod/foo",
Version: "v1.0.0",
LegacyReadmeContents: "readme",
CommitTime: now,
VersionType: version.TypeRelease,
IsRedistributable: true,
},
Packages: []*internal.Package{
LegacyPackages: []*internal.LegacyPackage{
{
Name: "foo",
Path: "/path/to/foo",
@ -44,14 +44,14 @@ func TestFetchSearchPage(t *testing.T) {
}
moduleBar = &internal.Module{
ModuleInfo: internal.ModuleInfo{
ModulePath: "github.com/mod/bar",
Version: "v1.0.0",
ReadmeContents: "readme",
CommitTime: now,
VersionType: version.TypeRelease,
IsRedistributable: true,
ModulePath: "github.com/mod/bar",
Version: "v1.0.0",
LegacyReadmeContents: "readme",
CommitTime: now,
VersionType: version.TypeRelease,
IsRedistributable: true,
},
Packages: []*internal.Package{
LegacyPackages: []*internal.LegacyPackage{
{
Name: "bar",
Path: "/path/to/bar",
@ -84,10 +84,10 @@ func TestFetchSearchPage(t *testing.T) {
},
Results: []*SearchResult{
{
Name: moduleBar.Packages[0].Name,
PackagePath: moduleBar.Packages[0].Path,
Name: moduleBar.LegacyPackages[0].Name,
PackagePath: moduleBar.LegacyPackages[0].Path,
ModulePath: moduleBar.ModulePath,
Synopsis: moduleBar.Packages[0].Synopsis,
Synopsis: moduleBar.LegacyPackages[0].Synopsis,
DisplayVersion: moduleBar.Version,
Licenses: []string{"MIT"},
CommitTime: elapsedTime(moduleBar.CommitTime),
@ -112,10 +112,10 @@ func TestFetchSearchPage(t *testing.T) {
},
Results: []*SearchResult{
{
Name: moduleFoo.Packages[0].Name,
PackagePath: moduleFoo.Packages[0].Path,
Name: moduleFoo.LegacyPackages[0].Name,
PackagePath: moduleFoo.LegacyPackages[0].Path,
ModulePath: moduleFoo.ModulePath,
Synopsis: moduleFoo.Packages[0].Synopsis,
Synopsis: moduleFoo.LegacyPackages[0].Synopsis,
DisplayVersion: moduleFoo.Version,
Licenses: []string{"MIT"},
CommitTime: elapsedTime(moduleFoo.CommitTime),

Просмотреть файл

@ -125,9 +125,9 @@ var testModules = []testModule{
func insertTestModules(ctx context.Context, t *testing.T, mods []testModule) {
for _, mod := range mods {
var ps []*internal.Package
var ps []*internal.LegacyPackage
for _, pkg := range mod.packages {
p := sample.Package(mod.path, pkg.suffix)
p := sample.LegacyPackage(mod.path, pkg.suffix)
if pkg.name != "" {
p.Name = pkg.name
}

Просмотреть файл

@ -93,7 +93,7 @@ var (
{
Name: "packages",
AlwaysShowDetails: true,
DisplayName: "Packages",
DisplayName: "LegacyPackages",
TemplateName: "subdirectories.tmpl",
},
{
@ -141,7 +141,7 @@ func init() {
// fetchDetailsForPackage returns tab details by delegating to the correct detail
// handler.
func fetchDetailsForPackage(ctx context.Context, r *http.Request, tab string, ds internal.DataSource, pkg *internal.VersionedPackage) (interface{}, error) {
func fetchDetailsForPackage(ctx context.Context, r *http.Request, tab string, ds internal.DataSource, pkg *internal.LegacyVersionedPackage) (interface{}, error) {
switch tab {
case "doc":
return fetchDocumentationDetails(pkg), nil
@ -206,7 +206,7 @@ func fetchDetailsForModule(ctx context.Context, r *http.Request, tab string, ds
// constructDetailsForDirectory returns tab details by delegating to the correct
// detail handler.
func constructDetailsForDirectory(r *http.Request, tab string, dir *internal.Directory, licenses []*licenses.License) (interface{}, error) {
func constructDetailsForDirectory(r *http.Request, tab string, dir *internal.LegacyDirectory, licenses []*licenses.License) (interface{}, error) {
switch tab {
case "overview":
return constructOverviewDetails(&dir.ModuleInfo, dir.ModuleInfo.IsRedistributable, urlIsVersioned(r.URL)), nil

Просмотреть файл

@ -22,7 +22,7 @@ var (
commitTime = "0 hours ago"
)
func sampleModule(modulePath, version string, versionType version.Type, packages ...*internal.Package) *internal.Module {
func sampleModule(modulePath, version string, versionType version.Type, packages ...*internal.LegacyPackage) *internal.Module {
if len(packages) == 0 {
return sample.Module(modulePath, version, sample.Suffix)
}
@ -161,17 +161,17 @@ func TestFetchPackageVersionsDetails(t *testing.T) {
v1Path = "test.com/module/foo"
)
pkg1 := &internal.VersionedPackage{
ModuleInfo: *sample.ModuleInfo(modulePath1, "v1.2.1"),
Package: *sample.Package(modulePath1, sample.Suffix),
pkg1 := &internal.LegacyVersionedPackage{
ModuleInfo: *sample.ModuleInfo(modulePath1, "v1.2.1"),
LegacyPackage: *sample.LegacyPackage(modulePath1, sample.Suffix),
}
pkg2 := &internal.VersionedPackage{
ModuleInfo: *sample.ModuleInfo(modulePath2, "v2.2.1-alpha.1"),
Package: *sample.Package(modulePath2, sample.Suffix),
pkg2 := &internal.LegacyVersionedPackage{
ModuleInfo: *sample.ModuleInfo(modulePath2, "v2.2.1-alpha.1"),
LegacyPackage: *sample.LegacyPackage(modulePath2, sample.Suffix),
}
nethttpPkg := &internal.VersionedPackage{
ModuleInfo: *sample.ModuleInfo("std", "v1.12.5"),
Package: *sample.Package("std", "net/http"),
nethttpPkg := &internal.LegacyVersionedPackage{
ModuleInfo: *sample.ModuleInfo("std", "v1.12.5"),
LegacyPackage: *sample.LegacyPackage("std", "net/http"),
}
makeList := func(pkgPath, modulePath, major string, versions []string) *VersionList {
return &VersionList{
@ -184,7 +184,7 @@ func TestFetchPackageVersionsDetails(t *testing.T) {
for _, tc := range []struct {
name string
pkg *internal.VersionedPackage
pkg *internal.LegacyVersionedPackage
modules []*internal.Module
wantDetails *VersionsDetails
}{
@ -192,8 +192,8 @@ func TestFetchPackageVersionsDetails(t *testing.T) {
name: "want stdlib versions",
pkg: nethttpPkg,
modules: []*internal.Module{
sampleModule("std", "v1.12.5", version.TypeRelease, &nethttpPkg.Package),
sampleModule("std", "v1.11.6", version.TypeRelease, &nethttpPkg.Package),
sampleModule("std", "v1.12.5", version.TypeRelease, &nethttpPkg.LegacyPackage),
sampleModule("std", "v1.11.6", version.TypeRelease, &nethttpPkg.LegacyPackage),
},
wantDetails: &VersionsDetails{
ThisModule: []*VersionList{
@ -205,13 +205,13 @@ func TestFetchPackageVersionsDetails(t *testing.T) {
name: "want v1 first",
pkg: pkg1,
modules: []*internal.Module{
sampleModule(modulePath1, "v0.0.0-20140414041502-3c2ca4d52544", version.TypePseudo, &pkg2.Package),
sampleModule(modulePath1, "v1.2.3", version.TypeRelease, &pkg1.Package),
sampleModule(modulePath2, "v2.0.0", version.TypeRelease, &pkg2.Package),
sampleModule(modulePath1, "v1.3.0", version.TypeRelease, &pkg1.Package),
sampleModule(modulePath1, "v1.2.1", version.TypeRelease, &pkg1.Package),
sampleModule(modulePath2, "v2.2.1-alpha.1", version.TypePrerelease, &pkg2.Package),
sampleModule("test.com", "v1.2.1", version.TypeRelease, &pkg1.Package),
sampleModule(modulePath1, "v0.0.0-20140414041502-3c2ca4d52544", version.TypePseudo, &pkg2.LegacyPackage),
sampleModule(modulePath1, "v1.2.3", version.TypeRelease, &pkg1.LegacyPackage),
sampleModule(modulePath2, "v2.0.0", version.TypeRelease, &pkg2.LegacyPackage),
sampleModule(modulePath1, "v1.3.0", version.TypeRelease, &pkg1.LegacyPackage),
sampleModule(modulePath1, "v1.2.1", version.TypeRelease, &pkg1.LegacyPackage),
sampleModule(modulePath2, "v2.2.1-alpha.1", version.TypePrerelease, &pkg2.LegacyPackage),
sampleModule("test.com", "v1.2.1", version.TypeRelease, &pkg1.LegacyPackage),
},
wantDetails: &VersionsDetails{
ThisModule: []*VersionList{
@ -227,12 +227,12 @@ func TestFetchPackageVersionsDetails(t *testing.T) {
name: "want v2 first",
pkg: pkg2,
modules: []*internal.Module{
sampleModule(modulePath1, "v0.0.0-20140414041502-3c2ca4d52544", version.TypePseudo, &pkg1.Package),
sampleModule(modulePath1, "v1.2.1", version.TypeRelease, &pkg1.Package),
sampleModule(modulePath1, "v1.2.3", version.TypeRelease, &pkg1.Package),
sampleModule(modulePath1, "v2.1.0+incompatible", version.TypeRelease, &pkg1.Package),
sampleModule(modulePath2, "v2.0.0", version.TypeRelease, &pkg2.Package),
sampleModule(modulePath2, "v2.2.1-alpha.1", version.TypePrerelease, &pkg2.Package),
sampleModule(modulePath1, "v0.0.0-20140414041502-3c2ca4d52544", version.TypePseudo, &pkg1.LegacyPackage),
sampleModule(modulePath1, "v1.2.1", version.TypeRelease, &pkg1.LegacyPackage),
sampleModule(modulePath1, "v1.2.3", version.TypeRelease, &pkg1.LegacyPackage),
sampleModule(modulePath1, "v2.1.0+incompatible", version.TypeRelease, &pkg1.LegacyPackage),
sampleModule(modulePath2, "v2.0.0", version.TypeRelease, &pkg2.LegacyPackage),
sampleModule(modulePath2, "v2.2.1-alpha.1", version.TypePrerelease, &pkg2.LegacyPackage),
},
wantDetails: &VersionsDetails{
ThisModule: []*VersionList{
@ -247,8 +247,8 @@ func TestFetchPackageVersionsDetails(t *testing.T) {
name: "want only pseudo",
pkg: pkg2,
modules: []*internal.Module{
sampleModule(modulePath1, "v0.0.0-20140414041501-3c2ca4d52544", version.TypePseudo, &pkg2.Package),
sampleModule(modulePath1, "v0.0.0-20140414041502-4c2ca4d52544", version.TypePseudo, &pkg2.Package),
sampleModule(modulePath1, "v0.0.0-20140414041501-3c2ca4d52544", version.TypePseudo, &pkg2.LegacyPackage),
sampleModule(modulePath1, "v0.0.0-20140414041502-4c2ca4d52544", version.TypePseudo, &pkg2.LegacyPackage),
},
wantDetails: &VersionsDetails{
OtherModules: []*VersionList{

Просмотреть файл

@ -25,7 +25,7 @@ import (
// GetPackagesInModule returns packages contained in the module version
// specified by modulePath and version. The returned packages will be sorted
// by their package path.
func (db *DB) GetPackagesInModule(ctx context.Context, modulePath, version string) (_ []*internal.Package, err error) {
func (db *DB) GetPackagesInModule(ctx context.Context, modulePath, version string) (_ []*internal.LegacyPackage, err error) {
query := `SELECT
path,
name,
@ -44,10 +44,10 @@ func (db *DB) GetPackagesInModule(ctx context.Context, modulePath, version strin
AND version = $2
ORDER BY path;`
var packages []*internal.Package
var packages []*internal.LegacyPackage
collect := func(rows *sql.Rows) error {
var (
p internal.Package
p internal.LegacyPackage
licenseTypes, licensePaths []string
)
if err := rows.Scan(&p.Path, &p.Name, &p.Synopsis, &p.V1Path, pq.Array(&licenseTypes),
@ -463,7 +463,7 @@ func (db *DB) GetModuleInfo(ctx context.Context, modulePath string, version stri
)
row := db.db.QueryRow(ctx, query, args...)
if err := row.Scan(&mi.ModulePath, &mi.Version, &mi.CommitTime,
database.NullIsEmpty(&mi.ReadmeFilePath), database.NullIsEmpty(&mi.ReadmeContents), &mi.VersionType,
database.NullIsEmpty(&mi.LegacyReadmeFilePath), database.NullIsEmpty(&mi.LegacyReadmeContents), &mi.VersionType,
jsonbScanner{&mi.SourceInfo}, &mi.IsRedistributable, &hasGoMod); err != nil {
if err == sql.ErrNoRows {
return nil, fmt.Errorf("module version %s@%s: %w", modulePath, version, derrors.NotFound)

Просмотреть файл

@ -96,9 +96,9 @@ func TestPostgres_GetImportsAndImportedBy(t *testing.T) {
m3 = sample.Module("path3.to/foo", "v1.3.0", "bar3")
testModules = []*internal.Module{m1, m2, m3}
pkg1 = m1.Packages[0]
pkg2 = m2.Packages[0]
pkg3 = m3.Packages[0]
pkg1 = m1.LegacyPackages[0]
pkg2 = m2.LegacyPackages[0]
pkg3 = m3.LegacyPackages[0]
)
pkg1.Imports = nil
pkg2.Imports = []string{pkg1.Path}
@ -332,11 +332,11 @@ func TestGetPackagesInVersion(t *testing.T) {
opts := []cmp.Option{
// TODO(b/130367504): remove this ignore once imports are not asymmetric
cmpopts.IgnoreFields(internal.Package{}, "Imports"),
cmpopts.IgnoreFields(internal.LegacyPackage{}, "Imports"),
// The packages table only includes partial license information; it omits the Coverage field.
cmpopts.IgnoreFields(licenses.Metadata{}, "Coverage"),
}
if diff := cmp.Diff(tc.module.Packages, got, opts...); diff != "" {
if diff := cmp.Diff(tc.module.LegacyPackages, got, opts...); diff != "" {
t.Errorf("testDB.GetPackageInVersion(ctx, %q, %q) mismatch (-want +got):\n%s", tc.pkgPath, tc.module.Version, diff)
}
})
@ -346,8 +346,8 @@ func TestGetPackagesInVersion(t *testing.T) {
func TestGetPackageLicenses(t *testing.T) {
modulePath := "test.module"
testModule := sample.Module(modulePath, "v1.2.3", "", "foo")
testModule.Packages[0].Licenses = nil
testModule.Packages[1].Licenses = sample.LicenseMetadata
testModule.LegacyPackages[0].Licenses = nil
testModule.LegacyPackages[1].Licenses = sample.LicenseMetadata
tests := []struct {
label, pkgPath string
@ -388,15 +388,15 @@ func TestGetPackageLicenses(t *testing.T) {
func TestGetModuleLicenses(t *testing.T) {
modulePath := "test.module"
testModule := sample.Module(modulePath, "v1.2.3", "", "foo", "bar")
testModule.Packages[0].Licenses = []*licenses.Metadata{{Types: []string{"ISC"}, FilePath: "LICENSE"}}
testModule.Packages[1].Licenses = []*licenses.Metadata{{Types: []string{"MIT"}, FilePath: "foo/LICENSE"}}
testModule.Packages[2].Licenses = []*licenses.Metadata{{Types: []string{"GPL2"}, FilePath: "bar/LICENSE.txt"}}
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"}}
defer ResetTestDB(testDB, t)
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
defer cancel()
for _, p := range testModule.Packages {
for _, p := range testModule.LegacyPackages {
testModule.Licenses = append(testModule.Licenses, &licenses.License{
Metadata: p.Licenses[0],
Contents: []byte(`Lorem Ipsum`),

Просмотреть файл

@ -74,8 +74,8 @@ func (db *DB) GetDirectoryNew(ctx context.Context, path, modulePath, version str
&mi.IsRedistributable,
&mi.HasGoMod,
jsonbScanner{&mi.SourceInfo},
&mi.ReadmeFilePath,
&mi.ReadmeContents,
&mi.LegacyReadmeFilePath,
&mi.LegacyReadmeContents,
&pathID,
&dir.Path,
database.NullIsEmpty(&pkg.Name),
@ -166,7 +166,7 @@ func (db *DB) GetDirectoryNew(ctx context.Context, path, modulePath, version str
//
// It will not match on:
// golang.org/x/tools/g
func (db *DB) GetDirectory(ctx context.Context, dirPath, modulePath, version string, fields internal.FieldSet) (_ *internal.Directory, err error) {
func (db *DB) GetDirectory(ctx context.Context, dirPath, modulePath, version string, fields internal.FieldSet) (_ *internal.LegacyDirectory, err error) {
defer derrors.Wrap(&err, "DB.GetDirectory(ctx, %q, %q, %q)", dirPath, modulePath, version)
if dirPath == "" || modulePath == "" || version == "" {
@ -184,12 +184,12 @@ func (db *DB) GetDirectory(ctx context.Context, dirPath, modulePath, version str
}
var (
packages []*internal.Package
mi = internal.ModuleInfo{ReadmeContents: internal.StringFieldMissing}
packages []*internal.LegacyPackage
mi = internal.ModuleInfo{LegacyReadmeContents: internal.StringFieldMissing}
)
collect := func(rows *sql.Rows) error {
var (
pkg = internal.Package{DocumentationHTML: internal.StringFieldMissing}
pkg = internal.LegacyPackage{DocumentationHTML: internal.StringFieldMissing}
licenseTypes []string
licensePaths []string
)
@ -210,9 +210,9 @@ func (db *DB) GetDirectory(ctx context.Context, dirPath, modulePath, version str
&pkg.GOARCH,
&mi.Version,
&mi.ModulePath,
database.NullIsEmpty(&mi.ReadmeFilePath))
database.NullIsEmpty(&mi.LegacyReadmeFilePath))
if fields&internal.WithReadmeContents != 0 {
scanArgs = append(scanArgs, database.NullIsEmpty(&mi.ReadmeContents))
scanArgs = append(scanArgs, database.NullIsEmpty(&mi.LegacyReadmeContents))
}
var hasGoMod sql.NullBool
scanArgs = append(scanArgs,
@ -242,7 +242,7 @@ func (db *DB) GetDirectory(ctx context.Context, dirPath, modulePath, version str
sort.Slice(packages, func(i, j int) bool {
return packages[i].Path < packages[j].Path
})
return &internal.Directory{
return &internal.LegacyDirectory{
Path: dirPath,
ModuleInfo: mi,
Packages: packages,

Просмотреть файл

@ -253,9 +253,9 @@ func TestGetDirectory(t *testing.T) {
}
mi := sample.ModuleInfo(tc.wantModulePath, tc.wantVersion)
var wantPackages []*internal.Package
var wantPackages []*internal.LegacyPackage
for _, suffix := range tc.wantSuffixes {
pkg := sample.Package(tc.wantModulePath, suffix)
pkg := sample.LegacyPackage(tc.wantModulePath, suffix)
pkg.Imports = nil
wantPackages = append(wantPackages, pkg)
}
@ -263,7 +263,7 @@ func TestGetDirectory(t *testing.T) {
return wantPackages[i].Path < wantPackages[j].Path
})
wantDirectory := &internal.Directory{
wantDirectory := &internal.LegacyDirectory{
ModuleInfo: *mi,
Packages: wantPackages,
Path: tc.dirPath,
@ -450,7 +450,7 @@ func TestGetDirectoryFieldSet(t *testing.T) {
defer ResetTestDB(testDB, t)
m := sample.Module("m.c", sample.VersionString, "d/p")
m.Packages[0].Imports = nil
m.LegacyPackages[0].Imports = nil
if err := testDB.InsertModule(ctx, m); err != nil {
t.Fatal(err)
}
@ -459,8 +459,8 @@ func TestGetDirectoryFieldSet(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if g, w := got.ReadmeContents, internal.StringFieldMissing; g != w {
t.Errorf("ReadmeContents = %q, want %q", g, w)
if g, w := got.LegacyReadmeContents, internal.StringFieldMissing; g != w {
t.Errorf("LegacyReadmeContents = %q, want %q", g, w)
}
if g, w := got.Packages[0].DocumentationHTML, internal.StringFieldMissing; g != w {
t.Errorf("DocumentationHTML = %q, want %q", g, w)

Просмотреть файл

@ -199,8 +199,8 @@ func insertModule(ctx context.Context, db *database.DB, m *internal.Module) (_ i
m.ModulePath,
m.Version,
m.CommitTime,
m.ReadmeFilePath,
makeValidUnicode(m.ReadmeContents),
m.LegacyReadmeFilePath,
makeValidUnicode(m.LegacyReadmeContents),
version.ForSorting(m.Version),
m.VersionType,
m.SeriesPath(),
@ -254,17 +254,17 @@ func insertPackages(ctx context.Context, db *database.DB, m *internal.Module) (e
// the same module, which happens regularly. But if we were ever to process
// the same module and version twice, we could see deadlocks in the other
// bulk inserts.
sort.Slice(m.Packages, func(i, j int) bool {
return m.Packages[i].Path < m.Packages[j].Path
sort.Slice(m.LegacyPackages, func(i, j int) bool {
return m.LegacyPackages[i].Path < m.LegacyPackages[j].Path
})
sort.Slice(m.Licenses, func(i, j int) bool {
return m.Licenses[i].FilePath < m.Licenses[j].FilePath
})
for _, p := range m.Packages {
for _, p := range m.LegacyPackages {
sort.Strings(p.Imports)
}
var pkgValues, importValues []interface{}
for _, p := range m.Packages {
for _, p := range m.LegacyPackages {
if p.DocumentationHTML == internal.StringFieldMissing {
return errors.New("saveModule: package missing DocumentationHTML")
}
@ -354,7 +354,7 @@ func insertImportsUnique(ctx context.Context, tx *database.DB, m *internal.Modul
}
var values []interface{}
for _, p := range m.Packages {
for _, p := range m.LegacyPackages {
for _, i := range p.Imports {
values = append(values, p.Path, m.ModulePath, i)
}
@ -371,9 +371,9 @@ func insertDirectories(ctx context.Context, db *database.DB, m *internal.Module,
ctx, span := trace.StartSpan(ctx, "insertDirectories")
defer span.End()
if m.ReadmeContents == internal.StringFieldMissing {
if m.LegacyReadmeContents == internal.StringFieldMissing {
// We don't expect this to ever happen here, but checking just in case.
return errors.New("saveModule: version missing ReadmeContents")
return errors.New("saveModule: version missing LegacyReadmeContents")
}
// Sort to ensure proper lock ordering, avoiding deadlocks. See
// b/141164828#comment8. We have seen deadlocks on package_imports and
@ -616,7 +616,7 @@ func validateModule(m *internal.Module) (err error) {
errReasons = append(errReasons, "invalid version")
}
}
if len(m.Packages) == 0 {
if len(m.LegacyPackages) == 0 {
errReasons = append(errReasons, "module does not have any packages")
}
if m.CommitTime.IsZero() {
@ -650,9 +650,9 @@ func (db *DB) compareLicenses(ctx context.Context, m *internal.Module) (err erro
return nil
}
// comparePackages compares m.Packages with the existing packages for
// comparePackages compares m.LegacyPackages with the existing packages for
// m.ModulePath and m.Version in the database. It returns an error if there
// are packages in the packages table that are not present in m.Packages.
// are packages in the packages table that are not present in m.LegacyPackages.
func (db *DB) comparePackages(ctx context.Context, m *internal.Module) (err error) {
defer derrors.Wrap(&err, "comparePackages(ctx, %q, %q)", m.ModulePath, m.Version)
dbPackages, err := db.GetPackagesInModule(ctx, m.ModulePath, m.Version)
@ -660,7 +660,7 @@ func (db *DB) comparePackages(ctx context.Context, m *internal.Module) (err erro
return err
}
set := map[string]bool{}
for _, p := range m.Packages {
for _, p := range m.LegacyPackages {
set[p.Path] = true
}
for _, p := range dbPackages {
@ -695,7 +695,7 @@ func (db *DB) comparePaths(ctx context.Context, m *internal.Module) (err error)
// removeNonDistributableData removes any information from the version payload,
// after checking licenses.
func removeNonDistributableData(m *internal.Module) {
for _, p := range m.Packages {
for _, p := range m.LegacyPackages {
if !p.IsRedistributable {
// Prune derived information that can't be stored.
p.Synopsis = ""
@ -703,8 +703,8 @@ func removeNonDistributableData(m *internal.Module) {
}
}
if !m.IsRedistributable {
m.ReadmeFilePath = ""
m.ReadmeContents = ""
m.LegacyReadmeFilePath = ""
m.LegacyReadmeContents = ""
}
}

Просмотреть файл

@ -62,7 +62,7 @@ func TestInsertModule(t *testing.T) {
name: "stdlib",
module: func() *internal.Module {
m := sample.Module("std", "v1.12.5")
p := &internal.Package{
p := &internal.LegacyPackage{
Name: "context",
Path: "context",
Synopsis: "This is a package synopsis",
@ -92,7 +92,7 @@ func TestInsertModule(t *testing.T) {
t.Fatalf("testDB.GetModuleInfo(%q, %q) mismatch (-want +got):\n%s", test.module.ModulePath, test.module.Version, diff)
}
for _, want := range test.module.Packages {
for _, want := range test.module.LegacyPackages {
got, err := testDB.GetPackage(ctx, want.Path, test.module.ModulePath, test.module.Version)
if err != nil {
t.Fatal(err)
@ -101,11 +101,11 @@ func TestInsertModule(t *testing.T) {
// The packages table only includes partial
// license information; it omits the Coverage
// field.
cmpopts.IgnoreFields(internal.Package{}, "Imports"),
cmpopts.IgnoreFields(internal.LegacyPackage{}, "Imports"),
cmpopts.IgnoreFields(licenses.Metadata{}, "Coverage"),
cmpopts.EquateEmpty(),
}
if diff := cmp.Diff(*want, got.Package, opts...); diff != "" {
if diff := cmp.Diff(*want, got.LegacyPackage, opts...); diff != "" {
t.Fatalf("testDB.GetPackage(%q, %q) mismatch (-want +got):\n%s", want.Path, test.module.Version, diff)
}
@ -121,8 +121,8 @@ func TestInsertModule(t *testing.T) {
ModuleInfo: test.module.ModuleInfo,
}
opts := cmp.Options{
cmpopts.IgnoreFields(internal.ModuleInfo{}, "ReadmeFilePath"),
cmpopts.IgnoreFields(internal.ModuleInfo{}, "ReadmeContents"),
cmpopts.IgnoreFields(internal.ModuleInfo{}, "LegacyReadmeFilePath"),
cmpopts.IgnoreFields(internal.ModuleInfo{}, "LegacyReadmeContents"),
cmpopts.IgnoreFields(licenses.Metadata{}, "Coverage"),
cmp.AllowUnexported(source.Info{}),
}
@ -294,7 +294,7 @@ func TestPostgres_NewerAlternative(t *testing.T) {
if err := testDB.InsertModule(ctx, m); err != nil {
t.Fatal(err)
}
if _, _, found := GetFromSearchDocuments(ctx, t, testDB, m.Packages[0].Path); found {
if _, _, found := GetFromSearchDocuments(ctx, t, testDB, m.LegacyPackages[0].Path); found {
t.Fatal("found package after inserting")
}
}

Просмотреть файл

@ -41,7 +41,7 @@ import (
// The returned error may be checked with
// errors.Is(err, derrors.InvalidArgument) to determine if it was caused by an
// invalid path or version.
func (db *DB) GetPackage(ctx context.Context, pkgPath, modulePath, version string) (_ *internal.VersionedPackage, err error) {
func (db *DB) GetPackage(ctx context.Context, pkgPath, modulePath, version string) (_ *internal.LegacyVersionedPackage, err error) {
defer derrors.Wrap(&err, "DB.GetPackage(ctx, %q, %q)", pkgPath, version)
if pkgPath == "" || modulePath == "" || version == "" {
return nil, fmt.Errorf("none of pkgPath, modulePath, or version can be empty: %w", derrors.InvalidArgument)
@ -132,15 +132,15 @@ func (db *DB) GetPackage(ctx context.Context, pkgPath, modulePath, version strin
}
var (
pkg internal.VersionedPackage
pkg internal.LegacyVersionedPackage
licenseTypes, licensePaths []string
hasGoMod sql.NullBool
)
row := db.db.QueryRow(ctx, query, args...)
err = row.Scan(&pkg.Path, &pkg.Name, &pkg.Synopsis,
&pkg.V1Path, pq.Array(&licenseTypes), pq.Array(&licensePaths), &pkg.Package.IsRedistributable,
&pkg.V1Path, pq.Array(&licenseTypes), pq.Array(&licensePaths), &pkg.LegacyPackage.IsRedistributable,
database.NullIsEmpty(&pkg.DocumentationHTML), &pkg.GOOS, &pkg.GOARCH, &pkg.Version,
&pkg.CommitTime, database.NullIsEmpty(&pkg.ReadmeFilePath), database.NullIsEmpty(&pkg.ReadmeContents),
&pkg.CommitTime, database.NullIsEmpty(&pkg.LegacyReadmeFilePath), database.NullIsEmpty(&pkg.LegacyReadmeContents),
&pkg.ModulePath, &pkg.VersionType, jsonbScanner{&pkg.SourceInfo}, &pkg.ModuleInfo.IsRedistributable,
&hasGoMod)
if err != nil {

Просмотреть файл

@ -42,11 +42,11 @@ func TestGetPackage(t *testing.T) {
t.Fatal(err)
}
}
checkPackage := func(got *internal.VersionedPackage, pkgPath, modulePath, version string) {
checkPackage := func(got *internal.LegacyVersionedPackage, pkgPath, modulePath, version string) {
t.Helper()
want := &internal.VersionedPackage{
ModuleInfo: *sample.ModuleInfo(modulePath, version),
Package: *sample.Package(modulePath, suffix(pkgPath, modulePath)),
want := &internal.LegacyVersionedPackage{
ModuleInfo: *sample.ModuleInfo(modulePath, version),
LegacyPackage: *sample.LegacyPackage(modulePath, suffix(pkgPath, modulePath)),
}
want.Imports = nil
opts := cmp.Options{

Просмотреть файл

@ -50,7 +50,7 @@ func TestGetPathInfo(t *testing.T) {
VersionType: vtype,
CommitTime: time.Now(),
},
Packages: []*internal.Package{{
LegacyPackages: []*internal.LegacyPackage{{
Name: pkgName,
Path: pkgPath,
}},
@ -188,7 +188,7 @@ func TestGetStdlibPaths(t *testing.T) {
},
} {
m := sample.Module(stdlib.ModulePath, data.version, data.suffixes...)
for _, p := range m.Packages {
for _, p := range m.LegacyPackages {
p.Imports = nil
}
if err := testDB.InsertModule(ctx, m); err != nil {

Просмотреть файл

@ -550,7 +550,7 @@ func UpsertSearchDocuments(ctx context.Context, db *database.DB, mod *internal.M
defer derrors.Wrap(&err, "UpsertSearchDocuments(ctx, %q)", mod.ModulePath)
ctx, span := trace.StartSpan(ctx, "UpsertSearchDocuments")
defer span.End()
for _, pkg := range mod.Packages {
for _, pkg := range mod.LegacyPackages {
if isInternalPackage(pkg.Path) {
continue
}
@ -558,8 +558,8 @@ func UpsertSearchDocuments(ctx context.Context, db *database.DB, mod *internal.M
PackagePath: pkg.Path,
ModulePath: mod.ModulePath,
Synopsis: pkg.Synopsis,
ReadmeFilePath: mod.ReadmeFilePath,
ReadmeContents: mod.ReadmeContents,
ReadmeFilePath: mod.LegacyReadmeFilePath,
ReadmeContents: mod.LegacyReadmeContents,
})
if err != nil {
return err

Просмотреть файл

@ -154,15 +154,15 @@ func TestSearch(t *testing.T) {
// a single importing module.
importGraph := func(popularPath, importerModule string, importerCount int) []*internal.Module {
m := sample.Module(popularPath, "v1.2.3", "")
m.Packages[0].Imports = nil
m.LegacyPackages[0].Imports = nil
// Try to improve the ts_rank of the 'foo' search term.
m.Packages[0].Synopsis = "foo"
m.ReadmeContents = "foo"
m.LegacyPackages[0].Synopsis = "foo"
m.LegacyReadmeContents = "foo"
mods := []*internal.Module{m}
if importerCount > 0 {
m := sample.Module(importerModule, "v1.2.3")
for i := 0; i < importerCount; i++ {
p := sample.Package(importerModule, fmt.Sprintf("importer%d", i))
p := sample.LegacyPackage(importerModule, fmt.Sprintf("importer%d", i))
p.Imports = []string{popularPath}
sample.AddPackage(m, p)
}
@ -318,7 +318,7 @@ func TestSearch(t *testing.T) {
func TestInsertSearchDocumentAndSearch(t *testing.T) {
var (
modGoCDK = "gocloud.dev"
pkgGoCDK = &internal.Package{
pkgGoCDK = &internal.LegacyPackage{
Name: "cloud",
Path: "gocloud.dev/cloud",
Synopsis: "Package cloud contains a library and tools for open cloud development in Go. The Go Cloud Development Kit (Go CDK)",
@ -326,7 +326,7 @@ func TestInsertSearchDocumentAndSearch(t *testing.T) {
}
modKube = "k8s.io"
pkgKube = &internal.Package{
pkgKube = &internal.LegacyPackage{
Name: "client-go",
Path: "k8s.io/client-go",
Synopsis: "Package client-go implements a Go client for Kubernetes.",
@ -370,7 +370,7 @@ func TestInsertSearchDocumentAndSearch(t *testing.T) {
for _, tc := range []struct {
name string
packages map[string]*internal.Package
packages map[string]*internal.LegacyPackage
limit, offset int
searchQuery string
want []*internal.SearchResult
@ -378,7 +378,7 @@ func TestInsertSearchDocumentAndSearch(t *testing.T) {
{
name: "two documents, single term search",
searchQuery: "package",
packages: map[string]*internal.Package{
packages: map[string]*internal.LegacyPackage{
modGoCDK: pkgGoCDK,
modKube: pkgKube,
},
@ -392,7 +392,7 @@ func TestInsertSearchDocumentAndSearch(t *testing.T) {
limit: 1,
offset: 0,
searchQuery: "package",
packages: map[string]*internal.Package{
packages: map[string]*internal.LegacyPackage{
modKube: pkgKube,
modGoCDK: pkgGoCDK,
},
@ -405,7 +405,7 @@ func TestInsertSearchDocumentAndSearch(t *testing.T) {
limit: 1,
offset: 1,
searchQuery: "package",
packages: map[string]*internal.Package{
packages: map[string]*internal.LegacyPackage{
modGoCDK: pkgGoCDK,
modKube: pkgKube,
},
@ -416,7 +416,7 @@ func TestInsertSearchDocumentAndSearch(t *testing.T) {
{
name: "two documents, multiple term search",
searchQuery: "go & cdk",
packages: map[string]*internal.Package{
packages: map[string]*internal.LegacyPackage{
modGoCDK: pkgGoCDK,
modKube: pkgKube,
},
@ -427,7 +427,7 @@ func TestInsertSearchDocumentAndSearch(t *testing.T) {
{
name: "one document, single term search",
searchQuery: "cloud",
packages: map[string]*internal.Package{
packages: map[string]*internal.LegacyPackage{
modGoCDK: pkgGoCDK,
},
want: []*internal.SearchResult{
@ -500,7 +500,7 @@ func TestSearchPenalties(t *testing.T) {
for path, m := range modules {
v := sample.Module(path, sample.VersionString, "p")
v.Packages[0].IsRedistributable = m.redist
v.LegacyPackages[0].IsRedistributable = m.redist
v.IsRedistributable = m.redist
v.HasGoMod = m.hasGoMod
if err := testDB.InsertModule(ctx, v); err != nil {
@ -600,7 +600,7 @@ func TestUpsertSearchDocument(t *testing.T) {
insertModule := func(version string, gomod bool) {
v := sample.Module(sample.ModulePath, version, "A")
v.HasGoMod = gomod
v.Packages[0].Synopsis = "syn-" + version
v.LegacyPackages[0].Synopsis = "syn-" + version
if err := testDB.InsertModule(ctx, v); err != nil {
t.Fatal(err)
}
@ -665,7 +665,7 @@ func TestUpdateSearchDocumentsImportedByCount(t *testing.T) {
insertPackageVersion := func(suffix, version string, imports []string) *internal.Module {
t.Helper()
m := sample.Module("mod.com/"+suffix, version, suffix)
pkg := m.Packages[0]
pkg := m.LegacyPackages[0]
pkg.Imports = nil
for _, imp := range imports {
pkg.Imports = append(pkg.Imports, fmt.Sprintf("mod.com/%s/%[1]s", imp))
@ -696,7 +696,7 @@ func TestUpdateSearchDocumentsImportedByCount(t *testing.T) {
return sd
}
pkgPath := func(m *internal.Module) string { return m.Packages[0].Path }
pkgPath := func(m *internal.Module) string { return m.LegacyPackages[0].Path }
t.Run("basic", func(t *testing.T) {
defer ResetTestDB(testDB, t)
@ -771,7 +771,7 @@ func TestUpdateSearchDocumentsImportedByCount(t *testing.T) {
// 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.Packages[0].Imports = []string{"B"}
mAlt.LegacyPackages[0].Imports = []string{"B"}
if err := testDB.InsertModule(ctx, mAlt); err != nil {
t.Fatal(err)
}

Просмотреть файл

@ -210,7 +210,7 @@ func InsertSampleDirectoryTree(ctx context.Context, t *testing.T, testDB *DB) {
},
} {
m := sample.Module(data.modulePath, data.version, data.suffixes...)
for _, p := range m.Packages {
for _, p := range m.LegacyPackages {
p.Imports = nil
}
if err := testDB.InsertModule(ctx, m); err != nil {

Просмотреть файл

@ -67,7 +67,7 @@ type versionEntry struct {
}
// GetDirectory returns packages contained in the given subdirectory of a module version.
func (ds *DataSource) GetDirectory(ctx context.Context, dirPath, modulePath, version string, _ internal.FieldSet) (_ *internal.Directory, err error) {
func (ds *DataSource) GetDirectory(ctx context.Context, dirPath, modulePath, version string, _ internal.FieldSet) (_ *internal.LegacyDirectory, err error) {
defer derrors.Wrap(&err, "GetDirectory(%q, %q, %q)", dirPath, modulePath, version)
var info *proxy.VersionInfo
@ -82,10 +82,10 @@ func (ds *DataSource) GetDirectory(ctx context.Context, dirPath, modulePath, ver
if err != nil {
return nil, err
}
return &internal.Directory{
return &internal.LegacyDirectory{
Path: dirPath,
ModuleInfo: v.ModuleInfo,
Packages: v.Packages,
Packages: v.LegacyPackages,
}, nil
}
@ -136,11 +136,11 @@ func (ds *DataSource) GetModuleLicenses(ctx context.Context, modulePath, version
return filtered, nil
}
// GetPackage returns a VersionedPackage for the given pkgPath and version. If
// GetPackage returns a LegacyVersionedPackage for the given pkgPath and version. If
// such a package exists in the cache, it will be returned without querying the
// proxy. Otherwise, the proxy is queried to find the longest module path at
// that version containing the package.
func (ds *DataSource) GetPackage(ctx context.Context, pkgPath, modulePath, version string) (_ *internal.VersionedPackage, err error) {
func (ds *DataSource) GetPackage(ctx context.Context, pkgPath, modulePath, version string) (_ *internal.LegacyVersionedPackage, err error) {
defer derrors.Wrap(&err, "GetPackage(%q, %q)", pkgPath, version)
var m *internal.Module
@ -163,7 +163,7 @@ func (ds *DataSource) GetPackageLicenses(ctx context.Context, pkgPath, modulePat
if err != nil {
return nil, err
}
for _, p := range v.Packages {
for _, p := range v.LegacyPackages {
if p.Path == pkgPath {
var lics []*licenses.License
for _, lmd := range p.Licenses {
@ -181,14 +181,14 @@ func (ds *DataSource) GetPackageLicenses(ctx context.Context, pkgPath, modulePat
return nil, fmt.Errorf("package %s is missing from module %s: %w", pkgPath, modulePath, derrors.NotFound)
}
// GetPackagesInModule returns Packages contained in the module zip corresponding to modulePath and version.
func (ds *DataSource) GetPackagesInModule(ctx context.Context, modulePath, version string) (_ []*internal.Package, err error) {
// GetPackagesInModule returns LegacyPackages contained in the module zip corresponding to modulePath and version.
func (ds *DataSource) GetPackagesInModule(ctx context.Context, modulePath, version string) (_ []*internal.LegacyPackage, err error) {
defer derrors.Wrap(&err, "GetPackagesInModule(%q, %q)", modulePath, version)
v, err := ds.getModule(ctx, modulePath, version)
if err != nil {
return nil, err
}
return v.Packages, nil
return v.LegacyPackages, nil
}
// GetPseudoVersionsForModule returns versions from the the proxy /list
@ -270,7 +270,7 @@ func (ds *DataSource) getModule(ctx context.Context, modulePath, version string)
// be a bit more careful and check that it is new. To do this, we can
// leverage the invariant that module paths in packagePathToModules are kept
// sorted in descending order of length.
for _, pkg := range m.Packages {
for _, pkg := range m.LegacyPackages {
var (
i int
mp string
@ -403,15 +403,15 @@ func (ds *DataSource) findModulePathForPackage(pkgPath, version string) (string,
return "", false
}
// packageFromVersion extracts the VersionedPackage for pkgPath from the
// packageFromVersion extracts the LegacyVersionedPackage for pkgPath from the
// Version payload.
func packageFromVersion(pkgPath string, m *internal.Module) (_ *internal.VersionedPackage, err error) {
func packageFromVersion(pkgPath string, m *internal.Module) (_ *internal.LegacyVersionedPackage, err error) {
defer derrors.Wrap(&err, "packageFromVersion(%q, ...)", pkgPath)
for _, p := range m.Packages {
for _, p := range m.LegacyPackages {
if p.Path == pkgPath {
return &internal.VersionedPackage{
Package: *p,
ModuleInfo: m.ModuleInfo,
return &internal.LegacyVersionedPackage{
LegacyPackage: *p,
ModuleInfo: m.ModuleInfo,
}, nil
}
}
@ -445,7 +445,7 @@ func (ds *DataSource) GetPathInfo(ctx context.Context, path, inModulePath, inVer
return "", "", false, err
}
isPackage = false
for _, p := range m.Packages {
for _, p := range m.LegacyPackages {
if p.Path == path {
isPackage = true
break

Просмотреть файл

@ -49,7 +49,7 @@ func setup(t *testing.T) (context.Context, *DataSource, func()) {
var (
wantLicenseMD = sample.LicenseMetadata[0]
wantLicense = &licenses.License{Metadata: wantLicenseMD}
wantPackage = internal.Package{
wantPackage = internal.LegacyPackage{
Path: "foo.com/bar/baz",
Name: "baz",
Imports: []string{"net/http"},
@ -68,12 +68,12 @@ var (
IsRedistributable: true,
HasGoMod: true,
}
wantVersionedPackage = &internal.VersionedPackage{
ModuleInfo: wantModuleInfo,
Package: wantPackage,
wantVersionedPackage = &internal.LegacyVersionedPackage{
ModuleInfo: wantModuleInfo,
LegacyPackage: wantPackage,
}
cmpOpts = append([]cmp.Option{
cmpopts.IgnoreFields(internal.Package{}, "DocumentationHTML"),
cmpopts.IgnoreFields(internal.LegacyPackage{}, "DocumentationHTML"),
cmpopts.IgnoreFields(licenses.License{}, "Contents"),
}, sample.LicenseCmpOpts...)
)
@ -81,10 +81,10 @@ var (
func TestDataSource_GetDirectory(t *testing.T) {
ctx, ds, teardown := setup(t)
defer teardown()
want := &internal.Directory{
want := &internal.LegacyDirectory{
Path: "foo.com/bar",
ModuleInfo: wantModuleInfo,
Packages: []*internal.Package{&wantPackage},
Packages: []*internal.LegacyPackage{&wantPackage},
}
got, err := ds.GetDirectory(ctx, "foo.com/bar", internal.UnknownModulePath, "v1.2.0", internal.AllFields)
if err != nil {
@ -177,7 +177,7 @@ func TestDataSource_GetPackagesInVersion(t *testing.T) {
if err != nil {
t.Fatal(err)
}
want := []*internal.Package{&wantPackage}
want := []*internal.LegacyPackage{&wantPackage}
if diff := cmp.Diff(want, got, cmpOpts...); diff != "" {
t.Errorf("GetPackagesInVersion diff (-want +got):\n%s", diff)
}

Просмотреть файл

@ -121,7 +121,7 @@ func (i *Info) RawURL(pathname string) string {
// Special case: the standard library's source module path is set to "src",
// which is correct for source file links. But the README is at the repo
// root, not in the src directory. In other words,
// VersionInfo.ReadmeFilePath is not relative to
// VersionInfo.LegacyReadmeFilePath is not relative to
// VersionInfo.SourceInfo.moduleDir, as it is for every other module.
// Correct for that here.
if i.repoURL == stdlib.GoSourceRepoURL {

Просмотреть файл

@ -79,19 +79,19 @@ func NowTruncated() time.Time {
return time.Now().Truncate(time.Microsecond)
}
// Package constructs a package with the given module path and suffix.
// LegacyPackage constructs a package with the given module path and suffix.
//
// If modulePath is the standard library, the package path is the
// suffix, which must not be empty. Otherwise, the package path
// is the concatenation of modulePath and suffix.
//
// The package name is last component of the package path.
func Package(modulePath, suffix string) *internal.Package {
func LegacyPackage(modulePath, suffix string) *internal.LegacyPackage {
pkgPath := suffix
if modulePath != stdlib.ModulePath {
pkgPath = path.Join(modulePath, suffix)
}
return &internal.Package{
return &internal.LegacyPackage{
Name: path.Base(pkgPath),
Path: pkgPath,
V1Path: internal.V1Path(modulePath, suffix),
@ -119,12 +119,12 @@ func ModuleInfo(modulePath, versionString string) *internal.ModuleInfo {
// ModuleInfos with "latest" for version, which should not be valid.
func ModuleInfoReleaseType(modulePath, versionString string) *internal.ModuleInfo {
return &internal.ModuleInfo{
ModulePath: modulePath,
Version: versionString,
ReadmeFilePath: ReadmeFilePath,
ReadmeContents: ReadmeContents,
CommitTime: CommitTime,
VersionType: version.TypeRelease,
ModulePath: modulePath,
Version: versionString,
LegacyReadmeFilePath: ReadmeFilePath,
LegacyReadmeContents: ReadmeContents,
CommitTime: CommitTime,
VersionType: version.TypeRelease,
// Assume the module path is a GitHub-like repo name.
SourceInfo: source.NewGitHubInfo("https://"+modulePath, "", versionString),
IsRedistributable: true,
@ -135,33 +135,33 @@ func ModuleInfoReleaseType(modulePath, versionString string) *internal.ModuleInf
func DefaultModule() *internal.Module {
return AddPackage(
Module(ModulePath, VersionString),
Package(ModulePath, Suffix))
LegacyPackage(ModulePath, Suffix))
}
// Module creates a Module with the given path and version.
// The list of suffixes is used to create Packages within the module.
// The list of suffixes is used to create LegacyPackages within the module.
func Module(modulePath, version string, suffixes ...string) *internal.Module {
mi := ModuleInfo(modulePath, version)
m := &internal.Module{
ModuleInfo: *mi,
Packages: nil,
Licenses: Licenses,
ModuleInfo: *mi,
LegacyPackages: nil,
Licenses: Licenses,
Directories: []*internal.DirectoryNew{
DirectoryNewForModuleRoot(mi, LicenseMetadata),
},
}
for _, s := range suffixes {
AddPackage(m, Package(modulePath, s))
AddPackage(m, LegacyPackage(modulePath, s))
}
return m
}
func AddPackage(m *internal.Module, p *internal.Package) *internal.Module {
func AddPackage(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.Packages = append(m.Packages, p)
m.LegacyPackages = append(m.LegacyPackages, p)
m.Directories = append(m.Directories, DirectoryNewForPackage(p))
minLen := len(m.ModulePath)
if m.ModulePath == stdlib.ModulePath {
@ -198,16 +198,16 @@ func DirectoryNewForModuleRoot(m *internal.ModuleInfo, licenses []*licenses.Meta
Licenses: licenses,
V1Path: internal.SeriesPathForModule(m.ModulePath),
}
if m.ReadmeFilePath != "" {
if m.LegacyReadmeFilePath != "" {
d.Readme = &internal.Readme{
Filepath: m.ReadmeFilePath,
Contents: m.ReadmeContents,
Filepath: m.LegacyReadmeFilePath,
Contents: m.LegacyReadmeContents,
}
}
return d
}
func DirectoryNewForPackage(pkg *internal.Package) *internal.DirectoryNew {
func DirectoryNewForPackage(pkg *internal.LegacyPackage) *internal.DirectoryNew {
return &internal.DirectoryNew{
Path: pkg.Path,
IsRedistributable: pkg.IsRedistributable,

Просмотреть файл

@ -31,7 +31,7 @@ func TestUpdateRedisIndexes(t *testing.T) {
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")
m2.Packages[0].Imports = []string{m1.Packages[0].Path}
m2.LegacyPackages[0].Imports = []string{m1.LegacyPackages[0].Path}
if err := testDB.InsertModule(ctx, m1); err != nil {
t.Fatal(err)
}

Просмотреть файл

@ -628,19 +628,19 @@ func TestReFetch(t *testing.T) {
if _, err := FetchAndUpdateState(ctx, modulePath, version, proxyClient, sourceClient, testDB); err != nil {
t.Fatalf("FetchAndUpdateState(%q, %q, %v, %v, %v): %v", modulePath, version, proxyClient, sourceClient, testDB, err)
}
want := &internal.VersionedPackage{
want := &internal.LegacyVersionedPackage{
ModuleInfo: internal.ModuleInfo{
ModulePath: modulePath,
Version: version,
CommitTime: time.Date(2019, 1, 30, 0, 0, 0, 0, time.UTC),
ReadmeFilePath: "README.md",
ReadmeContents: "This is a readme",
VersionType: "release",
IsRedistributable: true,
HasGoMod: false,
SourceInfo: source.NewGitHubInfo("https://github.com/my/module", "", "v1.0.0"),
ModulePath: modulePath,
Version: version,
CommitTime: time.Date(2019, 1, 30, 0, 0, 0, 0, time.UTC),
VersionType: "release",
IsRedistributable: true,
HasGoMod: false,
SourceInfo: source.NewGitHubInfo("https://github.com/my/module", "", "v1.0.0"),
LegacyReadmeFilePath: "README.md",
LegacyReadmeContents: "This is a readme",
},
Package: internal.Package{
LegacyPackage: internal.LegacyPackage{
Path: "github.com/my/module/bar",
Name: "bar",
Synopsis: "Package bar",
@ -658,7 +658,7 @@ func TestReFetch(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if diff := cmp.Diff(want, got, cmpopts.IgnoreFields(internal.Package{}, "DocumentationHTML"), cmp.AllowUnexported(source.Info{})); diff != "" {
if diff := cmp.Diff(want, got, cmpopts.IgnoreFields(internal.LegacyPackage{}, "DocumentationHTML"), cmp.AllowUnexported(source.Info{})); diff != "" {
t.Errorf("testDB.GetPackage(ctx, %q, %q) mismatch (-want +got):\n%s", pkgBar, version, diff)
}
@ -767,19 +767,19 @@ func TestFetchAndInsertModule(t *testing.T) {
})
defer teardownProxy()
myModuleV100 := &internal.VersionedPackage{
myModuleV100 := &internal.LegacyVersionedPackage{
ModuleInfo: internal.ModuleInfo{
ModulePath: "github.com/my/module",
Version: "v1.0.0",
CommitTime: testProxyCommitTime,
ReadmeFilePath: "README.md",
ReadmeContents: "README FILE FOR TESTING.",
SourceInfo: source.NewGitHubInfo("https://github.com/my/module", "", "v1.0.0"),
VersionType: "release",
IsRedistributable: true,
HasGoMod: true,
ModulePath: "github.com/my/module",
Version: "v1.0.0",
CommitTime: testProxyCommitTime,
LegacyReadmeFilePath: "README.md",
LegacyReadmeContents: "README FILE FOR TESTING.",
SourceInfo: source.NewGitHubInfo("https://github.com/my/module", "", "v1.0.0"),
VersionType: "release",
IsRedistributable: true,
HasGoMod: true,
},
Package: internal.Package{
LegacyPackage: internal.LegacyPackage{
Path: "github.com/my/module/bar",
Name: "bar",
Synopsis: "package bar",
@ -799,7 +799,7 @@ func TestFetchAndInsertModule(t *testing.T) {
modulePath string
version string
pkg string
want *internal.VersionedPackage
want *internal.LegacyVersionedPackage
moreWantDoc []string // Additional substrings we expect to see in DocumentationHTML.
dontWantDoc []string // Substrings we expect not to see in DocumentationHTML.
}{
@ -821,19 +821,19 @@ func TestFetchAndInsertModule(t *testing.T) {
modulePath: "nonredistributable.mod/module",
version: "v1.0.0",
pkg: "nonredistributable.mod/module/bar/baz",
want: &internal.VersionedPackage{
want: &internal.LegacyVersionedPackage{
ModuleInfo: internal.ModuleInfo{
ModulePath: "nonredistributable.mod/module",
Version: "v1.0.0",
CommitTime: testProxyCommitTime,
ReadmeFilePath: "README.md",
ReadmeContents: "README FILE FOR TESTING.",
VersionType: "release",
SourceInfo: nil,
IsRedistributable: true,
HasGoMod: true,
ModulePath: "nonredistributable.mod/module",
Version: "v1.0.0",
CommitTime: testProxyCommitTime,
LegacyReadmeFilePath: "README.md",
LegacyReadmeContents: "README FILE FOR TESTING.",
VersionType: "release",
SourceInfo: nil,
IsRedistributable: true,
HasGoMod: true,
},
Package: internal.Package{
LegacyPackage: internal.LegacyPackage{
Path: "nonredistributable.mod/module/bar/baz",
Name: "baz",
Synopsis: "package baz",
@ -853,19 +853,19 @@ func TestFetchAndInsertModule(t *testing.T) {
modulePath: "nonredistributable.mod/module",
version: "v1.0.0",
pkg: "nonredistributable.mod/module/foo",
want: &internal.VersionedPackage{
want: &internal.LegacyVersionedPackage{
ModuleInfo: internal.ModuleInfo{
ModulePath: "nonredistributable.mod/module",
Version: "v1.0.0",
CommitTime: testProxyCommitTime,
ReadmeFilePath: "README.md",
ReadmeContents: "README FILE FOR TESTING.",
VersionType: "release",
SourceInfo: nil,
IsRedistributable: true,
HasGoMod: true,
ModulePath: "nonredistributable.mod/module",
Version: "v1.0.0",
CommitTime: testProxyCommitTime,
LegacyReadmeFilePath: "README.md",
LegacyReadmeContents: "README FILE FOR TESTING.",
VersionType: "release",
SourceInfo: nil,
IsRedistributable: true,
HasGoMod: true,
},
Package: internal.Package{
LegacyPackage: internal.LegacyPackage{
Path: "nonredistributable.mod/module/foo",
Name: "foo",
Synopsis: "",
@ -883,19 +883,19 @@ func TestFetchAndInsertModule(t *testing.T) {
modulePath: "std",
version: "v1.12.5",
pkg: "context",
want: &internal.VersionedPackage{
want: &internal.LegacyVersionedPackage{
ModuleInfo: internal.ModuleInfo{
ModulePath: "std",
Version: "v1.12.5",
CommitTime: stdlib.TestCommitTime,
VersionType: "release",
ReadmeFilePath: "README.md",
ReadmeContents: "# The Go Programming Language\n",
SourceInfo: source.NewGitHubInfo(goRepositoryURLPrefix+"/go", "src", "go1.12.5"),
IsRedistributable: true,
HasGoMod: true,
ModulePath: "std",
Version: "v1.12.5",
CommitTime: stdlib.TestCommitTime,
VersionType: "release",
LegacyReadmeFilePath: "README.md",
LegacyReadmeContents: "# The Go Programming Language\n",
SourceInfo: source.NewGitHubInfo(goRepositoryURLPrefix+"/go", "src", "go1.12.5"),
IsRedistributable: true,
HasGoMod: true,
},
Package: internal.Package{
LegacyPackage: internal.LegacyPackage{
Path: "context",
Name: "context",
Synopsis: "Package context defines the Context type, which carries deadlines, cancelation signals, and other request-scoped values across API boundaries and between processes.",
@ -916,19 +916,19 @@ func TestFetchAndInsertModule(t *testing.T) {
modulePath: "std",
version: "v1.12.5",
pkg: "builtin",
want: &internal.VersionedPackage{
want: &internal.LegacyVersionedPackage{
ModuleInfo: internal.ModuleInfo{
ModulePath: "std",
Version: "v1.12.5",
CommitTime: stdlib.TestCommitTime,
VersionType: "release",
ReadmeFilePath: "README.md",
ReadmeContents: "# The Go Programming Language\n",
SourceInfo: source.NewGitHubInfo(goRepositoryURLPrefix+"/go", "src", "go1.12.5"),
IsRedistributable: true,
HasGoMod: true,
ModulePath: "std",
Version: "v1.12.5",
CommitTime: stdlib.TestCommitTime,
VersionType: "release",
LegacyReadmeFilePath: "README.md",
LegacyReadmeContents: "# The Go Programming Language\n",
SourceInfo: source.NewGitHubInfo(goRepositoryURLPrefix+"/go", "src", "go1.12.5"),
IsRedistributable: true,
HasGoMod: true,
},
Package: internal.Package{
LegacyPackage: internal.LegacyPackage{
Path: "builtin",
Name: "builtin",
Synopsis: "Package builtin provides documentation for Go's predeclared identifiers.",
@ -949,19 +949,19 @@ func TestFetchAndInsertModule(t *testing.T) {
modulePath: "std",
version: "v1.12.5",
pkg: "encoding/json",
want: &internal.VersionedPackage{
want: &internal.LegacyVersionedPackage{
ModuleInfo: internal.ModuleInfo{
ModulePath: "std",
Version: "v1.12.5",
CommitTime: stdlib.TestCommitTime,
VersionType: "release",
ReadmeFilePath: "README.md",
ReadmeContents: "# The Go Programming Language\n",
SourceInfo: source.NewGitHubInfo(goRepositoryURLPrefix+"/go", "src", "go1.12.5"),
IsRedistributable: true,
HasGoMod: true,
ModulePath: "std",
Version: "v1.12.5",
CommitTime: stdlib.TestCommitTime,
VersionType: "release",
LegacyReadmeFilePath: "README.md",
LegacyReadmeContents: "# The Go Programming Language\n",
SourceInfo: source.NewGitHubInfo(goRepositoryURLPrefix+"/go", "src", "go1.12.5"),
IsRedistributable: true,
HasGoMod: true,
},
Package: internal.Package{
LegacyPackage: internal.LegacyPackage{
Path: "encoding/json",
Name: "json",
Synopsis: "Package json implements encoding and decoding of JSON as defined in RFC 7159.",
@ -995,7 +995,7 @@ func TestFetchAndInsertModule(t *testing.T) {
modulePath: "build.constraints/module",
version: "v1.0.0",
pkg: "build.constraints/module/cpu",
want: &internal.VersionedPackage{
want: &internal.LegacyVersionedPackage{
ModuleInfo: internal.ModuleInfo{
ModulePath: "build.constraints/module",
Version: "v1.0.0",
@ -1005,7 +1005,7 @@ func TestFetchAndInsertModule(t *testing.T) {
IsRedistributable: true,
HasGoMod: false,
},
Package: internal.Package{
LegacyPackage: internal.LegacyPackage{
Path: "build.constraints/module/cpu",
Name: "cpu",
Synopsis: "Package cpu implements processor feature detection used by the Go standard library.",
@ -1052,7 +1052,7 @@ func TestFetchAndInsertModule(t *testing.T) {
sort.Slice(gotPkg.Licenses, func(i, j int) bool {
return gotPkg.Licenses[i].FilePath < gotPkg.Licenses[j].FilePath
})
if diff := cmp.Diff(test.want, gotPkg, cmpopts.IgnoreFields(internal.Package{}, "DocumentationHTML"), cmp.AllowUnexported(source.Info{})); diff != "" {
if diff := cmp.Diff(test.want, gotPkg, cmpopts.IgnoreFields(internal.LegacyPackage{}, "DocumentationHTML"), cmp.AllowUnexported(source.Info{})); diff != "" {
t.Errorf("testDB.GetPackage(ctx, %q, %q) mismatch (-want +got):\n%s", test.pkg, test.version, diff)
}
if got, want := gotPkg.DocumentationHTML, test.want.DocumentationHTML; len(want) == 0 && len(got) != 0 {