Merge pull request #4371 from thaJeztah/24.0_backport_no_homedir

[24.0 backport] cli/command/context: don't use pkg/homedir in test
This commit is contained in:
Bjorn Neergaard 2023-06-26 06:12:01 -06:00 committed by GitHub
commit b3750a8461
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 2 deletions

View File

@ -6,6 +6,7 @@ import (
"io" "io"
"os" "os"
"path/filepath" "path/filepath"
"runtime"
"testing" "testing"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
@ -13,7 +14,6 @@ import (
"github.com/docker/cli/cli/config/configfile" "github.com/docker/cli/cli/config/configfile"
"github.com/docker/cli/cli/flags" "github.com/docker/cli/cli/flags"
"github.com/docker/docker/errdefs" "github.com/docker/docker/errdefs"
"github.com/docker/docker/pkg/homedir"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp" is "gotest.tools/v3/assert/cmp"
) )
@ -57,7 +57,11 @@ func TestUseDefaultWithoutConfigFile(t *testing.T) {
// the _default_ configuration file. If we specify a custom configuration // the _default_ configuration file. If we specify a custom configuration
// file, the CLI produces an error if the file doesn't exist. // file, the CLI produces an error if the file doesn't exist.
tmpHomeDir := t.TempDir() tmpHomeDir := t.TempDir()
t.Setenv(homedir.Key(), tmpHomeDir) if runtime.GOOS == "windows" {
t.Setenv("USERPROFILE", tmpHomeDir)
} else {
t.Setenv("HOME", tmpHomeDir)
}
configDir := filepath.Join(tmpHomeDir, ".docker") configDir := filepath.Join(tmpHomeDir, ".docker")
configFilePath := filepath.Join(configDir, "config.json") configFilePath := filepath.Join(configDir, "config.json")