aboutsummaryrefslogtreecommitdiff
path: root/internal/testing/sample/sample.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/testing/sample/sample.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/testing/sample/sample.go')
-rw-r--r--internal/testing/sample/sample.go31
1 files changed, 13 insertions, 18 deletions
diff --git a/internal/testing/sample/sample.go b/internal/testing/sample/sample.go
index c35cde00..ca88902b 100644
--- a/internal/testing/sample/sample.go
+++ b/internal/testing/sample/sample.go
@@ -17,13 +17,14 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/google/licensecheck"
- "github.com/google/safehtml/template"
"golang.org/x/pkgsite/internal"
"golang.org/x/pkgsite/internal/licenses"
"golang.org/x/pkgsite/internal/source"
"golang.org/x/pkgsite/internal/stdlib"
)
+//go:generate go run gen_documentation.go
+
// These sample values can be used to construct test cases.
var (
ModulePath = "github.com/valid/module_name"
@@ -50,23 +51,16 @@ var (
},
Contents: []byte(`unknown`),
}
- DocumentationHTML = template.MustParseAndExecuteToHTML("This is the documentation HTML")
- PackageName = "foo"
- Suffix = "foo"
- PackagePath = path.Join(ModulePath, Suffix)
- V1Path = PackagePath
- Imports = []string{"path/to/bar", "fmt"}
- Synopsis = "This is a package synopsis"
- ReadmeFilePath = "README.md"
- ReadmeContents = "readme"
- GOOS = "linux"
- GOARCH = "amd64"
- Documentation = &internal.Documentation{
- Synopsis: Synopsis,
- HTML: DocumentationHTML,
- GOOS: GOOS,
- GOARCH: GOARCH,
- }
+ PackageName = "foo"
+ Suffix = "foo"
+ PackagePath = path.Join(ModulePath, Suffix)
+ V1Path = PackagePath
+ Imports = []string{"path/to/bar", "fmt"}
+ Synopsis = "This is a package synopsis"
+ ReadmeFilePath = "README.md"
+ ReadmeContents = "readme"
+ GOOS = "linux"
+ GOARCH = "amd64"
)
// LicenseCmpOpts are options to use when comparing licenses with the cmp package.
@@ -146,6 +140,7 @@ func UnitForPackage(path, modulePath, version, name string, isRedistributable bo
Documentation: &internal.Documentation{
Synopsis: Synopsis,
HTML: DocumentationHTML,
+ Source: DocumentationSource,
GOOS: GOOS,
GOARCH: GOARCH,
},