From f3921260647d8723941e6a2a43fcd07811ef2dfd Mon Sep 17 00:00:00 2001 From: Julie Qiu Date: Tue, 1 Sep 2020 18:28:33 -0400 Subject: internal/postgres: add WithLicenses to GetUnit GetUnit now supports the WithLicenses fieldset, which fetches license contents for the unit. For golang/go#39629 Change-Id: Ic51baf1d36e75c7ad05c59d232f400a756fb7a94 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/252318 Run-TryBot: Julie Qiu TryBot-Result: kokoro Reviewed-by: Jonathan Amsterdam --- internal/testing/sample/sample.go | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'internal/testing/sample/sample.go') diff --git a/internal/testing/sample/sample.go b/internal/testing/sample/sample.go index bbe70832..1096093d 100644 --- a/internal/testing/sample/sample.go +++ b/internal/testing/sample/sample.go @@ -217,8 +217,8 @@ func AddPackage(m *internal.Module, p *internal.LegacyPackage) *internal.Module } for pth := p.Path; len(pth) > minLen; pth = path.Dir(pth) { found := false - for _, d := range m.Units { - if d.Path == pth { + for _, u := range m.Units { + if u.Path == pth { found = true break } @@ -230,13 +230,13 @@ func AddPackage(m *internal.Module, p *internal.LegacyPackage) *internal.Module return m } -func AddUnit(m *internal.Module, d *internal.Unit) { +func AddUnit(m *internal.Module, u *internal.Unit) { for _, e := range m.Units { - if e.Path == d.Path { + if e.Path == u.Path { panic(fmt.Sprintf("module already has path %q", e.Path)) } } - m.Units = append(m.Units, d) + m.Units = append(m.Units, u) } func AddLicense(m *internal.Module, lic *licenses.License) { @@ -245,9 +245,9 @@ func AddLicense(m *internal.Module, lic *licenses.License) { if dir == "." { dir = "" } - for _, d := range m.Units { - if strings.TrimPrefix(d.Path, m.ModulePath+"/") == dir { - d.Licenses = append(d.Licenses, lic.Metadata) + for _, u := range m.Units { + if strings.TrimPrefix(u.Path, m.ModulePath+"/") == dir { + u.Licenses = append(u.Licenses, lic.Metadata) } } } @@ -259,20 +259,24 @@ func UnitEmpty(path, modulePath, version string) *internal.Unit { } func UnitForModuleRoot(m *internal.LegacyModuleInfo, licenses []*licenses.Metadata) *internal.Unit { - d := &internal.Unit{UnitMeta: *UnitMeta(m.ModulePath, m.ModulePath, m.Version, "", m.IsRedistributable)} + u := &internal.Unit{ + UnitMeta: *UnitMeta(m.ModulePath, m.ModulePath, m.Version, "", m.IsRedistributable), + LicenseContents: Licenses, + } if m.LegacyReadmeFilePath != "" { - d.Readme = &internal.Readme{ + u.Readme = &internal.Readme{ Filepath: m.LegacyReadmeFilePath, Contents: m.LegacyReadmeContents, } } - return d + return u } func UnitForPackage(pkg *internal.LegacyPackage, modulePath, version string) *internal.Unit { return &internal.Unit{ - UnitMeta: *UnitMeta(pkg.Path, modulePath, version, pkg.Name, pkg.IsRedistributable), - Imports: pkg.Imports, + UnitMeta: *UnitMeta(pkg.Path, modulePath, version, pkg.Name, pkg.IsRedistributable), + Imports: pkg.Imports, + LicenseContents: Licenses, Package: &internal.Package{ Name: pkg.Name, Path: pkg.Path, -- cgit v1.3-6-g1900