aboutsummaryrefslogtreecommitdiff
path: root/internal/testing/sample
diff options
context:
space:
mode:
authorJulie Qiu <julie@golang.org>2020-09-01 18:28:33 -0400
committerJulie Qiu <julie@golang.org>2020-09-02 16:44:36 +0000
commitf3921260647d8723941e6a2a43fcd07811ef2dfd (patch)
tree27e1d7449947dbe3becbb687f253f4583a3fd5f6 /internal/testing/sample
parentad8f77e99098805b3d7eff12ffc55c63136a55f8 (diff)
downloadgo-x-pkgsite-f3921260647d8723941e6a2a43fcd07811ef2dfd.tar.xz
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 <julie@golang.org> TryBot-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Jonathan Amsterdam <jba@google.com>
Diffstat (limited to 'internal/testing/sample')
-rw-r--r--internal/testing/sample/sample.go30
1 files changed, 17 insertions, 13 deletions
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,