add toYaml and fromYaml

Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
yxxhero 2022-05-21 12:13:19 +08:00 committed by yxxhero
parent 33c66a6f46
commit 23b6429f33
1 changed files with 24 additions and 0 deletions

View File

@ -110,6 +110,28 @@ var readFileTestCases = []tmplTestCase{
},
}
var toYamlTestCases = []tmplTestCase{
{
data: map[string]string{
"test": "test",
},
name: "toYaml",
tmplString: `{{ . | toYaml }}`,
output: "test: test\n",
},
}
var fromYamlTestCases = []tmplTestCase{
{
name: "fromYaml",
tmplString: `{{ $value := "test: test" | fromYaml }}
{{- $value.test }}`,
output: "test",
},
}
// tmplTestCases are the test cases for the template tests
type tmplE2e struct {
tcs []tmplTestCase
@ -127,6 +149,8 @@ func (t *tmplE2e) load() {
t.append(envExecTestCases...)
t.append(execTestCases...)
t.append(readFileTestCases...)
t.append(toYamlTestCases...)
t.append(fromYamlTestCases...)
}
var tmplE2eTest = tmplE2e{}