From fa8efe0a928a3eee560a473fed190614b7d711e3 Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Wed, 18 Mar 2026 13:39:07 -0400 Subject: 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 Reviewed-by: Alan Donovan Auto-Submit: Dmitri Shuralyov LUCI-TryBot-Result: Go LUCI --- cmd/golangorg/server_test.go | 19 ++++++++++++------- 1 file 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") { -- cgit v1.3