Skip to content

Commit da9e984

Browse files
authored
Merge pull request docker#5541 from thaJeztah/template_coverage
templates: add test for HeaderFunctions
2 parents 3865327 + 12dcc6e commit da9e984

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

templates/templates_test.go

+52
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,55 @@ func TestParseTruncateFunction(t *testing.T) {
8989
})
9090
}
9191
}
92+
93+
func TestHeaderFunctions(t *testing.T) {
94+
const source = "hello world"
95+
96+
tests := []struct {
97+
doc string
98+
template string
99+
}{
100+
{
101+
doc: "json",
102+
template: `{{ json .}}`,
103+
},
104+
{
105+
doc: "split",
106+
template: `{{ split . ","}}`,
107+
},
108+
{
109+
doc: "join",
110+
template: `{{ join . ","}}`,
111+
},
112+
{
113+
doc: "title",
114+
template: `{{ title .}}`,
115+
},
116+
{
117+
doc: "lower",
118+
template: `{{ lower .}}`,
119+
},
120+
{
121+
doc: "upper",
122+
template: `{{ upper .}}`,
123+
},
124+
{
125+
doc: "truncate",
126+
template: `{{ truncate . 2}}`,
127+
},
128+
}
129+
130+
for _, tc := range tests {
131+
t.Run(tc.doc, func(t *testing.T) {
132+
tmpl, err := New("").Funcs(HeaderFunctions).Parse(tc.template)
133+
assert.NilError(t, err)
134+
135+
var b bytes.Buffer
136+
assert.NilError(t, tmpl.Execute(&b, source))
137+
138+
// All header-functions are currently stubs, and don't modify the input.
139+
expected := source
140+
assert.Equal(t, expected, b.String())
141+
})
142+
}
143+
}

0 commit comments

Comments
 (0)