MCPcopy
hub / github.com/kopia/kopia / TestNotificationTemplates

Function TestNotificationTemplates

cli/command_notification_template_test.go:17–116  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15)
16
17func TestNotificationTemplates(t *testing.T) {
18 t.Parallel()
19
20 runner := testenv.NewInProcRunner(t)
21
22 e := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, runner)
23 defer e.RunAndExpectSuccess(t, "repo", "disconnect")
24
25 e.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", e.RepoDir)
26
27 defaultTemplates := e.RunAndExpectSuccess(t, "notification", "template", "list")
28 require.Len(t, defaultTemplates[1:], len(notifytemplate.SupportedTemplates()))
29
30 // initially all templates are built-in
31 for _, line := range defaultTemplates[1:] {
32 require.Contains(t, line, "<built-in>")
33 }
34
35 // override 'test-notification.txt' template from STDIN and verify.
36 runner.SetNextStdin(strings.NewReader("Subject: test-template-subject\n\ntest-template-body1\ntest-template-body2\n"))
37 e.RunAndExpectSuccess(t, "notification", "template", "set", "test-notification.txt", "--from-stdin")
38
39 verifyTemplateContents(t, e, "test-notification.txt", []string{
40 "Subject: test-template-subject",
41 "",
42 "test-template-body1",
43 "test-template-body2",
44 })
45
46 // make sure it shows up as <customized>
47 verifyHasLine(t, e.RunAndExpectSuccess(t, "notification", "template", "list"), func(s string) bool {
48 return strings.Contains(s, "test-notification.txt") && strings.Contains(s, "<customized>")
49 })
50
51 // reset 'test-notification.txt' template and verify.
52 e.RunAndExpectSuccess(t, "notification", "template", "remove", "test-notification.txt")
53
54 // make sure it shows up as <built-in>
55 verifyHasLine(t, e.RunAndExpectSuccess(t, "notification", "template", "list"), func(s string) bool {
56 return strings.Contains(s, "test-notification.txt") && strings.Contains(s, "<built-in>")
57 })
58
59 // now the same using external file
60 td := t.TempDir()
61 fname := td + "/template.md"
62
63 // no such file
64 e.RunAndExpectFailure(t, "notification", "template", "set", "test-notification.txt", "--from-file="+fname)
65
66 os.WriteFile(fname, []byte("Subject: test-template-subject\n\ntest-template-body3\ntest-template-body4\n"), 0o600)
67 e.RunAndExpectSuccess(t, "notification", "template", "set", "test-notification.txt", "--from-file="+fname)
68 verifyTemplateContents(t, e, "test-notification.txt", []string{
69 "Subject: test-template-subject",
70 "",
71 "test-template-body3",
72 "test-template-body4",
73 })
74

Callers

nothing calls this directly

Calls 12

RunAndExpectSuccessMethod · 0.95
RunAndExpectFailureMethod · 0.95
NewInProcRunnerFunction · 0.92
NewCLITestFunction · 0.92
SupportedTemplatesFunction · 0.92
verifyTemplateContentsFunction · 0.85
SetNextStdinMethod · 0.80
EqualMethod · 0.80
verifyHasLineFunction · 0.70
WriteFileMethod · 0.65
LenMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected