From 04a8bfb455dfd54b64fac60a6a5122f4274a7f10 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 18 Jun 2013 10:31:52 -0700 Subject: [PATCH] packer: Post-processors are configured --- packer/build.go | 9 +++++++++ packer/build_test.go | 10 ++++++++++ packer/post_processor_test.go | 15 ++++++++++++--- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/packer/build.go b/packer/build.go index a257ec65a..5d6ef5449 100644 --- a/packer/build.go +++ b/packer/build.go @@ -109,6 +109,15 @@ func (b *coreBuild) Prepare() (err error) { } } + // Prepare the post-processors + for _, ppSeq := range b.postProcessors { + for _, corePP := range ppSeq { + if err = corePP.processor.Configure(corePP.config); err != nil { + return + } + } + } + return } diff --git a/packer/build_test.go b/packer/build_test.go index f77cf8031..f06d4d613 100644 --- a/packer/build_test.go +++ b/packer/build_test.go @@ -16,6 +16,11 @@ func testBuild() Build { provisioners: []coreBuildProvisioner{ coreBuildProvisioner{&TestProvisioner{}, []interface{}{42}}, }, + postProcessors: [][]coreBuildPostProcessor{ + []coreBuildPostProcessor{ + coreBuildPostProcessor{&TestPostProcessor{}, 42}, + }, + }, } } @@ -47,6 +52,11 @@ func TestBuild_Prepare(t *testing.T) { prov := coreProv.provisioner.(*TestProvisioner) assert.True(prov.prepCalled, "prepare should be called") assert.Equal(prov.prepConfigs, []interface{}{42, debugFalseConfig}, "prepare should be called with proper config") + + corePP := coreB.postProcessors[0][0] + pp := corePP.processor.(*TestPostProcessor) + assert.True(pp.configCalled, "config should be called") + assert.Equal(pp.configVal, 42, "config should have right value") } func TestBuild_Prepare_Twice(t *testing.T) { diff --git a/packer/post_processor_test.go b/packer/post_processor_test.go index 8fc5e551a..7e06e51fe 100644 --- a/packer/post_processor_test.go +++ b/packer/post_processor_test.go @@ -1,11 +1,20 @@ package packer -type TestPostProcessor struct{} +type TestPostProcessor struct { + configCalled bool + configVal interface{} + ppCalled bool + ppArtifact Artifact +} -func (*TestPostProcessor) Configure(interface{}) error { +func (pp *TestPostProcessor) Configure(v interface{}) error { + pp.configCalled = true + pp.configVal = v return nil } -func (*TestPostProcessor) PostProcess(Artifact) (Artifact, error) { +func (pp *TestPostProcessor) PostProcess(a Artifact) (Artifact, error) { + pp.ppCalled = true + pp.ppArtifact = a return nil, nil }