From a5f650095801b3defaf34cd0466f67ed64eda18e Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sun, 6 Mar 2022 22:45:04 +0100 Subject: [PATCH] replace deprecated gotest.tools' env.Patch() with t.SetEnv() Signed-off-by: Sebastiaan van Stijn --- client/client_test.go | 8 ++++---- client/options_test.go | 5 ++--- daemon/logger/splunk/splunk_test.go | 4 +--- integration/daemon/daemon_test.go | 31 ++++++++++++++--------------- 4 files changed, 22 insertions(+), 26 deletions(-) diff --git a/client/client_test.go b/client/client_test.go index d2106d2979..10cf2d2f45 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -174,12 +174,12 @@ func TestParseHostURL(t *testing.T) { } func TestNewClientWithOpsFromEnvSetsDefaultVersion(t *testing.T) { - defer env.PatchAll(t, map[string]string{ + env.PatchAll(t, map[string]string{ "DOCKER_HOST": "", "DOCKER_API_VERSION": "", "DOCKER_TLS_VERIFY": "", "DOCKER_CERT_PATH": "", - })() + }) client, err := NewClientWithOpts(FromEnv) if err != nil { @@ -200,7 +200,7 @@ func TestNewClientWithOpsFromEnvSetsDefaultVersion(t *testing.T) { // downgrades to the correct API version if the API's ping response does not // return an API version. func TestNegotiateAPIVersionEmpty(t *testing.T) { - defer env.PatchAll(t, map[string]string{"DOCKER_API_VERSION": ""})() + t.Setenv("DOCKER_API_VERSION", "") client, err := NewClientWithOpts(FromEnv) assert.NilError(t, err) @@ -289,7 +289,7 @@ func TestNegotiateAPIVersion(t *testing.T) { // environment variable when negotiating versions. func TestNegotiateAPVersionOverride(t *testing.T) { const expected = "9.99" - defer env.PatchAll(t, map[string]string{"DOCKER_API_VERSION": expected})() + t.Setenv("DOCKER_API_VERSION", expected) client, err := NewClientWithOpts(FromEnv) assert.NilError(t, err) diff --git a/client/options_test.go b/client/options_test.go index b4ea0902e6..51900cef26 100644 --- a/client/options_test.go +++ b/client/options_test.go @@ -6,7 +6,6 @@ import ( "github.com/docker/docker/api" "gotest.tools/v3/assert" - "gotest.tools/v3/env" ) func TestOptionWithHostFromEnv(t *testing.T) { @@ -18,7 +17,7 @@ func TestOptionWithHostFromEnv(t *testing.T) { assert.Equal(t, c.addr, defaultAddr) assert.Equal(t, c.basePath, "") - defer env.Patch(t, "DOCKER_HOST", "tcp://foo.example.com:2376/test/")() + t.Setenv("DOCKER_HOST", "tcp://foo.example.com:2376/test/") c, err = NewClientWithOpts(WithHostFromEnv()) assert.NilError(t, err) @@ -44,7 +43,7 @@ func TestOptionWithVersionFromEnv(t *testing.T) { assert.Equal(t, c.version, api.DefaultVersion) assert.Equal(t, c.manualOverride, false) - defer env.Patch(t, "DOCKER_API_VERSION", "2.9999")() + t.Setenv("DOCKER_API_VERSION", "2.9999") c, err = NewClientWithOpts(WithVersionFromEnv()) assert.NilError(t, err) diff --git a/daemon/logger/splunk/splunk_test.go b/daemon/logger/splunk/splunk_test.go index 2317796e7e..1f2bdc3c3c 100644 --- a/daemon/logger/splunk/splunk_test.go +++ b/daemon/logger/splunk/splunk_test.go @@ -11,7 +11,6 @@ import ( "github.com/docker/docker/daemon/logger" "gotest.tools/v3/assert" - "gotest.tools/v3/env" ) // Validate options @@ -85,8 +84,7 @@ func TestNewMissedToken(t *testing.T) { func TestNewWithProxy(t *testing.T) { proxy := "http://proxy.testing:8888" - reset := env.Patch(t, "HTTP_PROXY", proxy) - defer reset() + t.Setenv("HTTP_PROXY", proxy) // must not be localhost splunkURL := "http://example.com:12345" diff --git a/integration/daemon/daemon_test.go b/integration/daemon/daemon_test.go index e4649a7ab3..72ffdd1dbf 100644 --- a/integration/daemon/daemon_test.go +++ b/integration/daemon/daemon_test.go @@ -18,7 +18,6 @@ import ( "github.com/docker/docker/testutil/daemon" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" - "gotest.tools/v3/env" "gotest.tools/v3/skip" ) @@ -213,9 +212,9 @@ func TestDaemonProxy(t *testing.T) { // Configure proxy through env-vars t.Run("environment variables", func(t *testing.T) { - defer env.Patch(t, "HTTP_PROXY", proxyServer.URL)() - defer env.Patch(t, "HTTPS_PROXY", proxyServer.URL)() - defer env.Patch(t, "NO_PROXY", "example.com")() + t.Setenv("HTTP_PROXY", proxyServer.URL) + t.Setenv("HTTPS_PROXY", proxyServer.URL) + t.Setenv("NO_PROXY", "example.com") d := daemon.New(t) c := d.NewClientT(t) @@ -241,12 +240,12 @@ func TestDaemonProxy(t *testing.T) { // Configure proxy through command-line flags t.Run("command-line options", func(t *testing.T) { - defer env.Patch(t, "HTTP_PROXY", "http://"+userPass+"from-env-http.invalid")() - defer env.Patch(t, "http_proxy", "http://"+userPass+"from-env-http.invalid")() - defer env.Patch(t, "HTTPS_PROXY", "https://"+userPass+"myuser:mypassword@from-env-https.invalid")() - defer env.Patch(t, "https_proxy", "https://"+userPass+"myuser:mypassword@from-env-https.invalid")() - defer env.Patch(t, "NO_PROXY", "ignore.invalid")() - defer env.Patch(t, "no_proxy", "ignore.invalid")() + t.Setenv("HTTP_PROXY", "http://"+userPass+"from-env-http.invalid") + t.Setenv("http_proxy", "http://"+userPass+"from-env-http.invalid") + t.Setenv("HTTPS_PROXY", "https://"+userPass+"myuser:mypassword@from-env-https.invalid") + t.Setenv("https_proxy", "https://"+userPass+"myuser:mypassword@from-env-https.invalid") + t.Setenv("NO_PROXY", "ignore.invalid") + t.Setenv("no_proxy", "ignore.invalid") d := daemon.New(t) d.Start(t, "--http-proxy", proxyServer.URL, "--https-proxy", proxyServer.URL, "--no-proxy", "example.com") @@ -282,12 +281,12 @@ func TestDaemonProxy(t *testing.T) { // Configure proxy through configuration file t.Run("configuration file", func(t *testing.T) { - defer env.Patch(t, "HTTP_PROXY", "http://"+userPass+"from-env-http.invalid")() - defer env.Patch(t, "http_proxy", "http://"+userPass+"from-env-http.invalid")() - defer env.Patch(t, "HTTPS_PROXY", "https://"+userPass+"myuser:mypassword@from-env-https.invalid")() - defer env.Patch(t, "https_proxy", "https://"+userPass+"myuser:mypassword@from-env-https.invalid")() - defer env.Patch(t, "NO_PROXY", "ignore.invalid")() - defer env.Patch(t, "no_proxy", "ignore.invalid")() + t.Setenv("HTTP_PROXY", "http://"+userPass+"from-env-http.invalid") + t.Setenv("http_proxy", "http://"+userPass+"from-env-http.invalid") + t.Setenv("HTTPS_PROXY", "https://"+userPass+"myuser:mypassword@from-env-https.invalid") + t.Setenv("https_proxy", "https://"+userPass+"myuser:mypassword@from-env-https.invalid") + t.Setenv("NO_PROXY", "ignore.invalid") + t.Setenv("no_proxy", "ignore.invalid") d := daemon.New(t) c := d.NewClientT(t)