packer: ProvisionHook
This commit is contained in:
parent
73b7d94933
commit
812722c20d
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
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")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue