MCPcopy Create free account
hub / github.com/docker/cli / TestHeaderFunctions

Function TestHeaderFunctions

templates/templates_test.go:92–142  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

NewFunction · 0.70
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…