Merge branch 'master' of https://github.com/armon/packer into armon-master

Conflicts:
	packer/config_template.go
This commit is contained in:
Mitchell Hashimoto 2013-09-05 17:12:15 -07:00
commit 4bd3f09099
2 changed files with 27 additions and 0 deletions

View File

@ -28,6 +28,7 @@ func NewConfigTemplate() (*ConfigTemplate, error) {
result.root = template.New("configTemplateRoot")
result.root.Funcs(template.FuncMap{
"isotime": templateISOTime,
"timestamp": templateTimestamp,
"user": result.templateUser,
"uuid": templateUuid,
@ -79,6 +80,10 @@ func (t *ConfigTemplate) templateUser(n string) (string, error) {
return result, nil
}
func templateISOTime() string {
return time.Now().UTC().Format(time.RFC3339)
}
func templateTimestamp() string {
return strconv.FormatInt(time.Now().UTC().Unix(), 10)
}

View File

@ -7,6 +7,28 @@ import (
"time"
)
func TestConfigTemplateProcess_isotime(t *testing.T) {
tpl, err := NewConfigTemplate()
if err != nil {
t.Fatalf("err: %s", err)
}
result, err := tpl.Process(`{{isotime}}`, nil)
if err != nil {
t.Fatalf("err: %s", err)
}
val, err := time.Parse(time.RFC3339, result)
if err != nil {
t.Fatalf("err: %s", err)
}
currentTime := time.Now().UTC()
if currentTime.Sub(val) > 2*time.Second {
t.Fatalf("val: %d (current: %d)", val, currentTime)
}
}
func TestConfigTemplateProcess_timestamp(t *testing.T) {
tpl, err := NewConfigTemplate()
if err != nil {