diff options
| author | Julie Qiu <julie@golang.org> | 2020-09-01 22:40:52 -0400 |
|---|---|---|
| committer | Julie Qiu <julie@golang.org> | 2020-09-02 16:46:14 +0000 |
| commit | d0a182d328c2ca96a505dcafe29f197526d897a4 (patch) | |
| tree | 50fa885931506afacfd8fb9a470ee7d68af7b6d6 /internal/fetch | |
| parent | 16ca4f2299153124ca2f996b94db92bc98fcebd1 (diff) | |
| download | go-x-pkgsite-d0a182d328c2ca96a505dcafe29f197526d897a4.tar.xz | |
internal: remove Unit.Package
Unit.Pacakge is removed, since it isn't need for anything.
For golang/go#39629
Change-Id: Ic620603550874de8a0b4c37c67a88bee65ec7933
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/252323
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Diffstat (limited to 'internal/fetch')
| -rw-r--r-- | internal/fetch/directory.go | 4 | ||||
| -rw-r--r-- | internal/fetch/fetchdata_test.go | 88 | ||||
| -rw-r--r-- | internal/fetch/test_helper.go | 47 |
3 files changed, 45 insertions, 94 deletions
diff --git a/internal/fetch/directory.go b/internal/fetch/directory.go index 9d958e17..b1a8003a 100644 --- a/internal/fetch/directory.go +++ b/internal/fetch/directory.go @@ -60,10 +60,6 @@ func moduleUnits(modulePath, version string, } if pkg, ok := pkgLookup[dirPath]; ok { dir.Name = pkg.Name - dir.Package = &internal.Package{ - Path: pkg.Path, - Name: pkg.Name, - } dir.Imports = pkg.Imports dir.Documentation = &internal.Documentation{ GOOS: pkg.GOOS, diff --git a/internal/fetch/fetchdata_test.go b/internal/fetch/fetchdata_test.go index 5df28942..c3ee36bd 100644 --- a/internal/fetch/fetchdata_test.go +++ b/internal/fetch/fetchdata_test.go @@ -53,14 +53,12 @@ var moduleOnePackage = &testModule{ }, { UnitMeta: internal.UnitMeta{ + Name: "foo", Path: "github.com/basic/foo", }, Documentation: &internal.Documentation{ Synopsis: "package foo exports a helpful constant.", }, - Package: &internal.Package{ - Name: "foo", - }, Imports: []string{"net/http"}, }, }, @@ -127,15 +125,13 @@ var moduleMultiPackage = &testModule{ }, { UnitMeta: internal.UnitMeta{ + Name: "bar", Path: "github.com/my/module/bar", }, Readme: &internal.Readme{ Filepath: "bar/README.md", Contents: "Another README FILE FOR TESTING.", }, - Package: &internal.Package{ - Name: "bar", - }, Documentation: &internal.Documentation{ Synopsis: "package bar", HTML: html("Bar returns the string "bar"."), @@ -143,10 +139,8 @@ var moduleMultiPackage = &testModule{ }, { UnitMeta: internal.UnitMeta{ - Path: "github.com/my/module/foo", - }, - Package: &internal.Package{ Name: "foo", + Path: "github.com/my/module/foo", }, Documentation: &internal.Documentation{ Synopsis: "package foo", @@ -189,10 +183,8 @@ var moduleNoGoMod = &testModule{ }, { UnitMeta: internal.UnitMeta{ - Path: "no.mod/module/p", - }, - Package: &internal.Package{ Name: "p", + Path: "no.mod/module/p", }, Documentation: &internal.Documentation{ Synopsis: "Package p is inside a module where a go.mod file hasn't been explicitly added yet.", @@ -254,10 +246,8 @@ var moduleBadPackages = &testModule{ }, { UnitMeta: internal.UnitMeta{ - Path: "bad.mod/module/good", - }, - Package: &internal.Package{ Name: "good", + Path: "bad.mod/module/good", }, Documentation: &internal.Documentation{ Synopsis: "Package good is inside a module that has bad packages.", @@ -321,10 +311,8 @@ var moduleBuildConstraints = &testModule{ }, { UnitMeta: internal.UnitMeta{ - Path: "build.constraints/module/cpu", - }, - Package: &internal.Package{ Name: "cpu", + Path: "build.constraints/module/cpu", }, Documentation: &internal.Documentation{ Synopsis: "Package cpu implements processor feature detection used by the Go standard library.", @@ -416,10 +404,8 @@ var moduleNonRedist = &testModule{ }, { UnitMeta: internal.UnitMeta{ - Path: "nonredistributable.mod/module/bar", - }, - Package: &internal.Package{ Name: "bar", + Path: "nonredistributable.mod/module/bar", }, Documentation: &internal.Documentation{ Synopsis: "package bar", @@ -428,10 +414,8 @@ var moduleNonRedist = &testModule{ }, { UnitMeta: internal.UnitMeta{ - Path: "nonredistributable.mod/module/bar/baz", - }, - Package: &internal.Package{ Name: "baz", + Path: "nonredistributable.mod/module/bar/baz", }, Documentation: &internal.Documentation{ Synopsis: "package baz", @@ -440,15 +424,13 @@ var moduleNonRedist = &testModule{ }, { UnitMeta: internal.UnitMeta{ + Name: "foo", Path: "nonredistributable.mod/module/foo", }, Readme: &internal.Readme{ Filepath: "foo/README.md", Contents: "README FILE SHOW UP HERE BUT WILL BE REMOVED BEFORE DB INSERT", }, - Package: &internal.Package{ - Name: "foo", - }, Documentation: &internal.Documentation{ Synopsis: "package foo", HTML: html("FooBar returns the string"), @@ -494,10 +476,8 @@ var moduleBadImportPath = &testModule{ }, { UnitMeta: internal.UnitMeta{ - Path: "bad.import.path.com/good/import/path", - }, - Package: &internal.Package{ Name: "foo", + Path: "bad.import.path.com/good/import/path", }, Documentation: &internal.Documentation{}, }, @@ -556,10 +536,8 @@ var moduleDocTest = &testModule{ }, { UnitMeta: internal.UnitMeta{ - Path: "doc.test/permalink", - }, - Package: &internal.Package{ Name: "permalink", + Path: "doc.test/permalink", }, Documentation: &internal.Documentation{ Synopsis: "Package permalink is for testing the heading permalink documentation rendering feature.", @@ -594,10 +572,8 @@ var moduleDocTooLarge = &testModule{ Units: []*internal.Unit{ { UnitMeta: internal.UnitMeta{ - Path: "bigdoc.test", - }, - Package: &internal.Package{ Name: "bigdoc", + Path: "bigdoc.test", }, Documentation: &internal.Documentation{ Synopsis: "This documentation is big.", @@ -654,10 +630,8 @@ var moduleWasm = &testModule{ }, { UnitMeta: internal.UnitMeta{ - Path: "github.com/my/module/js/js", - }, - Package: &internal.Package{ Name: "js", + Path: "github.com/my/module/js/js", }, Documentation: &internal.Documentation{ Synopsis: "Package js only works with wasm.", @@ -712,10 +686,8 @@ var moduleStd = &testModule{ }, { UnitMeta: internal.UnitMeta{ - Path: "builtin", - }, - Package: &internal.Package{ Name: "builtin", + Path: "builtin", }, Documentation: &internal.Documentation{ Synopsis: "Package builtin provides documentation for Go's predeclared identifiers.", @@ -728,15 +700,13 @@ var moduleStd = &testModule{ }, { UnitMeta: internal.UnitMeta{ + Name: "main", Path: "cmd/pprof", }, Readme: &internal.Readme{ Filepath: "cmd/pprof/README", Contents: "This directory is the copy of Google's pprof shipped as part of the Go distribution.\n", }, - Package: &internal.Package{ - Name: "main", - }, Documentation: &internal.Documentation{ Synopsis: "Pprof interprets and displays profiles of Go programs.", }, @@ -762,10 +732,8 @@ var moduleStd = &testModule{ }, { UnitMeta: internal.UnitMeta{ - Path: "context", - }, - Package: &internal.Package{ Name: "context", + Path: "context", }, Documentation: &internal.Documentation{ Synopsis: "Package context defines the Context type, which carries deadlines, cancelation signals, and other request-scoped values across API boundaries and between processes.", @@ -779,10 +747,8 @@ var moduleStd = &testModule{ }, { UnitMeta: internal.UnitMeta{ - Path: "encoding/json", - }, - Package: &internal.Package{ Name: "json", + Path: "encoding/json", }, Documentation: &internal.Documentation{ Synopsis: "Package json implements encoding and decoding of JSON as defined in RFC 7159.", @@ -807,10 +773,8 @@ var moduleStd = &testModule{ }, { UnitMeta: internal.UnitMeta{ - Path: "errors", - }, - Package: &internal.Package{ Name: "errors", + Path: "errors", }, Documentation: &internal.Documentation{ Synopsis: "Package errors implements functions to manipulate errors.", @@ -818,12 +782,10 @@ var moduleStd = &testModule{ }, { UnitMeta: internal.UnitMeta{ + Name: "flag", Path: "flag", }, Imports: []string{"errors", "fmt", "io", "os", "reflect", "sort", "strconv", "strings", "time"}, - Package: &internal.Package{ - Name: "flag", - }, Documentation: &internal.Documentation{ Synopsis: "Package flag implements command-line flag parsing.", }, @@ -859,10 +821,8 @@ var moduleMaster = &testModule{ }, { UnitMeta: internal.UnitMeta{ - Path: "github.com/my/module/foo", - }, - Package: &internal.Package{ Name: "foo", + Path: "github.com/my/module/foo", }, Documentation: &internal.Documentation{ Synopsis: "package foo exports a helpful constant.", @@ -899,10 +859,8 @@ var moduleLatest = &testModule{ }, { UnitMeta: internal.UnitMeta{ - Path: "github.com/my/module/foo", - }, - Package: &internal.Package{ Name: "foo", + Path: "github.com/my/module/foo", }, Documentation: &internal.Documentation{ Synopsis: "package foo exports a helpful constant.", @@ -953,10 +911,8 @@ package example_test }, { UnitMeta: internal.UnitMeta{ - Path: path + "/example", - }, - Package: &internal.Package{ Name: "example", + Path: path + "/example", }, Documentation: &internal.Documentation{ Synopsis: "Package example contains examples.", diff --git a/internal/fetch/test_helper.go b/internal/fetch/test_helper.go index 76727df0..dcd0f964 100644 --- a/internal/fetch/test_helper.go +++ b/internal/fetch/test_helper.go @@ -57,39 +57,38 @@ func cleanFetchResult(fr *FetchResult, detector *licenses.Detector) *FetchResult } shouldSetPVS := (fr.PackageVersionStates == nil) - for _, dir := range fr.Module.Units { - dir.UnitMeta = internal.UnitMeta{ + for _, u := range fr.Module.Units { + u.UnitMeta = internal.UnitMeta{ ModulePath: fr.Module.ModulePath, Version: fr.Module.Version, - Path: dir.Path, - IsRedistributable: dir.IsRedistributable, - Licenses: dir.Licenses, + Path: u.Path, + Name: u.Name, + IsRedistributable: u.IsRedistributable, + Licenses: u.Licenses, } - if dir.Documentation != nil { - if dir.Documentation.GOOS == "" { - dir.Documentation.GOOS = "linux" - dir.Documentation.GOARCH = "amd64" + if u.Documentation != nil { + if u.Documentation.GOOS == "" { + u.Documentation.GOOS = "linux" + u.Documentation.GOARCH = "amd64" } } - if dir.Package != nil { - dir.Name = dir.Package.Name - dir.Package.Path = dir.Path + if u.Name != "" { fr.Module.LegacyPackages = append(fr.Module.LegacyPackages, &internal.LegacyPackage{ - Path: dir.Path, - Licenses: dir.Licenses, - V1Path: internal.V1Path(dir.Path, dir.ModulePath), - Name: dir.Package.Name, - Synopsis: dir.Documentation.Synopsis, - DocumentationHTML: dir.Documentation.HTML, - Imports: dir.Imports, - GOOS: dir.Documentation.GOOS, - GOARCH: dir.Documentation.GOARCH, - IsRedistributable: dir.IsRedistributable, + Path: u.Path, + Licenses: u.Licenses, + V1Path: internal.V1Path(u.Path, u.ModulePath), + Name: u.Name, + Synopsis: u.Documentation.Synopsis, + DocumentationHTML: u.Documentation.HTML, + Imports: u.Imports, + GOOS: u.Documentation.GOOS, + GOARCH: u.Documentation.GOARCH, + IsRedistributable: u.IsRedistributable, }) if shouldSetPVS { fr.PackageVersionStates = append( fr.PackageVersionStates, &internal.PackageVersionState{ - PackagePath: dir.Path, + PackagePath: u.Path, ModulePath: fr.Module.ModulePath, Version: fr.Module.Version, Status: http.StatusOK, @@ -176,7 +175,7 @@ func validateDocumentationHTML(t *testing.T, got, want *internal.Module) { checkHTML("LegacyPackages", i, got.LegacyPackages[i].DocumentationHTML, want.LegacyPackages[i].DocumentationHTML) } for i := 0; i < len(want.Units); i++ { - if want.Units[i].Package == nil { + if !want.Units[i].IsPackage() { continue } checkHTML("Directories", i, got.Units[i].Documentation.HTML, want.Units[i].Documentation.HTML) |
