diff --git a/staging/src/k8s.io/apimachinery/pkg/util/net/http_test.go b/staging/src/k8s.io/apimachinery/pkg/util/net/http_test.go index 5d3588070d1..a9fe8014bec 100644 --- a/staging/src/k8s.io/apimachinery/pkg/util/net/http_test.go +++ b/staging/src/k8s.io/apimachinery/pkg/util/net/http_test.go @@ -26,7 +26,6 @@ import ( "net" "net/http" "net/url" - "os" "reflect" "strings" "testing" @@ -205,7 +204,7 @@ func TestProxierWithNoProxyCIDR(t *testing.T) { } for _, test := range testCases { - os.Setenv("NO_PROXY", test.noProxy) + t.Setenv("NO_PROXY", test.noProxy) actualDelegated := false proxyFunc := NewProxierWithNoProxyCIDR(func(req *http.Request) (*url.URL, error) { actualDelegated = true @@ -917,40 +916,28 @@ func TestIsProbableEOF(t *testing.T) { } } -func setEnv(key, value string) func() { - originalValue := os.Getenv(key) - os.Setenv(key, value) - return func() { - os.Setenv(key, originalValue) - } -} - func TestReadIdleTimeoutSeconds(t *testing.T) { - reset := setEnv("HTTP2_READ_IDLE_TIMEOUT_SECONDS", "60") + t.Setenv("HTTP2_READ_IDLE_TIMEOUT_SECONDS", "60") if e, a := 60, readIdleTimeoutSeconds(); e != a { t.Errorf("expected %d, got %d", e, a) } - reset() - reset = setEnv("HTTP2_READ_IDLE_TIMEOUT_SECONDS", "illegal value") + t.Setenv("HTTP2_READ_IDLE_TIMEOUT_SECONDS", "illegal value") if e, a := 30, readIdleTimeoutSeconds(); e != a { t.Errorf("expected %d, got %d", e, a) } - reset() } func TestPingTimeoutSeconds(t *testing.T) { - reset := setEnv("HTTP2_PING_TIMEOUT_SECONDS", "60") + t.Setenv("HTTP2_PING_TIMEOUT_SECONDS", "60") if e, a := 60, pingTimeoutSeconds(); e != a { t.Errorf("expected %d, got %d", e, a) } - reset() - reset = setEnv("HTTP2_PING_TIMEOUT_SECONDS", "illegal value") + t.Setenv("HTTP2_PING_TIMEOUT_SECONDS", "illegal value") if e, a := 15, pingTimeoutSeconds(); e != a { t.Errorf("expected %d, got %d", e, a) } - reset() } func Benchmark_ParseQuotedString(b *testing.B) {