actions: add a generic hook to define external commands and HTTP URL

We can only define a single hook now and it can be an HTTP notification
or an external command, not both
This commit is contained in:
Nicola Murino
2020-05-24 15:29:39 +02:00
parent 760cc9ba5a
commit c27e3ef436
8 changed files with 130 additions and 71 deletions

View File

@@ -159,9 +159,8 @@ func TestWrongActions(t *testing.T) {
badCommand = "C:\\bad\\command"
}
actions = Actions{
ExecuteOn: []string{operationDownload},
Command: badCommand,
HTTPNotificationURL: "",
ExecuteOn: []string{operationDownload},
Hook: badCommand,
}
user := dataprovider.User{
Username: "username",
@@ -170,21 +169,27 @@ func TestWrongActions(t *testing.T) {
assert.Error(t, err, "action with bad command must fail")
err = executeAction(newActionNotification(user, operationDelete, "path", "", "", 0, nil))
assert.NoError(t, err)
actions.Command = ""
actions.HTTPNotificationURL = "http://foo\x7f.com/"
assert.EqualError(t, err, errUnconfiguredAction.Error())
actions.Hook = "http://foo\x7f.com/"
err = executeAction(newActionNotification(user, operationDownload, "path", "", "", 0, nil))
assert.Error(t, err, "action with bad url must fail")
actions.Hook = ""
err = executeAction(newActionNotification(user, operationDownload, "path", "", "", 0, nil))
assert.Error(t, err, errNoHook.Error())
actions.Hook = "relative path"
err = executeNotificationCommand(newActionNotification(user, operationDownload, "path", "", "", 0, nil))
assert.EqualError(t, err, fmt.Sprintf("invalid notification command %#v", actions.Hook))
actions = actionsCopy
}
func TestActionHTTP(t *testing.T) {
actionsCopy := actions
actions = Actions{
ExecuteOn: []string{operationDownload},
Command: "",
HTTPNotificationURL: "http://127.0.0.1:8080/",
ExecuteOn: []string{operationDownload},
Hook: "http://127.0.0.1:8080/",
}
user := dataprovider.User{
Username: "username",