MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / TestExecuteTemplate

Function TestExecuteTemplate

app/cli/internal/policydevel/init_test.go:136–239  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

134}
135
136func TestExecuteTemplate(t *testing.T) {
137 testCases := []struct {
138 name string
139 template string
140 data *TemplateData
141 expected string
142 }{
143 {
144 name: "basic interpolation",
145 template: "Hello {{.Name}}!",
146 data: &TemplateData{Name: "world"},
147 expected: "Hello world!",
148 },
149 {
150 name: "sanitize function",
151 template: "{{.Name | sanitize}}",
152 data: &TemplateData{Name: "My Policy"},
153 expected: "my-policy",
154 },
155 {
156 name: "indent function",
157 template: "{{indent 2 \"hello\"}}",
158 expected: " hello",
159 },
160 {
161 name: "multiple fields interpolation",
162 template: "Name: {{.Name}}, Desc: {{.Description}}",
163 data: &TemplateData{Name: "test", Description: "description"},
164 expected: "Name: test, Desc: description",
165 },
166 {
167 name: "trimSpace function",
168 template: "{{.Name | trimSpace}}",
169 data: &TemplateData{Name: " spaced "},
170 expected: "spaced",
171 },
172 {
173 name: "combined functions",
174 template: "{{.Name | trimSpace | sanitize}}",
175 data: &TemplateData{Name: " My Policy 123 "},
176 expected: "my-policy-123",
177 },
178 {
179 name: "empty template",
180 template: "",
181 data: &TemplateData{Name: "test"},
182 expected: "",
183 },
184 {
185 name: "embedded rego flag",
186 template: "Embedded: {{.Embedded}}",
187 data: &TemplateData{Embedded: true},
188 expected: "Embedded: true",
189 },
190 {
191 name: "material kind",
192 template: "Material: {{.MaterialKind}}",
193 data: &TemplateData{MaterialKind: "SBOM_CYCLONEDX_JSON"},

Callers

nothing calls this directly

Calls 3

executeTemplateFunction · 0.85
ErrorMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected