From 13135cbf349685bfe5d2a401101d59eb705656b4 Mon Sep 17 00:00:00 2001 From: Nika Jones Date: Tue, 6 May 2014 04:08:08 -0700 Subject: [PATCH] Fixes #1114, Adds upper and lower as filters for the template engine. --- packer/config_template.go | 3 +++ packer/config_template_test.go | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/packer/config_template.go b/packer/config_template.go index d76e3e672..2f4df9aba 100644 --- a/packer/config_template.go +++ b/packer/config_template.go @@ -6,6 +6,7 @@ import ( "github.com/mitchellh/packer/common/uuid" "os" "strconv" + "strings" "text/template" "time" ) @@ -43,6 +44,8 @@ func NewConfigTemplate() (*ConfigTemplate, error) { "timestamp": templateTimestamp, "user": result.templateUser, "uuid": templateUuid, + "upper": strings.ToUpper, + "lower": strings.ToLower, }) return result, nil diff --git a/packer/config_template_test.go b/packer/config_template_test.go index 8604f2c43..7501f2249 100644 --- a/packer/config_template_test.go +++ b/packer/config_template_test.go @@ -130,6 +130,42 @@ func TestConfigTemplateProcess_uuid(t *testing.T) { } } +func TestConfigTemplateProcess_upper(t *testing.T) { + tpl, err := NewConfigTemplate() + if err != nil { + t.Fatalf("err: %s", err) + } + + tpl.UserVars["foo"] = "bar" + + result, err := tpl.Process(`{{user "foo" | upper}}`, nil) + if err != nil { + t.Fatalf("err: %s", err) + } + + if result != "BAR" { + t.Fatalf("bad: %s", result) + } +} + +func TestConfigTemplateProcess_lower(t *testing.T) { + tpl, err := NewConfigTemplate() + if err != nil { + t.Fatalf("err: %s", err) + } + + tpl.UserVars["foo"] = "BAR" + + result, err := tpl.Process(`{{user "foo" | lower}}`, nil) + if err != nil { + t.Fatalf("err: %s", err) + } + + if result != "bar" { + t.Fatalf("bad: %s", result) + } +} + func TestConfigTemplateValidate(t *testing.T) { tpl, err := NewConfigTemplate() if err != nil {