]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fix tests when go.env sets GOPROXY=direct GOSUMDB=off
authorBryan C. Mills <bcmills@google.com>
Fri, 14 Jul 2023 18:50:37 +0000 (14:50 -0400)
committerGopher Robot <gobot@golang.org>
Mon, 17 Jul 2023 18:25:37 +0000 (18:25 +0000)
Tested locally by changing GOROOT/go.env. At some point perhaps we
should also set up a builder that runs with some common expected
modifications to go.env
(such as GOTOOLCHAIN=local GOPROXY=direct GOSUMDB=off).

Fixes #61358.
Updates #61359.

Change-Id: I365ec536bec86370e302fb726fa897400ab42cf3
Reviewed-on: https://go-review.googlesource.com/c/go/+/509637
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>

src/cmd/go/scriptconds_test.go
src/cmd/go/testdata/script/README
src/cmd/go/testdata/script/gotoolchain_net.txt
src/cmd/go/testdata/script/gotoolchain_version.txt
src/cmd/go/testdata/script/mod_prefer_compatible.txt
src/cmd/go/testdata/script/mod_sumdb_file_path.txt
src/cmd/go/testdata/script/mod_sumdb_golang.txt

index 641f69f312bf1f763794bd302b5450d1334bfe0d..8dd9b0d1cd1a971ba4a87124b31cb960e29c82c6 100644 (file)
@@ -49,6 +49,7 @@ func scriptConditions() map[string]script.Cond {
        add("git", lazyBool("the 'git' executable exists and provides the standard CLI", hasWorkingGit))
        add("GODEBUG", script.PrefixCondition("GODEBUG contains <suffix>", hasGodebug))
        add("GOEXPERIMENT", script.PrefixCondition("GOEXPERIMENT <suffix> is enabled", hasGoexperiment))
+       add("go-builder", script.BoolCondition("GO_BUILDER_NAME is non-empty", testenv.Builder() != ""))
        add("link", lazyBool("testenv.HasLink()", testenv.HasLink))
        add("mismatched-goroot", script.Condition("test's GOROOT_FINAL does not match the real GOROOT", isMismatchedGoroot))
        add("msan", sysCondition("-msan", platform.MSanSupported, true))
index b7215e8f4f5c4f2ad024617ab4705821554ea1cf..792a158760f6f50c16bcd740df8ba9c2d17b8bca 100644 (file)
@@ -398,6 +398,8 @@ The available conditions are:
        GOOS/GOARCH supports -fuzz with instrumentation
 [git]
        the 'git' executable exists and provides the standard CLI
+[go-builder]
+       GO_BUILDER_NAME is non-empty
 [link]
        testenv.HasLink()
 [mismatched-goroot]
index 72bb2b72526980aaa0e000ce2f38839d22df8b1e..35f66964546c9f4c5efe2ebd2bcfe2778b1e244e 100644 (file)
@@ -43,11 +43,13 @@ env GOSUMDB=$oldsumdb
 # Test a real GOTOOLCHAIN
 [short] skip
 [!net:golang.org] skip
+[!net:sum.golang.org] skip
 [!GOOS:darwin] [!GOOS:windows] [!GOOS:linux] skip
 [!GOARCH:amd64] [!GOARCH:arm64] skip
 
 env GOPROXY=
-env GOSUMDB=
+[go-builder] env GOSUMDB=
+[!go-builder] env GOSUMDB=sum.golang.org  # Set explicitly in case GOROOT/go.env is modified.
 env GOTOOLCHAIN=go1.20.1
 
        # Avoid resolving a "go1.20.1" from the user's real $PATH.
index ba1bde6671c53e2754762ba56e239463130b5bac..e0736ff980c5ccbd0f8501d24015d3482e096538 100644 (file)
@@ -1,6 +1,15 @@
-[!net:golang.org] skip
+[!net:proxy.golang.org] skip
 
-env GOPROXY=
+       # In the Go project's official release GOPROXY defaults to proxy.golang.org,
+       # but it may be changed in GOROOT/go.env (such as in third-party
+       # distributions).
+       #
+       # Make sure it is in use here, because the server for releases not served
+       # through the proxy (https://golang.org/toolchain?go-get=1) currently only
+       # serves the latest patch release for each of the supported stable releases.
+
+[go-builder] env GOPROXY=
+[!go-builder] env GOPROXY=https://proxy.golang.org
 
 go list -m -versions go
 stdout 1.20.1 # among others
index 57036b95be8bc438eecf8f3395832e8edb4f2315..4d583ff5f7e5a0a43b6570077c84ebd7708aa6be 100644 (file)
@@ -10,9 +10,9 @@ env GOPROXY=
 env GOSUMDB=
 
 # github.com/russross/blackfriday v2.0.0+incompatible exists,
-# and should be resolved if we ask for v2.0 explicitly.
+# and should be resolved if we ask for it explicitly.
 
-go list -m github.com/russross/blackfriday@v2.0
+go list -m github.com/russross/blackfriday@v2.0.0+incompatible
 stdout '^github.com/russross/blackfriday v2\.0\.0\+incompatible$'
 
 # blackfriday v1.5.2 has a go.mod file, so v1.5.2 should be preferred over
@@ -27,6 +27,7 @@ stdout '^github.com/russross/blackfriday v1\.'
 ! go list -m github.com/russross/blackfriday@patch
 stderr '^go: github.com/russross/blackfriday@patch: can''t query version "patch" of module github.com/russross/blackfriday: no existing version is required$'
 
+
 # If we're fetching directly from version control, ignored +incompatible
 # versions should also be omitted by 'go list'.
 
@@ -38,10 +39,23 @@ stderr '^go: github.com/russross/blackfriday@patch: can''t query version "patch"
 [!git] stop
 env GOPROXY=direct
 
-go list -versions -m github.com/russross/blackfriday github.com/russross/blackfriday
+go list -versions -m github.com/russross/blackfriday
 stdout '^github.com/russross/blackfriday v1\.5\.1 v1\.5\.2' # and possibly others
 ! stdout ' v2\.'
 
+# For this module, v2.1.0 exists and has a go.mod file.
+# 'go list -m github.com/russross/blackfriday@v2.0' will check
+# the latest v2.0 tag, discover that it isn't the right module, and stop there
+# (instead of spending the time to check O(N) previous tags).
+
+! go list -m github.com/russross/blackfriday@v2.0
+stderr '^go: module github.com/russross/blackfriday: no matching versions for query "v2\.0\"'
+
+# (But asking for exactly v2.0.0+incompatible should still succeed.)
+go list -m github.com/russross/blackfriday@v2.0.0+incompatible
+stdout '^github.com/russross/blackfriday v2\.0\.0\+incompatible$'
+
+
 # However, if the latest compatible version does not include a go.mod file,
 # +incompatible versions should still be listed, as they may still reflect the
 # intent of the module author.
index c95a667bfdcada19af78e958e1569ddb1ec189fa..2f42cb54f5a3d1eb4814eb033390e758d1e40a31 100644 (file)
@@ -1,7 +1,9 @@
 [!net:proxy.golang.org] skip
+[!net:sum.golang.org] skip
 
 env GO111MODULE=on
-env GOSUMDB=
+[go-builder] env GOSUMDB=
+[!go-builder] env GOSUMDB=sum.golang.org  # Set explicitly in case GOROOT/go.env is modified.
 env GOPATH=$WORK/gopath1
 
 # With a file-based proxy with an empty checksum directory,
index 8698412f786ad6fbf26e03130235510f33ad3840..067e2e3b318350a24d7b14aac0b5107b8267b7be 100644 (file)
@@ -1,13 +1,13 @@
 # Test default GOPROXY and GOSUMDB
-env GOPROXY=
-env GOSUMDB=
-go env GOPROXY
-stdout '^https://proxy.golang.org,direct$'
-go env GOSUMDB
-stdout '^sum.golang.org$'
-env GOPROXY=https://proxy.golang.org
-go env GOSUMDB
-stdout '^sum.golang.org$'
+[go-builder] env GOPROXY=
+[go-builder] env GOSUMDB=
+[go-builder] go env GOPROXY
+[go-builder] stdout '^https://proxy.golang.org,direct$'
+[go-builder] go env GOSUMDB
+[go-builder] stdout '^sum.golang.org$'
+[go-builder] env GOPROXY=https://proxy.golang.org
+[go-builder] go env GOSUMDB
+[go-builder] stdout '^sum.golang.org$'
 
 # Download direct from github.
 
@@ -26,8 +26,8 @@ cp go.sum saved.sum
 # files not listed in go.sum.
 
 go clean -modcache
-env GOSUMDB=
-env GOPROXY=
+env GOSUMDB=sum.golang.org
+env GOPROXY=https://proxy.golang.org,direct
 
 go list -x -m all  # Download go.mod files.
 ! stderr github