packer-cn/packer/provisioner_test.go

50 lines
945 B
Go
Raw Normal View History

2013-05-22 15:39:30 -07:00
package packer
2013-05-23 21:13:18 -07:00
import "testing"
2013-05-22 15:39:30 -07:00
type TestProvisioner struct {
prepCalled bool
prepConfigs []interface{}
provCalled bool
2013-05-22 15:39:30 -07:00
}
2013-06-06 17:07:42 -07:00
func (t *TestProvisioner) Prepare(configs ...interface{}) error {
2013-05-22 15:39:30 -07:00
t.prepCalled = true
t.prepConfigs = configs
2013-06-06 17:07:42 -07:00
return nil
2013-05-22 15:39:30 -07:00
}
func (t *TestProvisioner) Provision(Ui, Communicator) {
t.provCalled = true
}
2013-05-23 21:13:18 -07:00
func TestProvisionHook_Impl(t *testing.T) {
var raw interface{}
raw = &ProvisionHook{}
if _, ok := raw.(Hook); !ok {
t.Fatalf("must be a Hook")
}
}
func TestProvisionHook(t *testing.T) {
pA := &TestProvisioner{}
pB := &TestProvisioner{}
ui := testUi()
var comm Communicator = nil
var data interface{} = nil
hook := &ProvisionHook{[]Provisioner{pA, pB}}
hook.Run("foo", ui, comm, data)
if !pA.provCalled {
t.Error("provision should be called on pA")
}
if !pB.provCalled {
t.Error("provision should be called on pB")
}
}
2013-05-23 21:13:40 -07:00
// TODO(mitchellh): Test that they're run in the proper order