fix tests.

This commit is contained in:
Matthew Hooker 2017-06-15 14:08:17 -07:00
parent 35332e4498
commit 2d581dfc7b
No known key found for this signature in database
GPG Key ID: 7B5F933D9CE8C6A1
4 changed files with 21 additions and 10 deletions

View File

@ -194,13 +194,20 @@ func (b *coreBuild) Run(originalUi Ui, cache Cache) ([]Artifact, error) {
// Add a hook for the provisioners if we have provisioners
if len(b.provisioners) > 0 {
provisioners := make([]Provisioner, len(b.provisioners))
provisionerTypes := make([]string, len(b.provisioners))
for i, p := range b.provisioners {
provisioners[i] = p.provisioner
provisionerTypes[i] = p.pType
}
if _, ok := hooks[HookProvision]; !ok {
hooks[HookProvision] = make([]Hook, 0, 1)
}
hooks[HookProvision] = append(hooks[HookProvision], &ProvisionHook{
Provisioners: b.provisioners,
Provisioners: provisioners,
ProvisionerTypes: provisionerTypes,
})
}

View File

@ -15,7 +15,7 @@ func testBuild() *coreBuild {
"foo": {&MockHook{}},
},
provisioners: []coreBuildProvisioner{
{&MockProvisioner{}, []interface{}{42}},
{"mock-provisioner", &MockProvisioner{}, []interface{}{42}},
},
postProcessors: [][]coreBuildPostProcessor{
{

View File

@ -30,7 +30,8 @@ type Provisioner interface {
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 []coreBuildProvisioner
Provisioners []Provisioner
ProvisionerTypes []string
lock sync.Mutex
runningProvisioner Provisioner
@ -57,13 +58,13 @@ func (h *ProvisionHook) Run(name string, ui Ui, comm Communicator, data interfac
h.runningProvisioner = nil
}()
for _, p := range h.Provisioners {
for i, p := range h.Provisioners {
h.lock.Lock()
h.runningProvisioner = p.provisioner
h.runningProvisioner = p
h.lock.Unlock()
ts := CheckpointReporter.AddSpan(p.pType, "provisioner")
err := p.provisioner.Provision(ui, comm)
ts := CheckpointReporter.AddSpan(h.ProvisionerTypes[i], "provisioner")
err := p.Provision(ui, comm)
ts.End(err)
if err != nil {
return err

View File

@ -24,6 +24,7 @@ func TestProvisionHook(t *testing.T) {
hook := &ProvisionHook{
Provisioners: []Provisioner{pA, pB},
ProvisionerTypes: []string{"", ""},
}
hook.Run("foo", ui, comm, data)
@ -47,6 +48,7 @@ func TestProvisionHook_nilComm(t *testing.T) {
hook := &ProvisionHook{
Provisioners: []Provisioner{pA, pB},
ProvisionerTypes: []string{"", ""},
}
err := hook.Run("foo", ui, comm, data)
@ -73,6 +75,7 @@ func TestProvisionHook_cancel(t *testing.T) {
hook := &ProvisionHook{
Provisioners: []Provisioner{p},
ProvisionerTypes: []string{""},
}
finished := make(chan struct{})