diff options
| author | Jonathan Amsterdam <jba@google.com> | 2020-10-26 10:31:27 -0400 |
|---|---|---|
| committer | Jonathan Amsterdam <jba@google.com> | 2020-10-27 13:19:30 +0000 |
| commit | 90295cd6899f032ee9832f91c200c8e96c437ee8 (patch) | |
| tree | 6e0598e0edd84ec260416941575f3593c1763095 /internal/postgres | |
| parent | 8520d59c35f6c7c3c032a111dc8691b3be7c81ae (diff) | |
| download | go-x-pkgsite-90295cd6899f032ee9832f91c200c8e96c437ee8.tar.xz | |
internal/testing/sample,etc.: add package source
Add encoded source to the sample Documentation value, and render it to
get the documentation HTML. Use the package in
internal/godoc/testdata.
I had hoped to use the godoc package in an init function to create the
needed values, but that caused an import cycle between sample and the
godoc test package. So instead, a small program invoked with `go
generate` uses godoc to generate the values and embed them in a Go
file.
This change required a few other changes:
internal/postgres: Always insert source when comparing Documentation.
internal/frontend: Change the strings we look for in doc to match the
one in the sample package.
internal/frontend: Remove the check on HTML ids. This was added when I
was doing safehtml, when I was being strict about HTML ids. The
safehtml package wants ids to conform to some strict rules to avoid
certain attacks, and I tried to follow those rules. But in the end I
had to be more forgiving, or I would have broken anchor tags to Go
symbols, like pkg.go.dev/fmt#Println. (safehtml does not consider
"Println" a safe identifier unless it is a constant string.)
The checkIDs function was added somewhere in the middle of that
process, and it worked until now because the value of
sample.DocumentationHTML was an ordinary text string with no ids, not
real HTML doc. It was actually only checking the ids for license
files, and those do contain a hyphen. I don't think its loss is
important.
Change-Id: I4019c56b216aaf1a4e92a6167c2af1eef4cfbf89
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/265297
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
Diffstat (limited to 'internal/postgres')
| -rw-r--r-- | internal/postgres/insert_module_test.go | 3 | ||||
| -rw-r--r-- | internal/postgres/search_test.go | 2 | ||||
| -rw-r--r-- | internal/postgres/unit_test.go | 3 |
3 files changed, 6 insertions, 2 deletions
diff --git a/internal/postgres/insert_module_test.go b/internal/postgres/insert_module_test.go index 955011a3..9807091e 100644 --- a/internal/postgres/insert_module_test.go +++ b/internal/postgres/insert_module_test.go @@ -22,6 +22,7 @@ import ( "golang.org/x/pkgsite/internal" "golang.org/x/pkgsite/internal/database" "golang.org/x/pkgsite/internal/derrors" + "golang.org/x/pkgsite/internal/experiment" "golang.org/x/pkgsite/internal/licenses" "golang.org/x/pkgsite/internal/source" "golang.org/x/pkgsite/internal/stdlib" @@ -31,6 +32,7 @@ import ( func TestInsertModule(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout*2) defer cancel() + ctx = experiment.NewContext(ctx, internal.ExperimentInsertPackageSource) for _, test := range []struct { name string @@ -169,6 +171,7 @@ func TestInsertModuleLicenseCheck(t *testing.T) { func TestUpsertModule(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() + ctx = experiment.NewContext(ctx, internal.ExperimentInsertPackageSource) m := sample.Module("upsert.org", "v1.2.3", "dir/p") // Insert the module. diff --git a/internal/postgres/search_test.go b/internal/postgres/search_test.go index e5a82185..b5615664 100644 --- a/internal/postgres/search_test.go +++ b/internal/postgres/search_test.go @@ -294,7 +294,7 @@ func TestSearch(t *testing.T) { for _, test := range tests { t.Run(test.label, func(t *testing.T) { defer ResetTestDB(testDB, t) - ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) defer cancel() for _, m := range test.modules { if err := testDB.InsertModule(ctx, m); err != nil { diff --git a/internal/postgres/unit_test.go b/internal/postgres/unit_test.go index 53603643..b0096353 100644 --- a/internal/postgres/unit_test.go +++ b/internal/postgres/unit_test.go @@ -23,7 +23,7 @@ import ( func TestGetUnit(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() - + ctx = experiment.NewContext(ctx, internal.ExperimentInsertPackageSource) defer ResetTestDB(testDB, t) InsertSampleDirectoryTree(ctx, t, testDB) @@ -208,6 +208,7 @@ func TestGetUnitFieldSet(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() + ctx = experiment.NewContext(ctx, internal.ExperimentInsertPackageSource) defer ResetTestDB(testDB, t) // Add a module that has READMEs in a directory and a package. |
