packer: Template requires builders

This commit is contained in:
Mitchell Hashimoto 2013-06-29 14:02:20 -07:00
parent 57c53ea2d7
commit 377f7ba3cd
3 changed files with 17 additions and 2 deletions

View File

@ -2,6 +2,7 @@
IMPROVEMENTS:
* core: Template doesn't validate if there are no builders.
* vmware: Delete any VMware files in the VM that aren't necessary for
it to function.

View File

@ -172,6 +172,10 @@ func ParseTemplate(data []byte) (t *Template, err error) {
raw.rawConfig = v
}
if len(t.Builders) == 0 {
errors = append(errors, fmt.Errorf("No builders are defined in the template."))
}
// If there were errors, we put it into a MultiError and return
if len(errors) > 0 {
err = &MultiError{errors}

View File

@ -11,14 +11,14 @@ func TestParseTemplate_Basic(t *testing.T) {
data := `
{
"builders": []
"builders": [{"type": "something"}]
}
`
result, err := ParseTemplate([]byte(data))
assert.Nil(err, "should not error")
assert.NotNil(result, "template should not be nil")
assert.Length(result.Builders, 0, "no builders")
assert.Length(result.Builders, 1, "one builder")
}
func TestParseTemplate_Invalid(t *testing.T) {
@ -140,6 +140,8 @@ func TestParseTemplate_Hooks(t *testing.T) {
data := `
{
"builders": [{"type": "foo"}],
"hooks": {
"event": ["foo", "bar"]
}
@ -159,6 +161,8 @@ func TestParseTemplate_Hooks(t *testing.T) {
func TestParseTemplate_PostProcessors(t *testing.T) {
data := `
{
"builders": [{"type": "foo"}],
"post-processors": [
"simple",
@ -215,6 +219,8 @@ func TestParseTemplate_ProvisionerWithoutType(t *testing.T) {
data := `
{
"builders": [{"type": "foo"}],
"provisioners": [{}]
}
`
@ -228,6 +234,8 @@ func TestParseTemplate_ProvisionerWithNonStringType(t *testing.T) {
data := `
{
"builders": [{"type": "foo"}],
"provisioners": [{
"type": 42
}]
@ -243,6 +251,8 @@ func TestParseTemplate_Provisioners(t *testing.T) {
data := `
{
"builders": [{"type": "foo"}],
"provisioners": [
{
"type": "shell"