Remove tmp files created by provisioner/puppet-masterless tests

This commit is contained in:
DanHam 2018-04-25 19:49:13 +01:00
parent 25dd27a164
commit fd07cfd2b1
No known key found for this signature in database
GPG Key ID: 58E79AEDD6AA987E
1 changed files with 51 additions and 16 deletions

View File

@ -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,
}