provisioner/salt: simple tests

This commit is contained in:
Rafael Garcia 2013-07-27 00:11:04 -07:00
parent 8fe0733676
commit 1b0d316456
2 changed files with 49 additions and 1 deletions

View File

@ -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 {

View File

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