(t *testing.T)
| 15 | ) |
| 16 | |
| 17 | func 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 |
nothing calls this directly
no test coverage detected