Fixes #1114, Adds upper and lower as filters for the template engine.

This commit is contained in:
Nika Jones 2014-05-06 04:08:08 -07:00
parent 7b09052845
commit 13135cbf34
2 changed files with 39 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import (
"github.com/mitchellh/packer/common/uuid" "github.com/mitchellh/packer/common/uuid"
"os" "os"
"strconv" "strconv"
"strings"
"text/template" "text/template"
"time" "time"
) )
@ -43,6 +44,8 @@ func NewConfigTemplate() (*ConfigTemplate, error) {
"timestamp": templateTimestamp, "timestamp": templateTimestamp,
"user": result.templateUser, "user": result.templateUser,
"uuid": templateUuid, "uuid": templateUuid,
"upper": strings.ToUpper,
"lower": strings.ToLower,
}) })
return result, nil return result, nil

View File

@ -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) { func TestConfigTemplateValidate(t *testing.T) {
tpl, err := NewConfigTemplate() tpl, err := NewConfigTemplate()
if err != nil { if err != nil {