chore(template): add test cases to cleanTemplate

This commit is contained in:
Jan De Dobbeleer 2023-04-24 09:04:25 +02:00 committed by Jan De Dobbeleer
parent 077e538500
commit 1e597a7c51

View file

@ -310,10 +310,21 @@ func TestCleanTemplate(t *testing.T) {
Expected: "{{ if or (.Data.Working.Changed) (.Data.Staging.Changed) }}#FF9248{{ end }}",
Template: "{{ if or (.Working.Changed) (.Staging.Changed) }}#FF9248{{ end }}",
},
{
Case: "Global property override",
Expected: "{{.OS}}",
Template: "{{.$.OS}}",
},
{
Case: "Local property override",
Expected: "{{.Data.OS}}",
Template: "{{.OS}}",
},
}
for _, tc := range cases {
tmpl := &Text{
Template: tc.Template,
Context: map[string]interface{}{"OS": "posh"},
}
tmpl.cleanTemplate()
assert.Equal(t, tc.Expected, tmpl.Template, tc.Case)