aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2021-11-09 12:48:49 -0500
committerRuss Cox <rsc@golang.org>2021-11-17 17:47:58 +0000
commit4209fd81f5a925f19309bb3331347e5a5d98694c (patch)
tree81004c10737ec536554c0045b934e692e9498d25 /cmd
parent0473aa5d479bcfc58e5769408c53b00a4a35bde1 (diff)
downloadgo-x-website-4209fd81f5a925f19309bb3331347e5a5d98694c.tar.xz
internal/dl: make download page testable offline
Added a copy of the datastore content for use offline. This lets us test download page rendering locally. Preparation for the golang.org -> go.dev move. Change-Id: Ic0c49a96329eed4310dd91e03c4ea832189ef65a Reviewed-on: https://go-review.googlesource.com/c/website/+/362496 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Jamal Carvalho <jamal@golang.org>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/golangorg/server.go24
-rw-r--r--cmd/golangorg/testdata/live.txt7
-rw-r--r--cmd/golangorg/testdata/web.txt7
3 files changed, 20 insertions, 18 deletions
diff --git a/cmd/golangorg/server.go b/cmd/golangorg/server.go
index 0e396acd..0859deca 100644
--- a/cmd/golangorg/server.go
+++ b/cmd/golangorg/server.go
@@ -193,13 +193,8 @@ func NewHandler(contentDir, goroot string) http.Handler {
io.WriteString(w, "User-agent: *\nDisallow: /search\n")
})
- if runningOnAppEngine {
- appEngineSetup(site, chinaSite, mux)
- }
-
- // Register a redirect handler for /dl/ to the golang.org download page.
+ // Register a redirect handler for tip.golang.org/dl/ to the golang.org download page.
// (golang.org/dl and golang.google.cn/dl are registered separately.)
- mux.Handle("/dl/", http.RedirectHandler("https://golang.org/dl/", http.StatusFound))
mux.Handle("tip.golang.org/dl/", http.RedirectHandler("https://golang.org/dl/", http.StatusFound))
godev, err := godevHandler(godevFS)
@@ -211,6 +206,12 @@ func NewHandler(contentDir, goroot string) http.Handler {
mux.Handle("blog.golang.org/", redirectPrefix("https://go.dev/blog/"))
mux.Handle("learn.go.dev/", redirectPrefix("https://go.dev/learn/"))
+ if runningOnAppEngine {
+ appEngineSetup(site, chinaSite, mux)
+ }
+ dl.RegisterHandlers(mux, site, "golang.org", datastoreClient, memcacheClient)
+ dl.RegisterHandlers(mux, chinaSite, "golang.google.cn", datastoreClient, memcacheClient)
+
var h http.Handler = mux
h = hostEnforcerHandler(h)
h = hostPathHandler(h)
@@ -307,12 +308,16 @@ func watchTip1(tipGoroot *atomicFS) {
}
}
+var datastoreClient *datastore.Client
+var memcacheClient *memcache.Client
+
func appEngineSetup(site, chinaSite *web.Site, mux *http.ServeMux) {
googleAnalytics = os.Getenv("GOLANGORG_ANALYTICS")
ctx := context.Background()
- datastoreClient, err := datastore.NewClient(ctx, "")
+ var err error
+ datastoreClient, err = datastore.NewClient(ctx, "")
if err != nil {
if strings.Contains(err.Error(), "missing project") {
log.Fatalf("Missing datastore project. Set the DATASTORE_PROJECT_ID env variable. Use `gcloud beta emulators datastore` to start a local datastore.")
@@ -324,10 +329,7 @@ func appEngineSetup(site, chinaSite *web.Site, mux *http.ServeMux) {
if redisAddr == "" {
log.Fatalf("Missing redis server for golangorg in production mode. set GOLANGORG_REDIS_ADDR environment variable.")
}
- memcacheClient := memcache.New(redisAddr)
-
- dl.RegisterHandlers(mux, site, "golang.org", datastoreClient, memcacheClient)
- dl.RegisterHandlers(mux, chinaSite, "golang.google.cn", datastoreClient, memcacheClient)
+ memcacheClient = memcache.New(redisAddr)
short.RegisterHandlers(mux, datastoreClient, memcacheClient)
proxy.RegisterHandlers(mux, googleCN)
diff --git a/cmd/golangorg/testdata/live.txt b/cmd/golangorg/testdata/live.txt
index f31a4c7a..b78cfaf4 100644
--- a/cmd/golangorg/testdata/live.txt
+++ b/cmd/golangorg/testdata/live.txt
@@ -1,13 +1,6 @@
# Tests that can only run against the live server,
# because they depend on production resources.
-GET https://golang.org/dl/
-body contains href="/dl/go1.11.windows-amd64.msi"
-
-GET https://golang.org/dl/?mode=json
-body contains .windows-amd64.msi
-body !contains UA-
-
GET https://golang.org/s/go2design
code == 302
body ~ proposal.*Found
diff --git a/cmd/golangorg/testdata/web.txt b/cmd/golangorg/testdata/web.txt
index 685144fb..002f2af4 100644
--- a/cmd/golangorg/testdata/web.txt
+++ b/cmd/golangorg/testdata/web.txt
@@ -227,3 +227,10 @@ body contains Controls the set of version control tools
GET https://golang.org/asdf
code == 404
body ~ <span class="alert" style="font-size:120%">open (../../_content/)?asdf: (.*)</span>
+
+GET https://golang.org/dl/
+body contains href="/dl/go1.11.windows-amd64.msi"
+
+GET https://golang.org/dl/?mode=json
+body contains .windows-amd64.msi
+body !contains UA-