]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: make TestUseProxy repeatable
authorDmitriy Vyukov <dvyukov@google.com>
Thu, 6 Mar 2014 14:44:14 +0000 (18:44 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Thu, 6 Mar 2014 14:44:14 +0000 (18:44 +0400)
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

src/pkg/net/http/proxy_test.go
src/pkg/net/http/transport_test.go

index d0726f61f3bf3e64fa21839661a1a23354da724e..b6aed3792b63304555e7bc967d3fa00c86e331b5 100644 (file)
@@ -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()
+}
index 1d73633ea4bc4946bdcf3cad6ed1cacdfb5a751f..7584db992b8bda5482a8d0ec837471be5da6cbe0 100644 (file)
@@ -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)