diff --git a/builder/vmware/common/step_output_dir_test.go b/builder/vmware/common/step_output_dir_test.go index fe71bbea8..3726a9354 100644 --- a/builder/vmware/common/step_output_dir_test.go +++ b/builder/vmware/common/step_output_dir_test.go @@ -30,6 +30,8 @@ func TestStepOutputDir(t *testing.T) { step := new(StepOutputDir) dir := testOutputDir(t) + // Delete the test output directory when done + defer os.RemoveAll(dir.dir) state.Put("dir", dir) // Test the run @@ -61,6 +63,7 @@ func TestStepOutputDir_existsNoForce(t *testing.T) { if err := os.MkdirAll(dir.dir, 0755); err != nil { t.Fatalf("err: %s", err) } + defer os.RemoveAll(dir.dir) // Test the run if action := step.Run(context.Background(), state); action != multistep.ActionHalt { @@ -89,6 +92,7 @@ func TestStepOutputDir_existsForce(t *testing.T) { if err := os.MkdirAll(dir.dir, 0755); err != nil { t.Fatalf("err: %s", err) } + defer os.RemoveAll(dir.dir) // Test the run if action := step.Run(context.Background(), state); action != multistep.ActionContinue { diff --git a/builder/vmware/common/step_shutdown_test.go b/builder/vmware/common/step_shutdown_test.go index ff775f2f2..0c3d98589 100644 --- a/builder/vmware/common/step_shutdown_test.go +++ b/builder/vmware/common/step_shutdown_test.go @@ -85,6 +85,12 @@ func TestStepShutdown_command(t *testing.T) { if comm.StartCmd.Command != "foo" { t.Fatalf("bad: %#v", comm.StartCmd.Command) } + + // Clean up the created test output directory + dir := state.Get("dir").(*LocalOutputDir) + if err := dir.RemoveAll(); err != nil { + t.Fatalf("Error cleaning up directory: %s", err) + } } func TestStepShutdown_noCommand(t *testing.T) { @@ -113,6 +119,12 @@ func TestStepShutdown_noCommand(t *testing.T) { if comm.StartCalled { t.Fatal("start should not be called") } + + // Clean up the created test output directory + dir := state.Get("dir").(*LocalOutputDir) + if err := dir.RemoveAll(); err != nil { + t.Fatalf("Error cleaning up directory: %s", err) + } } func TestStepShutdown_locks(t *testing.T) {