From fd2d44c212474ab516b47800bdc0f8d4889b2708 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 30 Jun 2015 10:42:55 -0700 Subject: [PATCH 1/2] helper/config: copy buildname/buildtype properly --- helper/config/decode.go | 2 ++ template/interpolate/funcs.go | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/helper/config/decode.go b/helper/config/decode.go index 177f8f930..620198e35 100644 --- a/helper/config/decode.go +++ b/helper/config/decode.go @@ -42,6 +42,8 @@ func Decode(target interface{}, config *DecodeOpts, raws ...interface{}) error { if config.InterpolateContext == nil { config.InterpolateContext = ctx } else { + config.InterpolateContext.BuildName = ctx.BuildName + config.InterpolateContext.BuildType = ctx.BuildType config.InterpolateContext.TemplatePath = ctx.TemplatePath config.InterpolateContext.UserVariables = ctx.UserVariables } diff --git a/template/interpolate/funcs.go b/template/interpolate/funcs.go index e5d01b455..75e1344ed 100644 --- a/template/interpolate/funcs.go +++ b/template/interpolate/funcs.go @@ -71,7 +71,7 @@ func funcGenBuildName(ctx *Context) interface{} { func funcGenBuildType(ctx *Context) interface{} { return func() (string, error) { if ctx == nil || ctx.BuildType == "" { - return "", errors.New("build_name not available") + return "", errors.New("build_type not available") } return ctx.BuildType, nil From ac444accb122e343ba6576f6e3e5c4dc038a8cec Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 30 Jun 2015 10:44:56 -0700 Subject: [PATCH 2/2] helper/config: tests --- helper/config/decode_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/helper/config/decode_test.go b/helper/config/decode_test.go index f9fa590c9..f325ae4a5 100644 --- a/helper/config/decode_test.go +++ b/helper/config/decode_test.go @@ -74,6 +74,36 @@ func TestDecode(t *testing.T) { }, }, }, + + "build name": { + []interface{}{ + map[string]interface{}{ + "name": "{{build_name}}", + }, + map[string]interface{}{ + "packer_build_name": "foo", + }, + }, + &Target{ + Name: "foo", + }, + nil, + }, + + "build type": { + []interface{}{ + map[string]interface{}{ + "name": "{{build_type}}", + }, + map[string]interface{}{ + "packer_builder_type": "foo", + }, + }, + &Target{ + Name: "foo", + }, + nil, + }, } for k, tc := range cases {