mirror of
https://github.com/hashicorp/packer.git
synced 2026-09-27 02:04:01 -04:00
Fixes #1114, Adds upper and lower as filters for the template engine.
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user