Commit 547d9e75 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer: test Build

parent dc74ec56
......@@ -48,6 +48,36 @@ func TestCoreBuildNames(t *testing.T) {
}
}
func TestCoreBuild_basic(t *testing.T) {
config := TestCoreConfig(t)
testCoreTemplate(t, config, fixtureDir("build-basic.json"))
b := TestBuilder(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())
}
}
func TestCoreValidate(t *testing.T) {
cases := []struct {
File string
......@@ -110,3 +140,12 @@ func testComponentFinder() *ComponentFinder {
Provisioner: provFactory,
}
}
func testCoreTemplate(t *testing.T, c *CoreConfig, p string) {
tpl, err := template.ParseFile(p)
if err != nil {
t.Fatalf("err: %s\n\n%s", p, err)
}
c.Template = tpl
}
{
"builders": [{
"type": "test"
}]
}
......@@ -42,3 +42,19 @@ func TestCore(t *testing.T, c *CoreConfig) *Core {
return core
}
// TestBuilder sets the builder with the name n to the component finder
// and returns the mock.
func TestBuilder(t *testing.T, c *CoreConfig, n string) *MockBuilder {
var b MockBuilder
c.Components.Builder = func(actual string) (Builder, error) {
if actual != n {
return nil, nil
}
return &b, nil
}
return &b
}
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