From c21610f5338df055ab563fcc9bd0ff78a58b23d2 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 31 Oct 2016 11:00:19 -0700 Subject: [PATCH] terraform: for tempEnv, if the var wans't set before, unset This was causing flaky behavior in our tests because `TF_VAR_x=""` is actually a valid env var. For tests, we need to actually unset env vars that haven't been set before. --- terraform/terraform_test.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/terraform/terraform_test.go b/terraform/terraform_test.go index 42994fe7d..52f17bdb4 100644 --- a/terraform/terraform_test.go +++ b/terraform/terraform_test.go @@ -59,9 +59,15 @@ func tempDir(t *testing.T) string { // a function to defer to reset the old value. // the old value that should be set via a defer. func tempEnv(t *testing.T, k string, v string) func() { - old := os.Getenv(k) + old, oldOk := os.LookupEnv(k) os.Setenv(k, v) - return func() { os.Setenv(k, old) } + return func() { + if !oldOk { + os.Unsetenv(k) + } else { + os.Setenv(k, old) + } + } } func testConfig(t *testing.T, name string) *config.Config {