From fd07cfd2b169643cd7bb323426eaca6975dda013 Mon Sep 17 00:00:00 2001 From: DanHam Date: Wed, 25 Apr 2018 19:49:13 +0100 Subject: [PATCH] Remove tmp files created by provisioner/puppet-masterless tests --- .../puppet-masterless/provisioner_test.go | 67 ++++++++++++++----- 1 file changed, 51 insertions(+), 16 deletions(-) diff --git a/provisioner/puppet-masterless/provisioner_test.go b/provisioner/puppet-masterless/provisioner_test.go index dd6725768..294534779 100644 --- a/provisioner/puppet-masterless/provisioner_test.go +++ b/provisioner/puppet-masterless/provisioner_test.go @@ -13,15 +13,17 @@ import ( "github.com/stretchr/testify/assert" ) -func testConfig() map[string]interface{} { +func testConfig() (config map[string]interface{}, tf *os.File) { tf, err := ioutil.TempFile("", "packer") if err != nil { panic(err) } - return map[string]interface{}{ + config = map[string]interface{}{ "manifest_file": tf.Name(), } + + return config, tf } func TestProvisioner_Impl(t *testing.T) { @@ -33,7 +35,10 @@ func TestProvisioner_Impl(t *testing.T) { } func TestGuestOSConfig_empty_unix(t *testing.T) { - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() + p := new(Provisioner) err := p.Prepare(config) if err != nil { @@ -58,7 +63,10 @@ func TestGuestOSConfig_empty_unix(t *testing.T) { } func TestGuestOSConfig_full_unix(t *testing.T) { - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() + p := new(Provisioner) err := p.Prepare(config) if err != nil { @@ -95,7 +103,10 @@ func TestGuestOSConfig_full_unix(t *testing.T) { } func TestGuestOSConfig_empty_windows(t *testing.T) { - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() + config["guest_os_type"] = "windows" p := new(Provisioner) err := p.Prepare(config) @@ -120,7 +131,10 @@ func TestGuestOSConfig_empty_windows(t *testing.T) { } func TestGuestOSConfig_full_windows(t *testing.T) { - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() + config["guest_os_type"] = "windows" p := new(Provisioner) err := p.Prepare(config) @@ -158,7 +172,9 @@ func TestGuestOSConfig_full_windows(t *testing.T) { } func TestProvisionerPrepare_puppetBinDir(t *testing.T) { - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() delete(config, "puppet_bin_dir") p := new(Provisioner) @@ -183,7 +199,9 @@ func TestProvisionerPrepare_puppetBinDir(t *testing.T) { } func TestProvisionerPrepare_hieraConfigPath(t *testing.T) { - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() delete(config, "hiera_config_path") p := new(Provisioner) @@ -208,7 +226,9 @@ func TestProvisionerPrepare_hieraConfigPath(t *testing.T) { } func TestProvisionerPrepare_manifestFile(t *testing.T) { - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() delete(config, "manifest_file") p := new(Provisioner) @@ -233,7 +253,9 @@ func TestProvisionerPrepare_manifestFile(t *testing.T) { } func TestProvisionerPrepare_manifestDir(t *testing.T) { - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() delete(config, "manifestdir") p := new(Provisioner) @@ -258,7 +280,9 @@ func TestProvisionerPrepare_manifestDir(t *testing.T) { } func TestProvisionerPrepare_modulePaths(t *testing.T) { - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() delete(config, "module_paths") p := new(Provisioner) @@ -291,7 +315,9 @@ func TestProvisionerPrepare_modulePaths(t *testing.T) { } func TestProvisionerPrepare_facterFacts(t *testing.T) { - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() delete(config, "facter") p := new(Provisioner) @@ -346,7 +372,9 @@ func TestProvisionerPrepare_facterFacts(t *testing.T) { } func TestProvisionerPrepare_extraArguments(t *testing.T) { - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() // Test with missing parameter delete(config, "extra_arguments") @@ -377,7 +405,9 @@ func TestProvisionerPrepare_extraArguments(t *testing.T) { } func TestProvisionerPrepare_stagingDir(t *testing.T) { - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() delete(config, "staging_directory") p := new(Provisioner) @@ -405,7 +435,9 @@ func TestProvisionerPrepare_stagingDir(t *testing.T) { } func TestProvisionerPrepare_workingDir(t *testing.T) { - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() delete(config, "working_directory") p := new(Provisioner) @@ -438,7 +470,10 @@ func TestProvisionerPrepare_workingDir(t *testing.T) { } func TestProvisionerProvision_extraArguments(t *testing.T) { - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() + ui := &packer.MachineReadableUi{ Writer: ioutil.Discard, }