provisioner/salt: simple tests
This commit is contained in:
parent
9c25bb5cd7
commit
5feadedba2
@ -18,6 +18,8 @@ import (
|
|||||||
|
|
||||||
var Ui packer.Ui
|
var Ui packer.Ui
|
||||||
|
|
||||||
|
const DefaultTempConfigDir = "/tmp/salt"
|
||||||
|
|
||||||
type config struct {
|
type config struct {
|
||||||
// If true, run the salt-bootstrap script
|
// If true, run the salt-bootstrap script
|
||||||
SkipBootstrap bool `mapstructure:"skip_bootstrap"`
|
SkipBootstrap bool `mapstructure:"skip_bootstrap"`
|
||||||
@ -72,7 +74,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if p.config.TempConfigDir == "" {
|
if p.config.TempConfigDir == "" {
|
||||||
p.config.TempConfigDir = "/tmp/salt"
|
p.config.TempConfigDir = DefaultTempConfigDir
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(errs) > 0 {
|
if len(errs) > 0 {
|
||||||
|
46
provisioner/salt/provisioner_test.go
Normal file
46
provisioner/salt/provisioner_test.go
Normal 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")
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user