From ccd87311e8e0c3cb210d4c7eaf875ae3cf8def26 Mon Sep 17 00:00:00 2001 From: Milas Bowman Date: Thu, 16 Jun 2022 09:44:26 -0400 Subject: [PATCH] e2e: always set HOME + USER for cmd env Signed-off-by: Milas Bowman --- pkg/e2e/ddev_test.go | 2 -- pkg/e2e/framework.go | 10 ++++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/e2e/ddev_test.go b/pkg/e2e/ddev_test.go index e4f44710..00b890d1 100644 --- a/pkg/e2e/ddev_test.go +++ b/pkg/e2e/ddev_test.go @@ -56,8 +56,6 @@ func TestComposeRunDdev(t *testing.T) { c := NewCLI(t, WithEnv( "DDEV_DEBUG=true", - fmt.Sprintf("HOME=%s", t.TempDir()), - fmt.Sprintf("USER=%s", os.Getenv("USER")), fmt.Sprintf("PATH=%s", pathDir), )) diff --git a/pkg/e2e/framework.go b/pkg/e2e/framework.go index 49874e95..2a5880ad 100644 --- a/pkg/e2e/framework.go +++ b/pkg/e2e/framework.go @@ -59,8 +59,15 @@ func init() { // CLI is used to wrap the CLI for end to end testing type CLI struct { + // ConfigDir for Docker configuration (set as DOCKER_CONFIG) ConfigDir string + // HomeDir for tools that look for user files (set as HOME) + HomeDir string + + // env overrides to apply to every invoked command + // + // To populate, use WithEnv when creating a CLI instance. env []string } @@ -84,6 +91,7 @@ func NewCLI(t testing.TB, opts ...CLIOption) *CLI { c := &CLI{ ConfigDir: configDir, + HomeDir: t.TempDir(), } for _, opt := range opts { @@ -188,6 +196,8 @@ func CopyFile(sourceFile string, destinationFile string) error { // Docker / Compose commands. func (c *CLI) BaseEnvironment() []string { return []string{ + "HOME=" + c.HomeDir, + "USER=" + os.Getenv("USER"), "DOCKER_CONFIG=" + c.ConfigDir, "KUBECONFIG=invalid", }