From 014f1354d0cc046575fd6f0918436b262909f1e9 Mon Sep 17 00:00:00 2001 From: Paul Tyng Date: Fri, 10 Jul 2020 21:41:02 -0400 Subject: [PATCH] Honor RemoveAll defer --- tfexec/terraform_test.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tfexec/terraform_test.go b/tfexec/terraform_test.go index 45fc2e23..a6a2b547 100644 --- a/tfexec/terraform_test.go +++ b/tfexec/terraform_test.go @@ -19,20 +19,20 @@ const testTerraformStateFileName = "terraform.tfstate" var tfPath string func TestMain(m *testing.M) { - var err error - td, err := ioutil.TempDir("", "tfinstall") - if err != nil { - panic(err) - } - defer os.RemoveAll(td) - - tfPath, err = tfinstall.Find(tfinstall.LookPath(), tfinstall.LatestVersion(td, true)) - if err != nil { - panic(err) - } - exitCode := m.Run() - os.Exit(exitCode) - + os.Exit(func() int { + var err error + td, err := ioutil.TempDir("", "tfinstall") + if err != nil { + panic(err) + } + defer os.RemoveAll(td) + + tfPath, err = tfinstall.Find(tfinstall.LookPath(), tfinstall.LatestVersion(td, true)) + if err != nil { + panic(err) + } + return m.Run() + }()) } func TestCheckpointDisablePropagation(t *testing.T) {