Commit 5d205ec1 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

template/interpolate: wd

parent 125369d1
......@@ -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)
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment