Commit df367ca0 authored by Bryan C. Mills's avatar Bryan C. Mills Committed by Alexander Rakoczy

[release-branch.go1.12] cmd/go/internal/{modconv,modfetch,modload}: set modfetch proxy URL in tests

Updates #30571
Fixes #34789

Change-Id: Id4c74e83ee58a080d1c2894ae5ebdbf4aeb1ce42
Reviewed-on: https://go-review.googlesource.com/c/go/+/167084
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: default avatarJay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
(cherry picked from commit bd680d94)
Reviewed-on: https://go-review.googlesource.com/c/go/+/200037
parent d7dd91aa
...@@ -28,6 +28,8 @@ func TestMain(m *testing.M) { ...@@ -28,6 +28,8 @@ func TestMain(m *testing.M) {
} }
func testMain(m *testing.M) int { func testMain(m *testing.M) int {
modfetch.SetProxy("direct")
if _, err := exec.LookPath("git"); err != nil { if _, err := exec.LookPath("git"); err != nil {
fmt.Fprintln(os.Stderr, "skipping because git binary not found") fmt.Fprintln(os.Stderr, "skipping because git binary not found")
fmt.Println("PASS") fmt.Println("PASS")
......
...@@ -24,6 +24,8 @@ func TestMain(m *testing.M) { ...@@ -24,6 +24,8 @@ func TestMain(m *testing.M) {
} }
func testMain(m *testing.M) int { func testMain(m *testing.M) int {
SetProxy("direct")
dir, err := ioutil.TempDir("", "gitrepo-test-") dir, err := ioutil.TempDir("", "gitrepo-test-")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
......
...@@ -87,6 +87,14 @@ cached module versions with GOPROXY=https://example.com/proxy. ...@@ -87,6 +87,14 @@ cached module versions with GOPROXY=https://example.com/proxy.
var proxyURL = os.Getenv("GOPROXY") var proxyURL = os.Getenv("GOPROXY")
// SetProxy sets the proxy to use when fetching modules.
// It accepts the same syntax as the GOPROXY environment variable,
// which also provides its default configuration.
// SetProxy must not be called after the first module fetch has begun.
func SetProxy(url string) {
proxyURL = url
}
func lookupProxy(path string) (Repo, error) { func lookupProxy(path string) (Repo, error) {
if strings.Contains(proxyURL, ",") { if strings.Contains(proxyURL, ",") {
return nil, fmt.Errorf("invalid $GOPROXY setting: cannot have comma") return nil, fmt.Errorf("invalid $GOPROXY setting: cannot have comma")
......
...@@ -14,6 +14,7 @@ import ( ...@@ -14,6 +14,7 @@ import (
"strings" "strings"
"testing" "testing"
"cmd/go/internal/cfg"
"cmd/go/internal/modfetch" "cmd/go/internal/modfetch"
"cmd/go/internal/modfetch/codehost" "cmd/go/internal/modfetch/codehost"
"cmd/go/internal/module" "cmd/go/internal/module"
...@@ -24,11 +25,16 @@ func TestMain(m *testing.M) { ...@@ -24,11 +25,16 @@ func TestMain(m *testing.M) {
} }
func testMain(m *testing.M) int { func testMain(m *testing.M) int {
modfetch.SetProxy("direct")
dir, err := ioutil.TempDir("", "modload-test-") dir, err := ioutil.TempDir("", "modload-test-")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
os.Setenv("GOPATH", dir)
cfg.BuildContext.GOPATH = dir
modfetch.PkgMod = filepath.Join(dir, "pkg/mod") modfetch.PkgMod = filepath.Join(dir, "pkg/mod")
codehost.WorkRoot = filepath.Join(dir, "codework") codehost.WorkRoot = filepath.Join(dir, "codework")
return m.Run() return m.Run()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment