From 2d581dfc7bccf0a48b0cf3c12e7e9c9316e35bcc Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Thu, 15 Jun 2017 14:08:17 -0700 Subject: [PATCH] fix tests. --- packer/build.go | 9 ++++++++- packer/build_test.go | 2 +- packer/provisioner.go | 11 ++++++----- packer/provisioner_test.go | 9 ++++++--- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/packer/build.go b/packer/build.go index 40f6d38ab..996c9a331 100644 --- a/packer/build.go +++ b/packer/build.go @@ -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, }) } diff --git a/packer/build_test.go b/packer/build_test.go index af5b62ebd..8fe7bc5af 100644 --- a/packer/build_test.go +++ b/packer/build_test.go @@ -15,7 +15,7 @@ func testBuild() *coreBuild { "foo": {&MockHook{}}, }, provisioners: []coreBuildProvisioner{ - {&MockProvisioner{}, []interface{}{42}}, + {"mock-provisioner", &MockProvisioner{}, []interface{}{42}}, }, postProcessors: [][]coreBuildPostProcessor{ { diff --git a/packer/provisioner.go b/packer/provisioner.go index 1fa2d66dc..639e8b1a8 100644 --- a/packer/provisioner.go +++ b/packer/provisioner.go @@ -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 diff --git a/packer/provisioner_test.go b/packer/provisioner_test.go index 7251d6f05..f303bc7d2 100644 --- a/packer/provisioner_test.go +++ b/packer/provisioner_test.go @@ -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{})