Skip to content

Commit

Permalink
cmd/go: fix tests when go.env sets GOPROXY=direct GOSUMDB=off
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Russ Cox <[email protected]>
Run-TryBot: Bryan Mills <[email protected]>
Auto-Submit: Bryan Mills <[email protected]>
  • Loading branch information
Bryan C. Mills authored and gopherbot committed Jul 17, 2023
1 parent c3458e3 commit 229cde5
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/cmd/go/scriptconds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions src/cmd/go/testdata/script/README
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 3 additions & 1 deletion src/cmd/go/testdata/script/gotoolchain_net.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 11 additions & 2 deletions src/cmd/go/testdata/script/gotoolchain_version.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
20 changes: 17 additions & 3 deletions src/cmd/go/testdata/script/mod_prefer_compatible.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
go list -m github.com/russross/[email protected].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
Expand All @@ -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'.

Expand All @@ -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/[email protected]' 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/[email protected]
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/[email protected]+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.
Expand Down
4 changes: 3 additions & 1 deletion src/cmd/go/testdata/script/mod_sumdb_file_path.txt
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
22 changes: 11 additions & 11 deletions src/cmd/go/testdata/script/mod_sumdb_golang.txt
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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
Expand Down

0 comments on commit 229cde5

Please sign in to comment.