From e84a963daaa5efcb2456ac3c604aad2bbdef4e4b Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Fri, 26 May 2023 10:54:40 +0200 Subject: [PATCH 1/3] Don't pass synthesized TMPDIR if not already set --- bundle/deploy/terraform/init.go | 6 +----- bundle/deploy/terraform/init_test.go | 14 +++++--------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/bundle/deploy/terraform/init.go b/bundle/deploy/terraform/init.go index 18a8de22af..aeb3ddac81 100644 --- a/bundle/deploy/terraform/init.go +++ b/bundle/deploy/terraform/init.go @@ -98,11 +98,7 @@ func setTempDirEnvVars(env map[string]string, b *bundle.Bundle) error { if v, ok := os.LookupEnv("TMPDIR"); ok { env["TMPDIR"] = v } else { - tmpDir, err := b.CacheDir("tmp") - if err != nil { - return err - } - env["TMPDIR"] = tmpDir + // If TMPDIR is not set, we let the process fall back to its default value. } } return nil diff --git a/bundle/deploy/terraform/init_test.go b/bundle/deploy/terraform/init_test.go index fdc6c89327..86eb897984 100644 --- a/bundle/deploy/terraform/init_test.go +++ b/bundle/deploy/terraform/init_test.go @@ -48,7 +48,7 @@ func TestInitEnvironmentVariables(t *testing.T) { } func TestSetTempDirEnvVarsForUnixWithTmpDirSet(t *testing.T) { - if runtime.GOOS != "darwin" && runtime.GOOS != "linux" { + if !(runtime.GOOS == "darwin" || runtime.GOOS == "linux") { t.SkipNow() } @@ -69,14 +69,14 @@ func TestSetTempDirEnvVarsForUnixWithTmpDirSet(t *testing.T) { err := setTempDirEnvVars(env, b) require.NoError(t, err) - // assert that we pass through env var value + // Assert that we pass through TMPDIR. assert.Equal(t, map[string]string{ "TMPDIR": "/foo/bar", }, env) } func TestSetTempDirEnvVarsForUnixWithTmpDirNotSet(t *testing.T) { - if runtime.GOOS != "darwin" && runtime.GOOS != "linux" { + if !(runtime.GOOS == "darwin" || runtime.GOOS == "linux") { t.SkipNow() } @@ -97,12 +97,8 @@ func TestSetTempDirEnvVarsForUnixWithTmpDirNotSet(t *testing.T) { err := setTempDirEnvVars(env, b) require.NoError(t, err) - // assert tmp dir is set to b.CacheDir("tmp") - tmpDir, err := b.CacheDir("tmp") - require.NoError(t, err) - assert.Equal(t, map[string]string{ - "TMPDIR": tmpDir, - }, env) + // Assert that we don't pass through TMPDIR. + assert.Equal(t, map[string]string{}, env) } func TestSetTempDirEnvVarsForWindowWithAllTmpDirEnvVarsSet(t *testing.T) { From 29424b63827e3216fa234d13cdb79aef457b1f14 Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Fri, 26 May 2023 12:57:24 +0200 Subject: [PATCH 2/3] Move comment --- bundle/deploy/terraform/init.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bundle/deploy/terraform/init.go b/bundle/deploy/terraform/init.go index aeb3ddac81..14a5d2c02d 100644 --- a/bundle/deploy/terraform/init.go +++ b/bundle/deploy/terraform/init.go @@ -95,10 +95,9 @@ func setTempDirEnvVars(env map[string]string, b *bundle.Bundle) error { env["TMP"] = tmpDir } default: + // If TMPDIR is not set, we let the process fall back to its default value. if v, ok := os.LookupEnv("TMPDIR"); ok { env["TMPDIR"] = v - } else { - // If TMPDIR is not set, we let the process fall back to its default value. } } return nil From 2b44e6e927335c0cb2fadc185d3c1be47eeba203 Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Fri, 26 May 2023 12:59:58 +0200 Subject: [PATCH 3/3] Nit --- bundle/deploy/terraform/init_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bundle/deploy/terraform/init_test.go b/bundle/deploy/terraform/init_test.go index 86eb897984..872d55c7eb 100644 --- a/bundle/deploy/terraform/init_test.go +++ b/bundle/deploy/terraform/init_test.go @@ -48,7 +48,7 @@ func TestInitEnvironmentVariables(t *testing.T) { } func TestSetTempDirEnvVarsForUnixWithTmpDirSet(t *testing.T) { - if !(runtime.GOOS == "darwin" || runtime.GOOS == "linux") { + if runtime.GOOS != "darwin" && runtime.GOOS != "linux" { t.SkipNow() } @@ -76,7 +76,7 @@ func TestSetTempDirEnvVarsForUnixWithTmpDirSet(t *testing.T) { } func TestSetTempDirEnvVarsForUnixWithTmpDirNotSet(t *testing.T) { - if !(runtime.GOOS == "darwin" || runtime.GOOS == "linux") { + if runtime.GOOS != "darwin" && runtime.GOOS != "linux" { t.SkipNow() }