summaryrefslogtreecommitdiff
path: root/integration-cli
diff options
context:
space:
mode:
authorBrian Goff <cpuguy@hey.com>2022-04-28 12:02:01 -0700
committerGitHub <noreply@github.com>2022-04-28 12:02:01 -0700
commitb3332b851a6ffeb4fd15f234436d8740df38a5d5 (patch)
treeb94779008ce2a9fe2ba9a49eeab21902e08de415 /integration-cli
parent647aede6ad42d0f4cf08d675f59bb8013a3fb56b (diff)
parent36049a04d2e11454789be71f40eb2aed1c7070d5 (diff)
downloaddocker-b3332b851a6ffeb4fd15f234436d8740df38a5d5.tar.gz
Merge pull request #43517 from Juneezee/test/t.Setenv
test: use `T.Setenv` to set env vars in tests
Diffstat (limited to 'integration-cli')
-rw-r--r--integration-cli/docker_cli_build_test.go8
-rw-r--r--integration-cli/docker_cli_daemon_test.go7
-rw-r--r--integration-cli/docker_cli_logout_test.go16
-rw-r--r--integration-cli/docker_cli_pull_local_test.go16
-rw-r--r--integration-cli/docker_cli_run_unix_test.go10
5 files changed, 18 insertions, 39 deletions
diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go
index db3e0fd1e7..9847995f18 100644
--- a/integration-cli/docker_cli_build_test.go
+++ b/integration-cli/docker_cli_build_test.go
@@ -5009,16 +5009,14 @@ func (s *DockerRegistryAuthHtpasswdSuite) TestBuildFromAuthenticatedRegistry(c *
}
func (s *DockerRegistryAuthHtpasswdSuite) TestBuildWithExternalAuth(c *testing.T) {
- osPath := os.Getenv("PATH")
- defer os.Setenv("PATH", osPath)
-
workingDir, err := os.Getwd()
assert.NilError(c, err)
absolute, err := filepath.Abs(filepath.Join(workingDir, "fixtures", "auth"))
assert.NilError(c, err)
- testPath := fmt.Sprintf("%s%c%s", osPath, filepath.ListSeparator, absolute)
- os.Setenv("PATH", testPath)
+ osPath := os.Getenv("PATH")
+ testPath := fmt.Sprintf("%s%c%s", osPath, filepath.ListSeparator, absolute)
+ c.Setenv("PATH", testPath)
repoName := fmt.Sprintf("%v/dockercli/busybox:authtest", privateRegistryURL)
diff --git a/integration-cli/docker_cli_daemon_test.go b/integration-cli/docker_cli_daemon_test.go
index 036aff81bc..94f07f56b4 100644
--- a/integration-cli/docker_cli_daemon_test.go
+++ b/integration-cli/docker_cli_daemon_test.go
@@ -1693,12 +1693,7 @@ func (s *DockerDaemonSuite) TestDaemonStartWithDefaultTLSHost(c *testing.T) {
"--tlskey", "fixtures/https/server-key.pem")
// The client with --tlsverify should also use default host localhost:2376
- tmpHost := os.Getenv("DOCKER_HOST")
- defer func() {
- os.Setenv("DOCKER_HOST", tmpHost)
- }()
-
- os.Setenv("DOCKER_HOST", "")
+ c.Setenv("DOCKER_HOST", "")
out, _ := dockerCmd(
c,
diff --git a/integration-cli/docker_cli_logout_test.go b/integration-cli/docker_cli_logout_test.go
index 37d5a2742e..ef11655287 100644
--- a/integration-cli/docker_cli_logout_test.go
+++ b/integration-cli/docker_cli_logout_test.go
@@ -15,16 +15,14 @@ import (
func (s *DockerRegistryAuthHtpasswdSuite) TestLogoutWithExternalAuth(c *testing.T) {
s.d.StartWithBusybox(c)
- osPath := os.Getenv("PATH")
- defer os.Setenv("PATH", osPath)
-
workingDir, err := os.Getwd()
assert.NilError(c, err)
absolute, err := filepath.Abs(filepath.Join(workingDir, "fixtures", "auth"))
assert.NilError(c, err)
- testPath := fmt.Sprintf("%s%c%s", osPath, filepath.ListSeparator, absolute)
- os.Setenv("PATH", testPath)
+ osPath := os.Getenv("PATH")
+ testPath := fmt.Sprintf("%s%c%s", osPath, filepath.ListSeparator, absolute)
+ c.Setenv("PATH", testPath)
repoName := fmt.Sprintf("%v/dockercli/busybox:authtest", privateRegistryURL)
@@ -65,16 +63,14 @@ func (s *DockerRegistryAuthHtpasswdSuite) TestLogoutWithExternalAuth(c *testing.
// #23100
func (s *DockerRegistryAuthHtpasswdSuite) TestLogoutWithWrongHostnamesStored(c *testing.T) {
- osPath := os.Getenv("PATH")
- defer os.Setenv("PATH", osPath)
-
workingDir, err := os.Getwd()
assert.NilError(c, err)
absolute, err := filepath.Abs(filepath.Join(workingDir, "fixtures", "auth"))
assert.NilError(c, err)
- testPath := fmt.Sprintf("%s%c%s", osPath, filepath.ListSeparator, absolute)
- os.Setenv("PATH", testPath)
+ osPath := os.Getenv("PATH")
+ testPath := fmt.Sprintf("%s%c%s", osPath, filepath.ListSeparator, absolute)
+ c.Setenv("PATH", testPath)
cmd := exec.Command("docker-credential-shell-test", "store")
stdin := bytes.NewReader([]byte(fmt.Sprintf(`{"ServerURL": "https://%s", "Username": "%s", "Secret": "%s"}`, privateRegistryURL, s.reg.Username(), s.reg.Password())))
diff --git a/integration-cli/docker_cli_pull_local_test.go b/integration-cli/docker_cli_pull_local_test.go
index 9037ca74f8..d5c7383659 100644
--- a/integration-cli/docker_cli_pull_local_test.go
+++ b/integration-cli/docker_cli_pull_local_test.go
@@ -367,16 +367,14 @@ func (s *DockerRegistrySuite) TestPullManifestList(c *testing.T) {
// #23100
func (s *DockerRegistryAuthHtpasswdSuite) TestPullWithExternalAuthLoginWithScheme(c *testing.T) {
- osPath := os.Getenv("PATH")
- defer os.Setenv("PATH", osPath)
-
workingDir, err := os.Getwd()
assert.NilError(c, err)
absolute, err := filepath.Abs(filepath.Join(workingDir, "fixtures", "auth"))
assert.NilError(c, err)
- testPath := fmt.Sprintf("%s%c%s", osPath, filepath.ListSeparator, absolute)
- os.Setenv("PATH", testPath)
+ osPath := os.Getenv("PATH")
+ testPath := fmt.Sprintf("%s%c%s", osPath, filepath.ListSeparator, absolute)
+ c.Setenv("PATH", testPath)
repoName := fmt.Sprintf("%v/dockercli/busybox:authtest", privateRegistryURL)
@@ -411,16 +409,14 @@ func (s *DockerRegistryAuthHtpasswdSuite) TestPullWithExternalAuthLoginWithSchem
}
func (s *DockerRegistryAuthHtpasswdSuite) TestPullWithExternalAuth(c *testing.T) {
- osPath := os.Getenv("PATH")
- defer os.Setenv("PATH", osPath)
-
workingDir, err := os.Getwd()
assert.NilError(c, err)
absolute, err := filepath.Abs(filepath.Join(workingDir, "fixtures", "auth"))
assert.NilError(c, err)
- testPath := fmt.Sprintf("%s%c%s", osPath, filepath.ListSeparator, absolute)
- os.Setenv("PATH", testPath)
+ osPath := os.Getenv("PATH")
+ testPath := fmt.Sprintf("%s%c%s", osPath, filepath.ListSeparator, absolute)
+ c.Setenv("PATH", testPath)
repoName := fmt.Sprintf("%v/dockercli/busybox:authtest", privateRegistryURL)
diff --git a/integration-cli/docker_cli_run_unix_test.go b/integration-cli/docker_cli_run_unix_test.go
index 280948d6b2..8a3f19d8d6 100644
--- a/integration-cli/docker_cli_run_unix_test.go
+++ b/integration-cli/docker_cli_run_unix_test.go
@@ -243,8 +243,6 @@ func (s *DockerSuite) TestRunAttachDetachFromConfig(c *testing.T) {
keyA := []byte{97}
// Setup config
- homeKey := homedir.Key()
- homeVal := homedir.Get()
tmpDir, err := os.MkdirTemp("", "fake-home")
assert.NilError(c, err)
defer os.RemoveAll(tmpDir)
@@ -253,8 +251,7 @@ func (s *DockerSuite) TestRunAttachDetachFromConfig(c *testing.T) {
os.Mkdir(dotDocker, 0600)
tmpCfg := filepath.Join(dotDocker, "config.json")
- defer func() { os.Setenv(homeKey, homeVal) }()
- os.Setenv(homeKey, tmpDir)
+ c.Setenv(homedir.Key(), tmpDir)
data := `{
"detachKeys": "ctrl-a,a"
@@ -326,8 +323,6 @@ func (s *DockerSuite) TestRunAttachDetachKeysOverrideConfig(c *testing.T) {
keyA := []byte{97}
// Setup config
- homeKey := homedir.Key()
- homeVal := homedir.Get()
tmpDir, err := os.MkdirTemp("", "fake-home")
assert.NilError(c, err)
defer os.RemoveAll(tmpDir)
@@ -336,8 +331,7 @@ func (s *DockerSuite) TestRunAttachDetachKeysOverrideConfig(c *testing.T) {
os.Mkdir(dotDocker, 0600)
tmpCfg := filepath.Join(dotDocker, "config.json")
- defer func() { os.Setenv(homeKey, homeVal) }()
- os.Setenv(homeKey, tmpDir)
+ c.Setenv(homedir.Key(), tmpDir)
data := `{
"detachKeys": "ctrl-e,e"