Added Prepare tests around formula URLs

Signed-off-by: Andrew Cornies <acornies@gmail.com>
This commit is contained in:
Andrew Cornies 2020-08-06 14:48:25 -04:00
parent a2ea308881
commit 24739270cf
2 changed files with 31 additions and 1 deletions

View File

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

View File

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