diff options
| author | Julie Qiu <julie@golang.org> | 2020-09-30 10:43:47 -0400 |
|---|---|---|
| committer | Julie Qiu <julie@golang.org> | 2020-09-30 16:44:53 +0000 |
| commit | 6cce679a76cb91b02426bd4d37689a6e4958d017 (patch) | |
| tree | 4d767e52e8eb25d147cf942138c2917e54d2deb7 /internal/postgres/unit_test.go | |
| parent | 183e9ae7f1cda25a9277aa82fba0db41363611d6 (diff) | |
| download | go-x-pkgsite-6cce679a76cb91b02426bd4d37689a6e4958d017.tar.xz | |
internal/postgres: support README in subdirectories
When the unit-page experiment is on, GetUnit will return the README for
that path, instead of the one that the module root.
For golang/go#38513
For golang/go#39629
Change-Id: I7a7bcb5762c614e5abb828b3d530207d24562339
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/258314
Run-TryBot: Julie Qiu <julie@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Trust: Julie Qiu <julie@golang.org>
Diffstat (limited to 'internal/postgres/unit_test.go')
| -rw-r--r-- | internal/postgres/unit_test.go | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/internal/postgres/unit_test.go b/internal/postgres/unit_test.go index d0ee8e6e..cdc83e57 100644 --- a/internal/postgres/unit_test.go +++ b/internal/postgres/unit_test.go @@ -13,6 +13,7 @@ import ( "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/safehtml" "golang.org/x/pkgsite/internal" + "golang.org/x/pkgsite/internal/experiment" "golang.org/x/pkgsite/internal/licenses" "golang.org/x/pkgsite/internal/source" "golang.org/x/pkgsite/internal/stdlib" @@ -160,29 +161,38 @@ func TestGetUnit(t *testing.T) { test.want.Name, test.want.IsRedistributable, ) - got, err := testDB.GetUnit(ctx, um, internal.AllFields) - if err != nil { - t.Fatal(err) - } - opts := []cmp.Option{ - cmp.AllowUnexported(source.Info{}, safehtml.HTML{}), - // The packages table only includes partial license information; it omits the Coverage field. - cmpopts.IgnoreFields(licenses.Metadata{}, "Coverage"), - } - // TODO(golang/go#38513): remove once we start displaying - // READMEs for directories instead of the top-level module. - test.want.Readme = &internal.Readme{ - Filepath: sample.ReadmeFilePath, - Contents: sample.ReadmeContents, - } - test.want.SourceInfo = um.SourceInfo - if diff := cmp.Diff(test.want, got, opts...); diff != "" { - t.Errorf("mismatch (-want, +got):\n%s", diff) - } + t.Run("unit-page", func(t *testing.T) { + checkUnit(ctx, t, um, test.want, internal.ExperimentUnitPage) + }) + t.Run("no-experiments", func(t *testing.T) { + test.want.Readme = &internal.Readme{ + Filepath: sample.ReadmeFilePath, + Contents: sample.ReadmeContents, + } + checkUnit(ctx, t, um, test.want) + }) }) } } +func checkUnit(ctx context.Context, t *testing.T, um *internal.UnitMeta, want *internal.Unit, experiments ...string) { + t.Helper() + ctx = experiment.NewContext(ctx, experiments...) + got, err := testDB.GetUnit(ctx, um, internal.AllFields) + if err != nil { + t.Fatal(err) + } + opts := []cmp.Option{ + cmp.AllowUnexported(source.Info{}, safehtml.HTML{}), + // The packages table only includes partial license information; it omits the Coverage field. + cmpopts.IgnoreFields(licenses.Metadata{}, "Coverage"), + } + want.SourceInfo = um.SourceInfo + if diff := cmp.Diff(want, got, opts...); diff != "" { + t.Errorf("mismatch (-want, +got):\n%s", diff) + } +} + func TestGetUnitFieldSet(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() |
