diff --git a/provisioner/salt/provisioner.go b/provisioner/salt/provisioner.go index 833200edf..9f641828c 100644 --- a/provisioner/salt/provisioner.go +++ b/provisioner/salt/provisioner.go @@ -18,6 +18,8 @@ import ( var Ui packer.Ui +const DefaultTempConfigDir = "/tmp/salt" + type config struct { // If true, run the salt-bootstrap script SkipBootstrap bool `mapstructure:"skip_bootstrap"` @@ -72,7 +74,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error { } if p.config.TempConfigDir == "" { - p.config.TempConfigDir = "/tmp/salt" + p.config.TempConfigDir = DefaultTempConfigDir } if len(errs) > 0 { diff --git a/provisioner/salt/provisioner_test.go b/provisioner/salt/provisioner_test.go new file mode 100644 index 000000000..0e3242d1f --- /dev/null +++ b/provisioner/salt/provisioner_test.go @@ -0,0 +1,46 @@ +package salt + +import ( + "github.com/mitchellh/packer/packer" + "testing" +) + +func testConfig() map[string]interface{} { + return map[string]interface{}{ + "local_state_tree": "/Users/me/salt", + } +} + +func TestProvisioner_Impl(t *testing.T) { + var raw interface{} + raw = &Provisioner{} + if _, ok := raw.(packer.Provisioner); !ok { + t.Fatalf("must be a Provisioner") + } +} + +func TestProvisionerPrepare_Defaults(t *testing.T) { + var p Provisioner + config := testConfig() + + err := p.Prepare(config) + if err != nil { + t.Fatalf("err: %s", err) + } + + if p.config.TempConfigDir != DefaultTempConfigDir { + t.Errorf("unexpected temp config dir: %s", p.config.TempConfigDir) + } +} + +func TestProvisionerPrepare_InvalidKey(t *testing.T) { + var p Provisioner + config := testConfig() + + // Add a random key + config["i_should_not_be_valid"] = true + err := p.Prepare(config) + if err == nil { + t.Fatal("should have error") + } +}