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 // Add a hook for the provisioners if we have provisioners
if len(b.provisioners) > 0 { 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 { if _, ok := hooks[HookProvision]; !ok {
hooks[HookProvision] = make([]Hook, 0, 1) hooks[HookProvision] = make([]Hook, 0, 1)
} }
hooks[HookProvision] = append(hooks[HookProvision], &ProvisionHook{ hooks[HookProvision] = append(hooks[HookProvision], &ProvisionHook{
Provisioners: b.provisioners, Provisioners: provisioners,
ProvisionerTypes: provisionerTypes,
}) })
} }

View File

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

View File

@ -30,7 +30,8 @@ type Provisioner interface {
type ProvisionHook struct { type ProvisionHook struct {
// The provisioners to run as part of the hook. These should already // The provisioners to run as part of the hook. These should already
// be prepared (by calling Prepare) at some earlier stage. // be prepared (by calling Prepare) at some earlier stage.
Provisioners []coreBuildProvisioner Provisioners []Provisioner
ProvisionerTypes []string
lock sync.Mutex lock sync.Mutex
runningProvisioner Provisioner runningProvisioner Provisioner
@ -57,13 +58,13 @@ func (h *ProvisionHook) Run(name string, ui Ui, comm Communicator, data interfac
h.runningProvisioner = nil h.runningProvisioner = nil
}() }()
for _, p := range h.Provisioners { for i, p := range h.Provisioners {
h.lock.Lock() h.lock.Lock()
h.runningProvisioner = p.provisioner h.runningProvisioner = p
h.lock.Unlock() h.lock.Unlock()
ts := CheckpointReporter.AddSpan(p.pType, "provisioner") ts := CheckpointReporter.AddSpan(h.ProvisionerTypes[i], "provisioner")
err := p.provisioner.Provision(ui, comm) err := p.Provision(ui, comm)
ts.End(err) ts.End(err)
if err != nil { if err != nil {
return err return err

View File

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