Browse Source

e2e: always set HOME + USER for cmd env

Signed-off-by: Milas Bowman <[email protected]>
Milas Bowman 3 years ago
parent
commit
ccd87311e8
2 changed files with 10 additions and 2 deletions
  1. 0 2
      pkg/e2e/ddev_test.go
  2. 10 0
      pkg/e2e/framework.go

+ 0 - 2
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),
 	))
 

+ 10 - 0
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",
 	}