From 25dd27a164355efbbf1dcb0df51f282a3734c0a1 Mon Sep 17 00:00:00 2001 From: DanHam Date: Wed, 25 Apr 2018 17:07:38 +0100 Subject: [PATCH] Remove tmp directories created by builder/vmware/common tests --- builder/vmware/common/step_output_dir_test.go | 4 ++++ builder/vmware/common/step_shutdown_test.go | 12 ++++++++++++ 2 files changed, 16 insertions(+) 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) {