aboutsummaryrefslogtreecommitdiff
path: root/internal/postgres/insert_module_test.go
diff options
context:
space:
mode:
authorJonathan Amsterdam <jba@google.com>2020-10-26 10:31:27 -0400
committerJonathan Amsterdam <jba@google.com>2020-10-27 13:19:30 +0000
commit90295cd6899f032ee9832f91c200c8e96c437ee8 (patch)
tree6e0598e0edd84ec260416941575f3593c1763095 /internal/postgres/insert_module_test.go
parent8520d59c35f6c7c3c032a111dc8691b3be7c81ae (diff)
downloadgo-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/insert_module_test.go')
-rw-r--r--internal/postgres/insert_module_test.go3
1 files changed, 3 insertions, 0 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.