diff options
| author | Julie Qiu <julie@golang.org> | 2020-09-01 18:52:12 -0400 |
|---|---|---|
| committer | Julie Qiu <julie@golang.org> | 2020-09-02 16:45:25 +0000 |
| commit | 16ca4f2299153124ca2f996b94db92bc98fcebd1 (patch) | |
| tree | 798a3073849cb63b6ac5391b7900a4a1b6dd57df /internal/postgres | |
| parent | afffc195e7586c235e41479ad391babe4f2edb05 (diff) | |
| download | go-x-pkgsite-16ca4f2299153124ca2f996b94db92bc98fcebd1.tar.xz | |
internal: move Unit.Package.Documentation to Unit.Documentation
The Documentation field is moved from Unit.Package.Documentation to
Unit.Documentation. Unit.Package will be deprecated in a later CL.
For golang/go#39629
Change-Id: Idc6d6598a2647a55b55c947120c322fec5da59cc
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/252321
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Diffstat (limited to 'internal/postgres')
| -rw-r--r-- | internal/postgres/insert_module.go | 14 | ||||
| -rw-r--r-- | internal/postgres/insert_module_test.go | 12 | ||||
| -rw-r--r-- | internal/postgres/path_test.go | 6 | ||||
| -rw-r--r-- | internal/postgres/unit.go | 16 | ||||
| -rw-r--r-- | internal/postgres/unit_test.go | 20 |
5 files changed, 29 insertions, 39 deletions
diff --git a/internal/postgres/insert_module.go b/internal/postgres/insert_module.go index 40bcf822..bcfabf06 100644 --- a/internal/postgres/insert_module.go +++ b/internal/postgres/insert_module.go @@ -431,14 +431,12 @@ func insertUnits(ctx context.Context, db *database.DB, m *internal.Module, modul if d.Readme != nil { pathToReadme[d.Path] = d.Readme } - if d.Package != nil { - if d.Package.Documentation != nil && d.Package.Documentation.HTML.String() == internal.StringFieldMissing { - return errors.New("saveModule: package missing Documentation.HTML") - } - pathToDoc[d.Path] = d.Package.Documentation - if len(d.Imports) > 0 { - pathToImports[d.Path] = d.Imports - } + if d.Documentation != nil && d.Documentation.HTML.String() == internal.StringFieldMissing { + return errors.New("saveModule: package missing Documentation.HTML") + } + pathToDoc[d.Path] = d.Documentation + if len(d.Imports) > 0 { + pathToImports[d.Path] = d.Imports } } diff --git a/internal/postgres/insert_module_test.go b/internal/postgres/insert_module_test.go index fd74d67e..d5b717d6 100644 --- a/internal/postgres/insert_module_test.go +++ b/internal/postgres/insert_module_test.go @@ -161,7 +161,7 @@ func TestInsertModuleLicenseCheck(t *testing.T) { mod := sample.Module(sample.ModulePath, sample.VersionString, "") checkHasRedistData(mod.LegacyReadmeContents, mod.LegacyPackages[0].DocumentationHTML, true) - checkHasRedistData(mod.Units[0].Readme.Contents, mod.Units[0].Package.Documentation.HTML, true) + checkHasRedistData(mod.Units[0].Readme.Contents, mod.Units[0].Documentation.HTML, true) mod.IsRedistributable = false mod.LegacyPackages[0].IsRedistributable = false mod.Units[0].IsRedistributable = false @@ -187,17 +187,17 @@ func TestInsertModuleLicenseCheck(t *testing.T) { ModulePath: mod.ModulePath, Version: mod.Version, } - dir, err := db.GetUnit(ctx, pathInfo, internal.AllFields) + u, err := db.GetUnit(ctx, pathInfo, internal.AllFields) if err != nil { t.Fatal(err) } var readme string - if dir.Readme != nil { - readme = dir.Readme.Contents + if u.Readme != nil { + readme = u.Readme.Contents } var doc safehtml.HTML - if dir.Package != nil && dir.Package.Documentation != nil { - doc = dir.Package.Documentation.HTML + if u.Documentation != nil { + doc = u.Documentation.HTML } checkHasRedistData(readme, doc, bypass) }) diff --git a/internal/postgres/path_test.go b/internal/postgres/path_test.go index bcaca35e..86f026a5 100644 --- a/internal/postgres/path_test.go +++ b/internal/postgres/path_test.go @@ -63,10 +63,10 @@ func TestGetUnitMeta(t *testing.T) { } if d == pkgPath { dir.Package = &internal.Package{ - Path: pkgPath, - Name: pkgName, - Documentation: &internal.Documentation{}, + Path: pkgPath, + Name: pkgName, } + dir.Documentation = &internal.Documentation{} } sample.AddUnit(m, dir) } diff --git a/internal/postgres/unit.go b/internal/postgres/unit.go index 59871efd..2e16b7af 100644 --- a/internal/postgres/unit.go +++ b/internal/postgres/unit.go @@ -104,13 +104,7 @@ func (db *DB) GetUnit(ctx context.Context, um *internal.UnitMeta, fields interna if err != nil && !errors.Is(err, derrors.NotFound) { return nil, err } - if doc != nil { - u.Package = &internal.Package{ - Path: u.Path, - Name: u.Name, - Documentation: doc, - } - } + u.Documentation = doc } if fields&internal.WithImports != 0 { imports, err := db.getImports(ctx, pathID) @@ -130,12 +124,10 @@ func (db *DB) GetUnit(ctx context.Context, um *internal.UnitMeta, fields interna } if fields == internal.AllFields { if u.Name != "" { - if u.Package == nil { - u.Package = &internal.Package{ - Path: u.Path, - } + u.Package = &internal.Package{ + Path: u.Path, + Name: u.Name, } - u.Package.Name = u.Name } } if !db.bypassLicenseCheck { diff --git a/internal/postgres/unit_test.go b/internal/postgres/unit_test.go index d2ffe817..855be001 100644 --- a/internal/postgres/unit_test.go +++ b/internal/postgres/unit_test.go @@ -359,16 +359,16 @@ func TestGetUnitFieldSet(t *testing.T) { } cleanFields := func(u *internal.Unit, fields internal.FieldSet) { - // Remove fields based on the FieldSet specified. + // Add/remove fields based on the FieldSet specified. + if fields&internal.WithDocumentation != 0 { + u.Documentation = sample.Documentation + } if fields&internal.WithImports != 0 { u.Imports = sample.Imports } if fields&internal.WithLicenses == 0 { u.LicenseContents = nil } - if u.Package != nil { - u.Package.Name = u.Name - } } for _, test := range []struct { @@ -380,7 +380,7 @@ func TestGetUnitFieldSet(t *testing.T) { name: "WithDocumentation", fields: internal.WithDocumentation, want: unit("a.com/m/dir/p", "a.com/m", "v1.2.3", - nil, newPackage("p", "a.com/m/dir/p")), + nil, nil), }, { name: "WithImports", @@ -445,6 +445,7 @@ func unit(path, modulePath, version string, readme *internal.Readme, pkg *intern Package: pkg, } if pkg != nil { + u.Documentation = sample.Documentation u.Name = pkg.Name } return u @@ -452,9 +453,8 @@ func unit(path, modulePath, version string, readme *internal.Readme, pkg *intern func newPackage(name, path string) *internal.Package { return &internal.Package{ - Name: name, - Path: path, - Documentation: sample.Documentation, + Name: name, + Path: path, } } @@ -488,10 +488,10 @@ func TestGetUnitBypass(t *testing.T) { if got := (d.Readme == nil); got != test.wantEmpty { t.Errorf("readme empty: got %t, want %t", got, test.wantEmpty) } - if got := (d.Package.Documentation == nil); got != test.wantEmpty { + if got := (d.Documentation == nil); got != test.wantEmpty { t.Errorf("synopsis empty: got %t, want %t", got, test.wantEmpty) } - if got := (d.Package.Documentation == nil); got != test.wantEmpty { + if got := (d.Documentation == nil); got != test.wantEmpty { t.Errorf("doc empty: got %t, want %t", got, test.wantEmpty) } |
