2013-05-22 18:39:30 -04:00
|
|
|
package packer
|
|
|
|
|
2013-05-24 00:13:18 -04:00
|
|
|
import "testing"
|
|
|
|
|
2013-05-22 18:39:30 -04:00
|
|
|
type TestProvisioner struct {
|
|
|
|
prepCalled bool
|
2013-05-22 19:29:07 -04:00
|
|
|
prepConfig interface{}
|
|
|
|
prepUi Ui
|
2013-05-22 18:39:30 -04:00
|
|
|
provCalled bool
|
|
|
|
}
|
|
|
|
|
2013-05-22 19:29:07 -04:00
|
|
|
func (t *TestProvisioner) Prepare(config interface{}, ui Ui) {
|
2013-05-22 18:39:30 -04:00
|
|
|
t.prepCalled = true
|
2013-05-22 19:29:07 -04:00
|
|
|
t.prepConfig = config
|
|
|
|
t.prepUi = ui
|
2013-05-22 18:39:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *TestProvisioner) Provision(Ui, Communicator) {
|
|
|
|
t.provCalled = true
|
|
|
|
}
|
2013-05-24 00:13:18 -04: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")
|
|
|
|
}
|
|
|
|
}
|