diff --git a/packer/core.go b/packer/core.go index 4c4292ca7..cabf10359 100644 --- a/packer/core.go +++ b/packer/core.go @@ -103,7 +103,7 @@ func (c *Core) BuildNames() []string { // Build returns the Build object for the given name. func (c *Core) Build(n string) (Build, error) { // Setup the builder - configBuilder, ok := c.template.Builders[n] + configBuilder, ok := c.builds[n] if !ok { return nil, fmt.Errorf("no such build found: %s", n) } diff --git a/packer/core_test.go b/packer/core_test.go index 5935b1407..31ee34218 100644 --- a/packer/core_test.go +++ b/packer/core_test.go @@ -78,6 +78,48 @@ func TestCoreBuild_basic(t *testing.T) { } } +func TestCoreBuild_basicInterpolated(t *testing.T) { + config := TestCoreConfig(t) + testCoreTemplate(t, config, fixtureDir("build-basic-interpolated.json")) + b := TestBuilder(t, config, "test") + core := TestCore(t, config) + + b.ArtifactId = "hello" + + build, err := core.Build("NAME") + 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()) + } +} + +func TestCoreBuild_nonExist(t *testing.T) { + config := TestCoreConfig(t) + testCoreTemplate(t, config, fixtureDir("build-basic.json")) + TestBuilder(t, config, "test") + core := TestCore(t, config) + + _, err := core.Build("nope") + if err == nil { + t.Fatal("should error") + } +} + func TestCoreValidate(t *testing.T) { cases := []struct { File string diff --git a/packer/test-fixtures/build-basic-interpolated.json b/packer/test-fixtures/build-basic-interpolated.json new file mode 100644 index 000000000..c70677c52 --- /dev/null +++ b/packer/test-fixtures/build-basic-interpolated.json @@ -0,0 +1,6 @@ +{ + "builders": [{ + "name": "{{upper `name`}}", + "type": "test" + }] +}