From 8e617d006b96445104572a45a2ed67d2cedfd05c Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 11 Dec 2013 13:43:43 -0800 Subject: [PATCH] packer: Add description to top-level template [GH-658] --- packer/template.go | 3 +++ packer/template_test.go | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/packer/template.go b/packer/template.go index 180b02c0f..6c601d05b 100644 --- a/packer/template.go +++ b/packer/template.go @@ -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 diff --git a/packer/template_test.go b/packer/template_test.go index d5299f4ac..053a4705d 100644 --- a/packer/template_test.go +++ b/packer/template_test.go @@ -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.