(t *testing.T)
| 65 | } |
| 66 | |
| 67 | func TestNotificationProfile_WebHook(t *testing.T) { |
| 68 | t.Parallel() |
| 69 | |
| 70 | e := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, testenv.NewInProcRunner(t)) |
| 71 | |
| 72 | defer e.RunAndExpectSuccess(t, "repo", "disconnect") |
| 73 | |
| 74 | e.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", e.RepoDir) |
| 75 | |
| 76 | var profiles []notifyprofile.Summary |
| 77 | |
| 78 | testutil.MustParseJSONLines(t, e.RunAndExpectSuccess(t, "notification", "profile", "list", "--json"), &profiles) |
| 79 | require.Empty(t, profiles) |
| 80 | |
| 81 | // setup a profile |
| 82 | e.RunAndExpectSuccess(t, "notification", "profile", "configure", "webhook", "--profile-name=mywebhook", "--endpoint=http://localhost:12345") |
| 83 | testutil.MustParseJSONLines(t, e.RunAndExpectSuccess(t, "notification", "profile", "list", "--json"), &profiles) |
| 84 | require.Len(t, profiles, 1) |
| 85 | require.Equal(t, "webhook", profiles[0].Type) |
| 86 | |
| 87 | // define another profile |
| 88 | e.RunAndExpectSuccess(t, "notification", "profile", "configure", "webhook", "--profile-name=myotherwebhook", "--min-severity=warning", "--endpoint=http://anotherhost:12345", "--http-header", "Foo:Bar", "--http-header", "Baz:Qux") |
| 89 | |
| 90 | lines := e.RunAndExpectSuccess(t, "notification", "profile", "list") |
| 91 | |
| 92 | require.Contains(t, lines, "Profile \"mywebhook\" Type \"webhook\" Minimum Severity: report") |
| 93 | require.Contains(t, lines, "Profile \"myotherwebhook\" Type \"webhook\" Minimum Severity: warning") |
| 94 | |
| 95 | var opt notifyprofile.Config |
| 96 | |
| 97 | testutil.MustParseJSONLines(t, e.RunAndExpectSuccess(t, "notification", "profile", "show", "--profile-name=myotherwebhook", "--json", "--raw"), &opt) |
| 98 | |
| 99 | var summ notifyprofile.Summary |
| 100 | |
| 101 | testutil.MustParseJSONLines(t, e.RunAndExpectSuccess(t, "notification", "profile", "show", "--profile-name=myotherwebhook", "--json"), &summ) |
| 102 | |
| 103 | require.Equal(t, []string{ |
| 104 | "Profile \"myotherwebhook\" Type \"webhook\" Minimum Severity: warning", |
| 105 | "Webhook POST http://anotherhost:12345 Format \"txt\"", |
| 106 | }, e.RunAndExpectSuccess(t, "notification", "profile", "show", "--profile-name=myotherwebhook")) |
| 107 | |
| 108 | var opt2 webhook.Options |
| 109 | |
| 110 | require.NoError(t, opt.MethodConfig.Options(&opt2)) |
| 111 | require.Equal(t, "Foo:Bar\nBaz:Qux", opt2.Headers) |
| 112 | |
| 113 | // partial update |
| 114 | e.RunAndExpectSuccess(t, "notification", "profile", "configure", "webhook", "--profile-name=myotherwebhook", "--method=PUT", "--format=html") |
| 115 | |
| 116 | require.Equal(t, []string{ |
| 117 | "Profile \"myotherwebhook\" Type \"webhook\" Minimum Severity: warning", |
| 118 | "Webhook PUT http://anotherhost:12345 Format \"html\"", |
| 119 | }, e.RunAndExpectSuccess(t, "notification", "profile", "show", "--profile-name=myotherwebhook")) |
| 120 | |
| 121 | // delete non-existent profile does not fail |
| 122 | e.RunAndExpectSuccess(t, "notification", "profile", "delete", "--profile-name=unknown") |
| 123 | |
| 124 | // delete existing profiles |
nothing calls this directly
no test coverage detected