From 5d37c584575b0b2bb165c5559d6b02c7522f505f Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Tue, 3 Feb 2015 18:14:21 -0500 Subject: [PATCH] Store the RawContents of the template on the template object This allows children to get the raw templates without re-reading the file. --- packer/template.go | 9 ++++++--- packer/template_test.go | 4 ++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packer/template.go b/packer/template.go index 5cbef4fac..717ae7682 100644 --- a/packer/template.go +++ b/packer/template.go @@ -3,15 +3,16 @@ package packer import ( "bytes" "fmt" - "github.com/hashicorp/go-version" - "github.com/mitchellh/mapstructure" - jsonutil "github.com/mitchellh/packer/common/json" "io" "io/ioutil" "os" "sort" "text/template" "time" + + "github.com/hashicorp/go-version" + "github.com/mitchellh/mapstructure" + jsonutil "github.com/mitchellh/packer/common/json" ) // The rawTemplate struct represents the structure of a template read @@ -33,6 +34,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 { + RawContents []byte Description string Variables map[string]RawVariable Builders map[string]RawBuilderConfig @@ -163,6 +165,7 @@ func ParseTemplate(data []byte, vars map[string]string) (t *Template, err error) } t = &Template{} + t.RawContents = data t.Description = rawTpl.Description t.Variables = make(map[string]RawVariable) t.Builders = make(map[string]RawBuilderConfig) diff --git a/packer/template_test.go b/packer/template_test.go index d42895665..bf11fc7d0 100644 --- a/packer/template_test.go +++ b/packer/template_test.go @@ -58,6 +58,10 @@ func TestParseTemplateFile_basic(t *testing.T) { if len(result.Builders) != 1 { t.Fatalf("bad: %#v", result.Builders) } + + if string(result.RawContents) != data { + t.Fatalf("expected %q to be %q", result.RawContents, data) + } } func TestParseTemplateFile_minPackerVersionBad(t *testing.T) {