fix tests

This commit is contained in:
Matthew Hooker 2017-11-02 23:31:32 -07:00
parent 46f41d1f12
commit 3e3768ec3e
No known key found for this signature in database
GPG Key ID: 7B5F933D9CE8C6A1
3 changed files with 23 additions and 21 deletions

View File

@ -194,20 +194,12 @@ 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: provisioners,
ProvisionerTypes: provisionerTypes,
Provisioners: b.provisioners,
})
}

View File

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

View File

@ -23,8 +23,10 @@ func TestProvisionHook(t *testing.T) {
var data interface{} = nil
hook := &ProvisionHook{
Provisioners: []Provisioner{pA, pB},
ProvisionerTypes: []string{"", ""},
Provisioners: []coreBuildProvisioner{
{"", pA, nil},
{"", pB, nil},
},
}
hook.Run("foo", ui, comm, data)
@ -47,8 +49,10 @@ func TestProvisionHook_nilComm(t *testing.T) {
var data interface{} = nil
hook := &ProvisionHook{
Provisioners: []Provisioner{pA, pB},
ProvisionerTypes: []string{"", ""},
Provisioners: []coreBuildProvisioner{
{"", pA, nil},
{"", pB, nil},
},
}
err := hook.Run("foo", ui, comm, data)
@ -74,8 +78,9 @@ func TestProvisionHook_cancel(t *testing.T) {
}
hook := &ProvisionHook{
Provisioners: []Provisioner{p},
ProvisionerTypes: []string{""},
Provisioners: []coreBuildProvisioner{
{"", p, nil},
},
}
finished := make(chan struct{})