packer: Parse "hooks" configuration into the Template
This commit is contained in:
parent
44bd56c3a8
commit
5ac06e116e
|
@ -12,6 +12,7 @@ import (
|
|||
type rawTemplate struct {
|
||||
Name string
|
||||
Builders []map[string]interface{}
|
||||
Hooks map[string][]string
|
||||
Provisioners []map[string]interface{}
|
||||
Outputs []map[string]interface{}
|
||||
}
|
||||
|
@ -21,6 +22,7 @@ type rawTemplate struct {
|
|||
type Template struct {
|
||||
Name string
|
||||
Builders map[string]rawBuilderConfig
|
||||
Hooks map[string][]string
|
||||
}
|
||||
|
||||
// The rawBuilderConfig struct represents a raw, unprocessed builder
|
||||
|
@ -44,6 +46,7 @@ func ParseTemplate(data []byte) (t *Template, err error) {
|
|||
t = &Template{}
|
||||
t.Name = rawTpl.Name
|
||||
t.Builders = make(map[string]rawBuilderConfig)
|
||||
t.Hooks = rawTpl.Hooks
|
||||
|
||||
for _, v := range rawTpl.Builders {
|
||||
rawType, ok := v["type"]
|
||||
|
|
|
@ -89,6 +89,29 @@ func TestParseTemplate_BuilderWithName(t *testing.T) {
|
|||
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) {
|
||||
assert := asserts.NewTestingAsserts(t, true)
|
||||
|
||||
|
|
Loading…
Reference in New Issue