Fixes #1114, Adds upper and lower as filters for the template engine.
This commit is contained in:
parent
7b09052845
commit
13135cbf34
|
@ -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…
Reference in New Issue