Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
4bd3f090
Commit
4bd3f090
authored
Sep 05, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://github.com/armon/packer
into armon-master
Conflicts: packer/config_template.go
parents
acd9f3c9
fab369bf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
0 deletions
+27
-0
packer/config_template.go
packer/config_template.go
+5
-0
packer/config_template_test.go
packer/config_template_test.go
+22
-0
No files found.
packer/config_template.go
View file @
4bd3f090
...
...
@@ -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
)
}
...
...
packer/config_template_test.go
View file @
4bd3f090
...
...
@@ -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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment