Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't pass synthesized TMPDIR if not already set #409

Merged
merged 3 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions bundle/deploy/terraform/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +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 {
tmpDir, err := b.CacheDir("tmp")
if err != nil {
return err
}
env["TMPDIR"] = tmpDir
}
}
return nil
Expand Down
14 changes: 5 additions & 9 deletions bundle/deploy/terraform/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand All @@ -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()
}

Expand All @@ -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) {
Expand Down