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
fab369bf
Commit
fab369bf
authored
Sep 05, 2013
by
Armon Dadgar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding support for isotime template variable
parent
1df07357
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 @
fab369bf
...
...
@@ -26,6 +26,7 @@ func NewConfigTemplate() (*ConfigTemplate, error) {
result
.
root
=
template
.
New
(
"configTemplateRoot"
)
result
.
root
.
Funcs
(
template
.
FuncMap
{
"isotime"
:
templateISOTime
,
"timestamp"
:
templateTimestamp
,
"user"
:
result
.
templateUser
,
})
...
...
@@ -79,3 +80,7 @@ func (t *ConfigTemplate) templateUser(n string) (string, error) {
func
templateTimestamp
()
string
{
return
strconv
.
FormatInt
(
time
.
Now
()
.
UTC
()
.
Unix
(),
10
)
}
func
templateISOTime
()
string
{
return
time
.
Now
()
.
UTC
()
.
Format
(
time
.
RFC3339
)
}
packer/config_template_test.go
View file @
fab369bf
...
...
@@ -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