Skip to content

Commit

Permalink
Added atoi function to template funcs and test
Browse files Browse the repository at this point in the history
  • Loading branch information
dcode committed Feb 15, 2018
1 parent 9671ca0 commit d84d890
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions resource/template/template_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"path"
"sort"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -45,6 +46,7 @@ func newFuncMap() map[string]interface{} {
m["mod"] = func(a, b int) int { return a % b }
m["mul"] = func(a, b int) int { return a * b }
m["seq"] = Seq
m["atoi"] = strconv.Atoi
return m
}

Expand Down
19 changes: 19 additions & 0 deletions resource/template/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,25 @@ dest = "./tmp/test.conf"
[1 2 3]
`,
updateStore: func(tr *TemplateResource) {},
}, templateTest{
desc: "atoi test",
toml: `
[template]
src = "test.conf.tmpl"
dest = "./tmp/test.conf"
keys = [
"/test/count/",
]
`,
tmpl: `
{{ seq 1 (atoi (getv "/test/count")) }}
`,
expected: `
[1 2 3]
`,
updateStore: func(tr *TemplateResource) {
tr.store.Set("/test/count", "3")
},
},
}

Expand Down

0 comments on commit d84d890

Please sign in to comment.