packer: Panic if provisioners and no provisioner function
This commit is contained in:
parent
3d0dde03e6
commit
e69e74b2dc
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue