MCPcopy
hub / github.com/kopia/kopia / verifyTemplate

Function verifyTemplate

notification/notifytemplate/notifytemplate_test.go:218–246  ·  view source on GitHub ↗
(t *testing.T, embeddedTemplateName, expectedSuffix string, args any, opt notifytemplate.Options)

Source from the content-addressed store, hash-verified

216}
217
218func verifyTemplate(t *testing.T, embeddedTemplateName, expectedSuffix string, args any, opt notifytemplate.Options) {
219 t.Helper()
220
221 tmpl, err := notifytemplate.GetEmbeddedTemplate(embeddedTemplateName)
222 require.NoError(t, err)
223
224 tt, err := notifytemplate.ParseTemplate(tmpl, opt)
225 require.NoError(t, err)
226
227 var buf bytes.Buffer
228
229 require.NoError(t, tt.Execute(&buf, args))
230
231 actualFileName := filepath.Join("testdata", embeddedTemplateName+expectedSuffix+".actual")
232 require.NoError(t, os.WriteFile(actualFileName, buf.Bytes(), 0o644))
233
234 expectedFileName := filepath.Join("testdata", embeddedTemplateName+expectedSuffix+".expected")
235
236 wantBytes, err := os.ReadFile(expectedFileName)
237 require.NoError(t, err)
238
239 want := string(wantBytes)
240
241 assert.Equal(t, want, buf.String())
242
243 if want == buf.String() {
244 require.NoError(t, os.Remove(actualFileName))
245 }
246}

Calls 8

GetEmbeddedTemplateFunction · 0.92
ParseTemplateFunction · 0.92
HelperMethod · 0.80
EqualMethod · 0.80
WriteFileMethod · 0.65
RemoveMethod · 0.65
BytesMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected