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.
This commit is contained in:
parent
2e639cb506
commit
c21610f533
|
@ -59,9 +59,15 @@ func tempDir(t *testing.T) string {
|
||||||
// a function to defer to reset the old value.
|
// a function to defer to reset the old value.
|
||||||
// the old value that should be set via a defer.
|
// the old value that should be set via a defer.
|
||||||
func tempEnv(t *testing.T, k string, v string) func() {
|
func tempEnv(t *testing.T, k string, v string) func() {
|
||||||
old := os.Getenv(k)
|
old, oldOk := os.LookupEnv(k)
|
||||||
os.Setenv(k, v)
|
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 {
|
func testConfig(t *testing.T, name string) *config.Config {
|
||||||
|
|
Loading…
Reference in New Issue