Commit 5ac06e11 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer: Parse "hooks" configuration into the Template

parent 44bd56c3
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
type rawTemplate struct { type rawTemplate struct {
Name string Name string
Builders []map[string]interface{} Builders []map[string]interface{}
Hooks map[string][]string
Provisioners []map[string]interface{} Provisioners []map[string]interface{}
Outputs []map[string]interface{} Outputs []map[string]interface{}
} }
...@@ -21,6 +22,7 @@ type rawTemplate struct { ...@@ -21,6 +22,7 @@ type rawTemplate struct {
type Template struct { type Template struct {
Name string Name string
Builders map[string]rawBuilderConfig Builders map[string]rawBuilderConfig
Hooks map[string][]string
} }
// The rawBuilderConfig struct represents a raw, unprocessed builder // The rawBuilderConfig struct represents a raw, unprocessed builder
...@@ -44,6 +46,7 @@ func ParseTemplate(data []byte) (t *Template, err error) { ...@@ -44,6 +46,7 @@ func ParseTemplate(data []byte) (t *Template, err error) {
t = &Template{} t = &Template{}
t.Name = rawTpl.Name t.Name = rawTpl.Name
t.Builders = make(map[string]rawBuilderConfig) t.Builders = make(map[string]rawBuilderConfig)
t.Hooks = rawTpl.Hooks
for _, v := range rawTpl.Builders { for _, v := range rawTpl.Builders {
rawType, ok := v["type"] rawType, ok := v["type"]
......
...@@ -89,6 +89,29 @@ func TestParseTemplate_BuilderWithName(t *testing.T) { ...@@ -89,6 +89,29 @@ func TestParseTemplate_BuilderWithName(t *testing.T) {
assert.Equal(builder.builderName, "amazon-ebs", "builder should be amazon-ebs") assert.Equal(builder.builderName, "amazon-ebs", "builder should be amazon-ebs")
} }
func TestParseTemplate_Hooks(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
data := `
{
"name": "my-image",
"hooks": {
"event": ["foo", "bar"]
}
}
`
result, err := ParseTemplate([]byte(data))
assert.Nil(err, "should not error")
assert.NotNil(result, "template should not be nil")
assert.Length(result.Hooks, 1, "should have one hook")
hooks, ok := result.Hooks["event"]
assert.True(ok, "should have hook")
assert.Equal(hooks, []string{"foo", "bar"}, "hooks should be correct")
}
func TestTemplate_BuildNames(t *testing.T) { func TestTemplate_BuildNames(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true) 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