packer: overrides work

This commit is contained in:
Mitchell Hashimoto 2015-05-26 09:46:04 -07:00
parent b9eea82a36
commit 53e77eacea
3 changed files with 66 additions and 2 deletions

View File

@ -144,8 +144,11 @@ func (c *Core) Build(n string) (Build, error) {
// Get the configuration
config := make([]interface{}, 1, 2)
config[0] = rawP.Config
// TODO override
if rawP.Override != nil {
if override, ok := rawP.Override[rawName]; ok {
config = append(config, override)
}
}
// If we're pausing, we wrap the provisioner in a special pauser.
if rawP.PauseBefore > 0 {

View File

@ -222,6 +222,53 @@ func TestCoreBuild_provSkipInclude(t *testing.T) {
}
}
func TestCoreBuild_provOverride(t *testing.T) {
config := TestCoreConfig(t)
testCoreTemplate(t, config, fixtureDir("build-prov-override.json"))
b := TestBuilder(t, config, "test")
p := TestProvisioner(t, config, "test")
core := TestCore(t, config)
b.ArtifactId = "hello"
build, err := core.Build("test")
if err != nil {
t.Fatalf("err: %s", err)
}
if _, err := build.Prepare(); err != nil {
t.Fatalf("err: %s", err)
}
artifact, err := build.Run(nil, nil)
if err != nil {
t.Fatalf("err: %s", err)
}
if len(artifact) != 1 {
t.Fatalf("bad: %#v", artifact)
}
if artifact[0].Id() != b.ArtifactId {
t.Fatalf("bad: %s", artifact[0].Id())
}
if !p.ProvCalled {
t.Fatal("provisioner not called")
}
found := false
for _, raw := range p.PrepConfigs {
if m, ok := raw.(map[string]interface{}); ok {
if _, ok := m["foo"]; ok {
found = true
break
}
}
}
if !found {
t.Fatal("override not called")
}
}
func TestCoreBuild_postProcess(t *testing.T) {
config := TestCoreConfig(t)
testCoreTemplate(t, config, fixtureDir("build-pp.json"))

View File

@ -0,0 +1,14 @@
{
"builders": [{
"type": "test"
}],
"provisioners": [{
"type": "test",
"override": {
"test": {
"foo": "bar"
}
}
}]
}