diff --git a/provisioner/salt-masterless/provisioner.go b/provisioner/salt-masterless/provisioner.go index e9eac5787..e60702ccf 100644 --- a/provisioner/salt-masterless/provisioner.go +++ b/provisioner/salt-masterless/provisioner.go @@ -363,7 +363,7 @@ func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.C for _, f := range formulas { if _, err := os.Stat(f); !os.IsNotExist(err) && f != p.config.LocalStateTree { ui.Message(fmt.Sprintf("Removing Salt formula: %s", f)) - os.RemoveAll(f) + defer os.RemoveAll(f) } } } diff --git a/provisioner/salt-masterless/provisioner_test.go b/provisioner/salt-masterless/provisioner_test.go index c38a9b879..42dc7f686 100644 --- a/provisioner/salt-masterless/provisioner_test.go +++ b/provisioner/salt-masterless/provisioner_test.go @@ -325,3 +325,33 @@ func TestProvisionerPrepare_GuestOSType(t *testing.T) { t.Fatalf("GuestOSType should be 'windows'") } } + +func TestProvisionerPrepare_BadFormulaURL(t *testing.T) { + var p Provisioner + config := testConfig() + + config["formulas"] = []string{ + "git::https://github.com/org/some-formula.git//", + } + + err := p.Prepare(config) + if err == nil { + t.Fatalf("Expected invalid formula URL: %s", err) + } +} + +func TestProvisionerPrepare_ValidFormulaURLs(t *testing.T) { + + var p Provisioner + config := testConfig() + + config["formulas"] = []string{ + "git::https://github.com/org/some-formula.git//example", + "git@github.com:org/some-formula.git//example", + } + + err := p.Prepare(config) + if err != nil { + t.Fatalf("Unexpected error in formula URLs: %s", err) + } +}