]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.12] cmd/go/internal/{modconv,modfetch,modload}: set modfetch...
authorBryan C. Mills <bcmills@google.com>
Tue, 12 Mar 2019 19:43:16 +0000 (15:43 -0400)
committerAlexander Rakoczy <alex@golang.org>
Wed, 9 Oct 2019 15:29:01 +0000 (15:29 +0000)
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: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
(cherry picked from commit bd680d94a030962efbdb20a51eb19e50ba286e56)
Reviewed-on: https://go-review.googlesource.com/c/go/+/200037

src/cmd/go/internal/modconv/convert_test.go
src/cmd/go/internal/modfetch/coderepo_test.go
src/cmd/go/internal/modfetch/proxy.go
src/cmd/go/internal/modload/query_test.go

index 4d55d73f21423646a8f0f57d0d84389348d4eaa6..d6316e36e97fe353f33d81d0abb8bbf920ea4a9a 100644 (file)
@@ -28,6 +28,8 @@ func TestMain(m *testing.M) {
 }
 
 func testMain(m *testing.M) int {
+       modfetch.SetProxy("direct")
+
        if _, err := exec.LookPath("git"); err != nil {
                fmt.Fprintln(os.Stderr, "skipping because git binary not found")
                fmt.Println("PASS")
index 7a419576ced03ce767259e03a374ce19931d615b..2c756c50f242e0dc767867bca93689275d2ad809 100644 (file)
@@ -24,6 +24,8 @@ func TestMain(m *testing.M) {
 }
 
 func testMain(m *testing.M) int {
+       SetProxy("direct")
+
        dir, err := ioutil.TempDir("", "gitrepo-test-")
        if err != nil {
                log.Fatal(err)
index 60ed2a37966067dc9f9647facbe9c6aed9749a00..3d4d2becf40346d66599e9946e46d89f9dff1bd9 100644 (file)
@@ -87,6 +87,14 @@ cached module versions with GOPROXY=https://example.com/proxy.
 
 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) {
        if strings.Contains(proxyURL, ",") {
                return nil, fmt.Errorf("invalid $GOPROXY setting: cannot have comma")
index 9b07383217175cafb4eee83c7db5b4cec2b22faf..d6e52c6b74fd421ce2efae76e37d164abc4e5d70 100644 (file)
@@ -14,6 +14,7 @@ import (
        "strings"
        "testing"
 
+       "cmd/go/internal/cfg"
        "cmd/go/internal/modfetch"
        "cmd/go/internal/modfetch/codehost"
        "cmd/go/internal/module"
@@ -24,11 +25,16 @@ func TestMain(m *testing.M) {
 }
 
 func testMain(m *testing.M) int {
+       modfetch.SetProxy("direct")
+
        dir, err := ioutil.TempDir("", "modload-test-")
        if err != nil {
                log.Fatal(err)
        }
        defer os.RemoveAll(dir)
+
+       os.Setenv("GOPATH", dir)
+       cfg.BuildContext.GOPATH = dir
        modfetch.PkgMod = filepath.Join(dir, "pkg/mod")
        codehost.WorkRoot = filepath.Join(dir, "codework")
        return m.Run()