Commit f03d57f9 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

Merge pull request #1124 from njones/template-uplow

common: Fixes #1114, Adds upper and lower as filters for the template engine.
parents 880ac531 13135cbf
......@@ -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 {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment