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
5d205ec1
Commit
5d205ec1
authored
May 15, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
template/interpolate: wd
parent
125369d1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
0 deletions
+37
-0
template/interpolate/funcs.go
template/interpolate/funcs.go
+7
-0
template/interpolate/funcs_test.go
template/interpolate/funcs_test.go
+30
-0
No files found.
template/interpolate/funcs.go
View file @
5d205ec1
...
...
@@ -9,6 +9,7 @@ import (
// Funcs are the interpolation funcs that are available within interpolations.
var
FuncGens
=
map
[
string
]
FuncGenerator
{
"env"
:
funcGenEnv
,
"pwd"
:
funcGenPwd
,
"user"
:
funcGenUser
,
}
...
...
@@ -39,6 +40,12 @@ func funcGenEnv(ctx *Context) interface{} {
}
}
func
funcGenPwd
(
ctx
*
Context
)
interface
{}
{
return
func
()
(
string
,
error
)
{
return
os
.
Getwd
()
}
}
func
funcGenUser
(
ctx
*
Context
)
interface
{}
{
return
func
()
string
{
return
""
...
...
template/interpolate/funcs_test.go
View file @
5d205ec1
...
...
@@ -64,3 +64,33 @@ func TestFuncEnv_disable(t *testing.T) {
}
}
}
func
TestFuncPwd
(
t
*
testing
.
T
)
{
wd
,
err
:=
os
.
Getwd
()
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
cases
:=
[]
struct
{
Input
string
Output
string
}{
{
`{{pwd}}`
,
wd
,
},
}
ctx
:=
&
Context
{}
for
_
,
tc
:=
range
cases
{
i
:=
&
I
{
Value
:
tc
.
Input
}
result
,
err
:=
i
.
Render
(
ctx
)
if
err
!=
nil
{
t
.
Fatalf
(
"Input: %s
\n\n
err: %s"
,
tc
.
Input
,
err
)
}
if
result
!=
tc
.
Output
{
t
.
Fatalf
(
"Input: %s
\n\n
Got: %s"
,
tc
.
Input
,
result
)
}
}
}
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