mirror of
https://github.com/golang/go
synced 2024-11-23 08:00:05 -07:00
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
This commit is contained in:
parent
130458470a
commit
fd7ff20495
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user