Commit 75fe58d5 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer: Post-processors are configured

parent 21869295
...@@ -109,6 +109,15 @@ func (b *coreBuild) Prepare() (err error) { ...@@ -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 return
} }
......
...@@ -16,6 +16,11 @@ func testBuild() Build { ...@@ -16,6 +16,11 @@ func testBuild() Build {
provisioners: []coreBuildProvisioner{ provisioners: []coreBuildProvisioner{
coreBuildProvisioner{&TestProvisioner{}, []interface{}{42}}, coreBuildProvisioner{&TestProvisioner{}, []interface{}{42}},
}, },
postProcessors: [][]coreBuildPostProcessor{
[]coreBuildPostProcessor{
coreBuildPostProcessor{&TestPostProcessor{}, 42},
},
},
} }
} }
...@@ -47,6 +52,11 @@ func TestBuild_Prepare(t *testing.T) { ...@@ -47,6 +52,11 @@ func TestBuild_Prepare(t *testing.T) {
prov := coreProv.provisioner.(*TestProvisioner) prov := coreProv.provisioner.(*TestProvisioner)
assert.True(prov.prepCalled, "prepare should be called") assert.True(prov.prepCalled, "prepare should be called")
assert.Equal(prov.prepConfigs, []interface{}{42, debugFalseConfig}, "prepare should be called with proper config") 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) { func TestBuild_Prepare_Twice(t *testing.T) {
......
package packer 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 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 return nil, nil
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment