packer: Panic on template if no builder function
This commit is contained in:
parent
d919f9545a
commit
3d0dde03e6
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue