diff options
| author | Julie Qiu <julie@golang.org> | 2020-08-31 21:19:41 -0400 |
|---|---|---|
| committer | Julie Qiu <julie@golang.org> | 2020-09-01 14:40:41 +0000 |
| commit | a327f4f5ecaffa6d82bfe9cf767b10104c2dcd28 (patch) | |
| tree | 5d980802ad466f0fa2841f770cd95919855ba0d1 /internal/postgres/unit_test.go | |
| parent | 4d4b7bf93903cfc8e05824502b05a2721859f292 (diff) | |
| download | go-x-pkgsite-a327f4f5ecaffa6d82bfe9cf767b10104c2dcd28.tar.xz | |
internal: replace Unit.DirectoryMeta with Unit.PathInfo
Unit.DirectoryMeta is replaced with Unit.PathInfo
DirectoryMeta isn't necessary and will be deleted in a future CL.
For golang/go#39629
Change-Id: I521a062207d3f48592d6e949306a015458d1398d
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/251957
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/postgres/unit_test.go')
| -rw-r--r-- | internal/postgres/unit_test.go | 53 |
1 files changed, 20 insertions, 33 deletions
diff --git a/internal/postgres/unit_test.go b/internal/postgres/unit_test.go index 66d001e6..df19493e 100644 --- a/internal/postgres/unit_test.go +++ b/internal/postgres/unit_test.go @@ -276,13 +276,6 @@ func TestGetUnit(t *testing.T) { want: unit("archive/zip", stdlib.ModulePath, "v1.13.4", nil, newPackage("zip", "archive/zip")), }, { - name: "stdlib package - incomplete last element", - path: "archive/zi", - modulePath: stdlib.ModulePath, - version: "v1.13.4", - wantNotFoundErr: true, - }, - { name: "stdlib - internal directory", path: "cmd/internal", modulePath: stdlib.ModulePath, @@ -313,14 +306,13 @@ func TestGetUnit(t *testing.T) { }, } { t.Run(test.name, func(t *testing.T) { - pathInfo := &internal.PathInfo{ - Path: test.path, - ModulePath: test.modulePath, - Version: test.version, - } - if test.want != nil { - pathInfo.Name = test.want.Name - } + pathInfo := sample.PathInfo( + test.path, + test.modulePath, + test.version, + test.want.Name, + true, + ) got, err := testDB.GetUnit(ctx, pathInfo, internal.AllFields) if test.wantNotFoundErr { if !errors.Is(err, derrors.NotFound) { @@ -346,6 +338,7 @@ func TestGetUnit(t *testing.T) { if test.want.Package != nil { test.want.Imports = sample.Imports } + test.want.SourceInfo = pathInfo.SourceInfo if diff := cmp.Diff(test.want, got, opts...); diff != "" { t.Errorf("mismatch (-want, +got):\n%s", diff) } @@ -367,19 +360,11 @@ func TestGetUnitFieldSet(t *testing.T) { cleanFields := func(u *internal.Unit, fields internal.FieldSet) { // Remove fields based on the FieldSet specified. - u.DirectoryMeta = internal.DirectoryMeta{ - Path: u.Path, - IsRedistributable: true, - ModuleInfo: internal.ModuleInfo{ - ModulePath: u.ModulePath, - Version: u.Version, - }, - } if fields&internal.WithImports != 0 { u.Imports = sample.Imports } if u.Package != nil { - u.Package.Name = "" + u.Package.Name = u.Name } } @@ -411,12 +396,13 @@ func TestGetUnitFieldSet(t *testing.T) { }, } { t.Run(test.name, func(t *testing.T) { - pathInfo := &internal.PathInfo{ - Path: test.want.Path, - ModulePath: test.want.ModulePath, - Version: test.want.Version, - IsRedistributable: test.want.IsRedistributable, - } + pathInfo := sample.PathInfo( + test.want.Path, + test.want.ModulePath, + test.want.Version, + test.want.Name, + true, + ) got, err := testDB.GetUnit(ctx, pathInfo, test.fields) if err != nil { t.Fatal(err) @@ -427,6 +413,7 @@ func TestGetUnitFieldSet(t *testing.T) { cmpopts.IgnoreFields(licenses.Metadata{}, "Coverage"), cmpopts.IgnoreFields(internal.DirectoryMeta{}, "PathID"), } + test.want.SourceInfo = pathInfo.SourceInfo cleanFields(test.want, test.fields) if diff := cmp.Diff(test.want, got, opts...); diff != "" { t.Errorf("mismatch (-want, +got):\n%s", diff) @@ -437,8 +424,9 @@ func TestGetUnitFieldSet(t *testing.T) { func unit(path, modulePath, version string, readme *internal.Readme, pkg *internal.Package) *internal.Unit { u := &internal.Unit{ - DirectoryMeta: internal.DirectoryMeta{ - ModuleInfo: *sample.ModuleInfo(modulePath, version), + PathInfo: internal.PathInfo{ + ModulePath: modulePath, + Version: version, Path: path, IsRedistributable: true, Licenses: sample.LicenseMetadata, @@ -512,7 +500,6 @@ func TestGetUnitBypass(t *testing.T) { func findDirectory(m *internal.Module, path string) *internal.Unit { for _, d := range m.Units { - d.ModuleInfo = m.ModuleInfo if d.Path == path { return d } |
