mirror of
https://github.com/hashicorp/packer.git
synced 2026-09-28 02:34:02 -04:00
packer: Panic on template if no builder function
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user