Commit fd7ff204 authored by Dmitriy Vyukov's avatar Dmitriy Vyukov

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
parent 13045847
......@@ -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()
}
......@@ -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)
......
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