packer: tests around interpolated names

This commit is contained in:
Mitchell Hashimoto 2015-05-25 18:15:07 -07:00
parent 547d9e759e
commit c12072ecad
3 changed files with 49 additions and 1 deletions

View File

@ -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)
}

View File

@ -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

View File

@ -0,0 +1,6 @@
{
"builders": [{
"name": "{{upper `name`}}",
"type": "test"
}]
}