Commit 812722c2 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer: ProvisionHook

parent 73b7d949
......@@ -14,3 +14,17 @@ type Provisioner interface {
// can be done.
Provision(Ui, Communicator)
}
// A Hook implementation that runs the given provisioners.
type ProvisionHook struct {
// The provisioners to run as part of the hook. These should already
// be prepared (by calling Prepare) at some earlier stage.
Provisioners []Provisioner
}
// Runs the provisioners in order.
func (h *ProvisionHook) Run(name string, ui Ui, comm Communicator, data interface{}) {
for _, p := range h.Provisioners {
p.Provision(ui, comm)
}
}
package packer
import "testing"
type TestProvisioner struct {
prepCalled bool
prepConfig interface{}
......@@ -16,3 +18,31 @@ func (t *TestProvisioner) Prepare(config interface{}, ui Ui) {
func (t *TestProvisioner) Provision(Ui, Communicator) {
t.provCalled = true
}
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")
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment