fix tests.
This commit is contained in:
parent
35332e4498
commit
2d581dfc7b
|
@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ func testBuild() *coreBuild {
|
|||
"foo": {&MockHook{}},
|
||||
},
|
||||
provisioners: []coreBuildProvisioner{
|
||||
{&MockProvisioner{}, []interface{}{42}},
|
||||
{"mock-provisioner", &MockProvisioner{}, []interface{}{42}},
|
||||
},
|
||||
postProcessors: [][]coreBuildPostProcessor{
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -23,7 +23,8 @@ func TestProvisionHook(t *testing.T) {
|
|||
var data interface{} = nil
|
||||
|
||||
hook := &ProvisionHook{
|
||||
Provisioners: []Provisioner{pA, pB},
|
||||
Provisioners: []Provisioner{pA, pB},
|
||||
ProvisionerTypes: []string{"", ""},
|
||||
}
|
||||
|
||||
hook.Run("foo", ui, comm, data)
|
||||
|
@ -46,7 +47,8 @@ func TestProvisionHook_nilComm(t *testing.T) {
|
|||
var data interface{} = nil
|
||||
|
||||
hook := &ProvisionHook{
|
||||
Provisioners: []Provisioner{pA, pB},
|
||||
Provisioners: []Provisioner{pA, pB},
|
||||
ProvisionerTypes: []string{"", ""},
|
||||
}
|
||||
|
||||
err := hook.Run("foo", ui, comm, data)
|
||||
|
@ -72,7 +74,8 @@ func TestProvisionHook_cancel(t *testing.T) {
|
|||
}
|
||||
|
||||
hook := &ProvisionHook{
|
||||
Provisioners: []Provisioner{p},
|
||||
Provisioners: []Provisioner{p},
|
||||
ProvisionerTypes: []string{""},
|
||||
}
|
||||
|
||||
finished := make(chan struct{})
|
||||
|
|
Loading…
Reference in New Issue