packer: Add description to top-level template [GH-658]
This commit is contained in:
parent
fe22308a2d
commit
8e617d006b
|
@ -16,6 +16,7 @@ import (
|
|||
// "interface{}" pointers since we actually don't know what their contents
|
||||
// are until we read the "type" field.
|
||||
type rawTemplate struct {
|
||||
Description string
|
||||
Variables map[string]interface{}
|
||||
Builders []map[string]interface{}
|
||||
Hooks map[string][]string
|
||||
|
@ -26,6 +27,7 @@ type rawTemplate struct {
|
|||
// The Template struct represents a parsed template, parsed into the most
|
||||
// completed form it can be without additional processing by the caller.
|
||||
type Template struct {
|
||||
Description string
|
||||
Variables map[string]RawVariable
|
||||
Builders map[string]RawBuilderConfig
|
||||
Hooks map[string][]string
|
||||
|
@ -115,6 +117,7 @@ func ParseTemplate(data []byte) (t *Template, err error) {
|
|||
}
|
||||
|
||||
t = &Template{}
|
||||
t.Description = rawTpl.Description
|
||||
t.Variables = make(map[string]RawVariable)
|
||||
t.Builders = make(map[string]RawBuilderConfig)
|
||||
t.Hooks = rawTpl.Hooks
|
||||
|
|
|
@ -111,6 +111,26 @@ func TestParseTemplate_Basic(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestParseTemplate_Description(t *testing.T) {
|
||||
data := `
|
||||
{
|
||||
"description": "Foo",
|
||||
"builders": [{"type": "something"}]
|
||||
}
|
||||
`
|
||||
|
||||
result, err := ParseTemplate([]byte(data))
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
if result == nil {
|
||||
t.Fatal("should have result")
|
||||
}
|
||||
if result.Description != "Foo" {
|
||||
t.Fatalf("bad: %#v", result.Description)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseTemplate_Invalid(t *testing.T) {
|
||||
// Note there is an extra comma below for a purposeful
|
||||
// syntax error in the JSON.
|
||||
|
|
Loading…
Reference in New Issue