Merge pull request #1124 from njones/template-uplow

common: Fixes #1114, Adds upper and lower as filters for the template engine.
pull/1468/head
Mitchell Hashimoto 12 years ago
commit f03d57f966

@ -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

@ -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 {

Loading…
Cancel
Save