From: Dmitriy Vyukov Date: Thu, 6 Mar 2014 14:44:14 +0000 (+0400) Subject: net/http: make TestUseProxy repeatable X-Git-Tag: go1.3beta1~446 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=fd7ff2049512b3a900004e3e3c83e45263f93d13;p=gostls13.git net/http: make TestUseProxy repeatable Currently it fails on second and subsequent runs (when using -cpu=1,2,4) as: --- FAIL: TestUseProxy-4 (0.00 seconds) proxy_test.go:109: useProxy(barbaz.net) = true, want false proxy_test.go:109: useProxy(foobar.com) = true, want false proxy_test.go:109: useProxy(www.foobar.com) = true, want false LGTM=bradfitz R=bradfitz CC=golang-codereviews https://golang.org/cl/71940044 --- diff --git a/src/pkg/net/http/proxy_test.go b/src/pkg/net/http/proxy_test.go index d0726f61f3..b6aed3792b 100644 --- a/src/pkg/net/http/proxy_test.go +++ b/src/pkg/net/http/proxy_test.go @@ -35,12 +35,8 @@ var UseProxyTests = []struct { } func TestUseProxy(t *testing.T) { - oldenv := os.Getenv("NO_PROXY") - defer os.Setenv("NO_PROXY", oldenv) - - no_proxy := "foobar.com, .barbaz.net" - os.Setenv("NO_PROXY", no_proxy) - + ResetProxyEnv() + os.Setenv("NO_PROXY", "foobar.com, .barbaz.net") for _, test := range UseProxyTests { if useProxy(test.host+":80") != test.match { t.Errorf("useProxy(%v) = %v, want %v", test.host, !test.match, test.match) @@ -76,3 +72,10 @@ func TestCacheKeys(t *testing.T) { } } } + +func ResetProxyEnv() { + for _, v := range []string{"HTTP_PROXY", "http_proxy", "NO_PROXY", "no_proxy"} { + os.Setenv(v, "") + } + ResetCachedEnvironment() +} diff --git a/src/pkg/net/http/transport_test.go b/src/pkg/net/http/transport_test.go index 1d73633ea4..7584db992b 100644 --- a/src/pkg/net/http/transport_test.go +++ b/src/pkg/net/http/transport_test.go @@ -1694,10 +1694,7 @@ var proxyFromEnvTests = []proxyFromEnvTest{ } func TestProxyFromEnvironment(t *testing.T) { - os.Setenv("HTTP_PROXY", "") - os.Setenv("http_proxy", "") - os.Setenv("NO_PROXY", "") - os.Setenv("no_proxy", "") + ResetProxyEnv() for _, tt := range proxyFromEnvTests { os.Setenv("HTTP_PROXY", tt.env) os.Setenv("NO_PROXY", tt.noenv)