test(pkg/engine): add tests for TOML parsing

Signed-off-by: Dominik Müller <mail@dominikm.de>
pull/12026/head
Dominik Müller 1 year ago
parent f550eda6e9
commit 266ab5af05

@ -71,7 +71,7 @@ func TestFuncMap(t *testing.T) {
}
// Test for Engine-specific template functions.
expect := []string{"include", "required", "tpl", "toYaml", "fromYaml", "toToml", "toJson", "fromJson", "lookup"}
expect := []string{"include", "required", "tpl", "toYaml", "fromYaml", "toToml", "fromToml", "toJson", "fromJson", "lookup"}
for _, f := range expect {
if _, ok := fns[f]; !ok {
t.Errorf("Expected add-on function %q", f)

@ -37,6 +37,30 @@ func TestFuncs(t *testing.T) {
tpl: `{{ toToml . }}`,
expect: "foo = \"bar\"\n",
vars: map[string]interface{}{"foo": "bar"},
}, {
tpl: `{{ fromToml . }}`,
expect: "map[hello:world]",
vars: `hello = "world"`,
}, {
tpl: `{{ fromToml . }}`,
expect: "map[table:map[keyInTable:valueInTable subtable:map[keyInSubtable:valueInSubTable]]]",
vars: `
[table]
keyInTable = "valueInTable"
[table.subtable]
keyInSubtable = "valueInSubTable"`,
}, {
tpl: `{{ fromToml . }}`,
expect: "map[tableArray:[map[keyInElement0:valueInElement0] map[keyInElement1:valueInElement1]]]",
vars: `
[[tableArray]]
keyInElement0 = "valueInElement0"
[[tableArray]]
keyInElement1 = "valueInElement1"`,
}, {
tpl: `{{ fromToml . }}`,
expect: "map[Error:toml: line 0: unexpected EOF; expected key separator '=']",
vars: "one",
}, {
tpl: `{{ toJson . }}`,
expect: `{"foo":"bar"}`,

Loading…
Cancel
Save