Commit f7cbdf41 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

provisioner/salt-masterless: verify local_state_tree exists

/cc @rgarcia
parent 104fe91b
......@@ -48,6 +48,9 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
if p.config.LocalStateTree == "" {
errs = packer.MultiErrorAppend(errs,
errors.New("Please specify a local_state_tree"))
} else if _, err := os.Stat(p.config.LocalStateTree); err != nil {
errs = packer.MultiErrorAppend(errs,
errors.New("local_state_tree must exist and be accessible"))
}
if errs != nil && len(errs.Errors) > 0 {
......
......@@ -2,12 +2,13 @@ package saltmasterless
import (
"github.com/mitchellh/packer/packer"
"os"
"testing"
)
func testConfig() map[string]interface{} {
return map[string]interface{}{
"local_state_tree": "/Users/me/salt",
"local_state_tree": os.TempDir(),
}
}
......@@ -44,3 +45,20 @@ func TestProvisionerPrepare_InvalidKey(t *testing.T) {
t.Fatal("should have error")
}
}
func TestProvisionerPrepare_LocalStateTree(t *testing.T) {
var p Provisioner
config := testConfig()
config["local_state_tree"] = "/i/dont/exist/i/think"
err := p.Prepare(config)
if err == nil {
t.Fatal("should have error")
}
config["local_state_tree"] = os.TempDir()
err = p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment