Skip to content

Commit

Permalink
Merge pull request #5541 from thaJeztah/template_coverage
Browse files Browse the repository at this point in the history
templates: add test for HeaderFunctions
  • Loading branch information
thaJeztah authored Oct 18, 2024
2 parents 3865327 + 12dcc6e commit da9e984
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions templates/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,55 @@ func TestParseTruncateFunction(t *testing.T) {
})
}
}

func TestHeaderFunctions(t *testing.T) {
const source = "hello world"

tests := []struct {
doc string
template string
}{
{
doc: "json",
template: `{{ json .}}`,
},
{
doc: "split",
template: `{{ split . ","}}`,
},
{
doc: "join",
template: `{{ join . ","}}`,
},
{
doc: "title",
template: `{{ title .}}`,
},
{
doc: "lower",
template: `{{ lower .}}`,
},
{
doc: "upper",
template: `{{ upper .}}`,
},
{
doc: "truncate",
template: `{{ truncate . 2}}`,
},
}

for _, tc := range tests {
t.Run(tc.doc, func(t *testing.T) {
tmpl, err := New("").Funcs(HeaderFunctions).Parse(tc.template)
assert.NilError(t, err)

var b bytes.Buffer
assert.NilError(t, tmpl.Execute(&b, source))

// All header-functions are currently stubs, and don't modify the input.
expected := source
assert.Equal(t, expected, b.String())
})
}
}

0 comments on commit da9e984

Please sign in to comment.