diff --git a/provisioner/powershell/provisioner_test.go b/provisioner/powershell/provisioner_test.go index 06fe39ef7..7e739016c 100644 --- a/provisioner/powershell/provisioner_test.go +++ b/provisioner/powershell/provisioner_test.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "io/ioutil" - //"log" "os" "regexp" "strings" @@ -30,6 +29,7 @@ func TestProvisionerPrepare_extractScript(t *testing.T) { p := new(Provisioner) _ = p.Prepare(config) file, err := extractScript(p) + defer os.Remove(file) if err != nil { t.Fatalf("Should not be error: %s", err) } @@ -177,6 +177,7 @@ func TestProvisionerPrepare_Script(t *testing.T) { t.Fatalf("error tempfile: %s", err) } defer os.Remove(tf.Name()) + defer tf.Close() config["script"] = tf.Name() p = new(Provisioner) @@ -203,6 +204,7 @@ func TestProvisionerPrepare_ScriptAndInline(t *testing.T) { t.Fatalf("error tempfile: %s", err) } defer os.Remove(tf.Name()) + defer tf.Close() config["inline"] = []interface{}{"foo"} config["script"] = tf.Name() @@ -222,6 +224,7 @@ func TestProvisionerPrepare_ScriptAndScripts(t *testing.T) { t.Fatalf("error tempfile: %s", err) } defer os.Remove(tf.Name()) + defer tf.Close() config["inline"] = []interface{}{"foo"} config["scripts"] = []string{tf.Name()} @@ -248,6 +251,7 @@ func TestProvisionerPrepare_Scripts(t *testing.T) { t.Fatalf("error tempfile: %s", err) } defer os.Remove(tf.Name()) + defer tf.Close() config["scripts"] = []string{tf.Name()} p = new(Provisioner) @@ -444,6 +448,8 @@ func TestProvisionerProvision_Inline(t *testing.T) { func TestProvisionerProvision_Scripts(t *testing.T) { tempFile, _ := ioutil.TempFile("", "packer") defer os.Remove(tempFile.Name()) + defer tempFile.Close() + config := testConfig() delete(config, "inline") config["scripts"] = []string{tempFile.Name()} @@ -473,6 +479,8 @@ func TestProvisionerProvision_ScriptsWithEnvVars(t *testing.T) { config := testConfig() ui := testUi() defer os.Remove(tempFile.Name()) + defer tempFile.Close() + delete(config, "inline") config["scripts"] = []string{tempFile.Name()}