mirror of
https://github.com/hashicorp/packer.git
synced 2026-09-26 09:44:01 -04:00
template/interpolate: wd
This commit is contained in:
@@ -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 ""
|
||||
|
||||
@@ -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\nerr: %s", tc.Input, err)
|
||||
}
|
||||
|
||||
if result != tc.Output {
|
||||
t.Fatalf("Input: %s\n\nGot: %s", tc.Input, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user