aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitri Shuralyov <dmitshur@golang.org>2026-03-18 13:39:07 -0400
committerGopher Robot <gobot@golang.org>2026-03-25 10:58:32 -0700
commitfa8efe0a928a3eee560a473fed190614b7d711e3 (patch)
tree012da3a96b91d3661fff32d5d013db7c04b0d48a
parent914537a3dacb58e0b7189623c40a1ac6b4cec132 (diff)
downloadgo-x-website-fa8efe0a928a3eee560a473fed190614b7d711e3.tar.xz
cmd/golangorg: support absolute paths in testTree
The use of strings.TrimPrefix on filepath.ToSlash output works on all OSes when testTree is given a relative path like "../../_content", but it doesn't work on Windows if testTree is given an absolute path. The next change will do that (in order to process GOROOT/doc content), so prepare for it by migrating to filepath.Rel to compute relative path. For golang/go#78211. Change-Id: I2117d916e1c4112bfbd667597e32622039040dd0 Reviewed-on: https://go-review.googlesource.com/c/website/+/756501 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Alan Donovan <adonovan@google.com> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
-rw-r--r--cmd/golangorg/server_test.go19
1 files changed, 12 insertions, 7 deletions
diff --git a/cmd/golangorg/server_test.go b/cmd/golangorg/server_test.go
index 8ec9de15..ec2d2f73 100644
--- a/cmd/golangorg/server_test.go
+++ b/cmd/golangorg/server_test.go
@@ -106,7 +106,7 @@ func TestAll(t *testing.T) {
"/play/p/",
}
- // Do not process these paths or path prefixes.
+ // Do not process these path prefixes.
ignores := []string{
// The Wiki and gopls are in different repos;
// errors there should not block production push.
@@ -124,25 +124,30 @@ func TestAll(t *testing.T) {
// Otherwise we recheck all the URLs in the page frames for every page.
checked := make(map[string]bool)
- testTree := func(dir, prefix string) {
+ testTree := func(dir, baseURL string) {
filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil {
t.Fatal(err)
}
- path = filepath.ToSlash(path)
- siteURL := strings.TrimPrefix(path, dir)
+ rel, err := filepath.Rel(dir, path)
+ if err != nil {
+ t.Fatal(err)
+ }
+ siteURL, err := url.JoinPath(baseURL, filepath.ToSlash(rel))
+ if err != nil {
+ t.Fatal(err)
+ }
for _, ig := range ignores {
- if strings.HasPrefix(siteURL, ig) {
+ if strings.HasPrefix(siteURL, "https://go.dev"+ig) {
return nil
}
}
- siteURL = prefix + siteURL // add https://go.dev/
if strings.HasSuffix(path, ".md") ||
strings.HasSuffix(path, ".html") ||
strings.HasSuffix(path, ".article") ||
strings.HasSuffix(path, ".slide") {
- if !strings.Contains(path, "/talks/") {
+ if !strings.Contains(filepath.ToSlash(path), "/talks/") {
siteURL = strings.TrimSuffix(siteURL, pathpkg.Ext(path))
}
if strings.HasSuffix(siteURL, "/index") {