Commit 3d0dde03 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer: Panic on template if no builder function

parent d919f954
......@@ -156,6 +156,12 @@ func (t *Template) Build(name string, components *ComponentFinder) (b Build, err
return
}
// We panic if there is no builder function because this is really
// an internal bug that always needs to be fixed, not an error.
if components.Builder == nil {
panic("no builder function")
}
builder, err := components.Builder(builderConfig.builderType)
if err != nil {
return
......
......@@ -291,6 +291,42 @@ func TestTemplate_BuildUnknownBuilder(t *testing.T) {
assert.NotNil(err, "should have error")
}
func TestTemplate_Build_NilBuilderFunc(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
data := `
{
"name": "my-image",
"builders": [
{
"name": "test1",
"type": "test-builder"
}
],
"provisioners": [
{
"type": "test-prov"
}
]
}
`
template, err := ParseTemplate([]byte(data))
assert.Nil(err, "should not error")
defer func() {
p := recover()
assert.NotNil(p, "should panic")
if p != nil {
assert.Equal(p.(string), "no builder function", "right panic")
}
}()
template.Build("test1", &ComponentFinder{})
}
func TestTemplate_Build(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
......
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