Commit e69e74b2 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer: Panic if provisioners and no provisioner function

parent 3d0dde03
......@@ -162,6 +162,10 @@ func (t *Template) Build(name string, components *ComponentFinder) (b Build, err
panic("no builder function")
}
if len(t.Provisioners) > 0 && components.Provisioner == nil {
panic("no provisioner function")
}
builder, err := components.Builder(builderConfig.builderType)
if err != nil {
return
......
......@@ -327,6 +327,69 @@ func TestTemplate_Build_NilBuilderFunc(t *testing.T) {
template.Build("test1", &ComponentFinder{})
}
func TestTemplate_Build_NilProvisionerFunc(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 provisioner function", "right panic")
}
}()
template.Build("test1", &ComponentFinder{
Builder: func(string) (Builder, error) { return nil, nil },
})
}
func TestTemplate_Build_NilProvisionerFunc_WithNoProvisioners(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
data := `
{
"name": "my-image",
"builders": [
{
"name": "test1",
"type": "test-builder"
}
],
"provisioners": []
}
`
template, err := ParseTemplate([]byte(data))
assert.Nil(err, "should not error")
template.Build("test1", &ComponentFinder{
Builder: func(string) (Builder, error) { return nil, nil },
})
}
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