packer: Template requires builders

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

View File

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

View File

@ -172,6 +172,10 @@ func ParseTemplate(data []byte) (t *Template, err error) {
raw.rawConfig = v 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 there were errors, we put it into a MultiError and return
if len(errors) > 0 { if len(errors) > 0 {
err = &MultiError{errors} err = &MultiError{errors}

View File

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