MCPcopy
hub / github.com/kopia/kopia / TestNotificationProfile

Function TestNotificationProfile

cli/command_notification_profile_test.go:14–65  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestNotificationProfile(t *testing.T) {
15 t.Parallel()
16
17 e := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, testenv.NewInProcRunner(t))
18
19 defer e.RunAndExpectSuccess(t, "repo", "disconnect")
20
21 e.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", e.RepoDir)
22
23 // no profiles
24 e.RunAndExpectFailure(t, "notification", "profile", "show", "--profile-name=no-such-profile")
25
26 var profiles []notifyprofile.Summary
27
28 testutil.MustParseJSONLines(t, e.RunAndExpectSuccess(t, "notification", "profile", "list", "--json"), &profiles)
29 require.Empty(t, profiles)
30
31 // setup a profile
32 e.RunAndExpectSuccess(t, "notification", "profile", "configure", "testsender", "--profile-name=mywebhook", "--send-test-notification")
33 testutil.MustParseJSONLines(t, e.RunAndExpectSuccess(t, "notification", "profile", "list", "--json"), &profiles)
34 require.Len(t, profiles, 1)
35 require.Equal(t, "testsender", profiles[0].Type)
36
37 // one test message sent
38 require.Len(t, e.NotificationsSent(), 1)
39
40 // now send a test message
41 e.RunAndExpectSuccess(t, "notification", "profile", "test", "--profile-name=mywebhook")
42 e.RunAndExpectFailure(t, "notification", "profile", "show", "--profile-name=no-such-profile")
43
44 // make sure we received the test message
45 require.Len(t, e.NotificationsSent(), 2)
46 require.Contains(t, e.NotificationsSent()[0].Body, "If you received this, your notification configuration")
47
48 // define another profile
49 e.RunAndExpectSuccess(t, "notification", "profile", "configure", "testsender", "--profile-name=myotherwebhook", "--min-severity=warning")
50
51 lines := e.RunAndExpectSuccess(t, "notification", "profile", "list")
52
53 require.Contains(t, lines, "Profile \"mywebhook\" Type \"testsender\" Minimum Severity: report")
54 require.Contains(t, lines, "Profile \"myotherwebhook\" Type \"testsender\" Minimum Severity: warning")
55
56 // delete non-existent profile does not fail
57 e.RunAndExpectSuccess(t, "notification", "profile", "delete", "--profile-name=unknown")
58
59 // delete existing profiles
60 e.RunAndExpectSuccess(t, "notification", "profile", "delete", "--profile-name=myotherwebhook")
61 e.RunAndExpectSuccess(t, "notification", "profile", "delete", "--profile-name=mywebhook")
62
63 // no profiles left
64 require.Empty(t, e.RunAndExpectSuccess(t, "notification", "profile", "list"))
65}
66
67func TestNotificationProfile_WebHook(t *testing.T) {
68 t.Parallel()

Callers

nothing calls this directly

Calls 9

RunAndExpectSuccessMethod · 0.95
RunAndExpectFailureMethod · 0.95
NotificationsSentMethod · 0.95
NewCLITestFunction · 0.92
NewInProcRunnerFunction · 0.92
MustParseJSONLinesFunction · 0.92
EqualMethod · 0.80
LenMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected