Commit d180df00 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer: Template requires builders

parent bd8f8941
...@@ -2,6 +2,7 @@ ...@@ -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.
......
...@@ -172,6 +172,10 @@ func ParseTemplate(data []byte) (t *Template, err error) { ...@@ -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}
......
...@@ -11,14 +11,14 @@ func TestParseTemplate_Basic(t *testing.T) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -243,6 +251,8 @@ func TestParseTemplate_Provisioners(t *testing.T) {
data := ` data := `
{ {
"builders": [{"type": "foo"}],
"provisioners": [ "provisioners": [
{ {
"type": "shell" "type": "shell"
......
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