-
-
Notifications
You must be signed in to change notification settings - Fork 781
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EventManager: add timestamp and name to scheduled events
Signed-off-by: Nicola Murino <[email protected]>
- Loading branch information
Showing
2 changed files
with
45 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1933,12 +1933,27 @@ func TestScheduledActions(t *testing.T) { | |
backupsPath := filepath.Join(os.TempDir(), "backups") | ||
err := os.RemoveAll(backupsPath) | ||
assert.NoError(t, err) | ||
now := time.Now().UTC().Format(dateTimeMillisFormat) | ||
// The backup action sets the home directory to the backup path. | ||
expectedDirPath := filepath.Join(backupsPath, fmt.Sprintf("%s_%s_%s", now[0:4], now[5:7], now[8:10])) | ||
|
||
action := &dataprovider.BaseEventAction{ | ||
Name: "action", | ||
action1 := &dataprovider.BaseEventAction{ | ||
Name: "action1", | ||
Type: dataprovider.ActionTypeBackup, | ||
} | ||
err = dataprovider.AddEventAction(action, "", "", "") | ||
err = dataprovider.AddEventAction(action1, "", "", "") | ||
assert.NoError(t, err) | ||
action2 := &dataprovider.BaseEventAction{ | ||
Name: "action2", | ||
Type: dataprovider.ActionTypeFilesystem, | ||
Options: dataprovider.BaseEventActionOptions{ | ||
FsConfig: dataprovider.EventActionFilesystemConfig{ | ||
Type: dataprovider.FilesystemActionMkdirs, | ||
MkDirs: []string{"{{Year}}_{{Month}}_{{Day}}"}, | ||
}, | ||
}, | ||
} | ||
err = dataprovider.AddEventAction(action2, "", "", "") | ||
assert.NoError(t, err) | ||
rule := &dataprovider.EventRule{ | ||
Name: "rule", | ||
|
@@ -1957,10 +1972,16 @@ func TestScheduledActions(t *testing.T) { | |
Actions: []dataprovider.EventAction{ | ||
{ | ||
BaseEventAction: dataprovider.BaseEventAction{ | ||
Name: action.Name, | ||
Name: action1.Name, | ||
}, | ||
Order: 1, | ||
}, | ||
{ | ||
BaseEventAction: dataprovider.BaseEventAction{ | ||
Name: action2.Name, | ||
}, | ||
Order: 2, | ||
}, | ||
}, | ||
} | ||
|
||
|
@@ -1975,26 +1996,30 @@ func TestScheduledActions(t *testing.T) { | |
|
||
job.Run() | ||
assert.DirExists(t, backupsPath) | ||
assert.DirExists(t, expectedDirPath) | ||
|
||
action.Type = dataprovider.ActionTypeEmail | ||
action.Options = dataprovider.BaseEventActionOptions{ | ||
action1.Type = dataprovider.ActionTypeEmail | ||
action1.Options = dataprovider.BaseEventActionOptions{ | ||
EmailConfig: dataprovider.EventActionEmailConfig{ | ||
Recipients: []string{"[email protected]"}, | ||
Subject: "test with attachments", | ||
Body: "body", | ||
Attachments: []string{"/file1.txt"}, | ||
}, | ||
} | ||
err = dataprovider.UpdateEventAction(action, "", "", "") | ||
err = dataprovider.UpdateEventAction(action1, "", "", "") | ||
assert.NoError(t, err) | ||
job.Run() // action is not compatible with a scheduled rule | ||
|
||
err = dataprovider.DeleteEventRule(rule.Name, "", "", "") | ||
assert.NoError(t, err) | ||
err = dataprovider.DeleteEventAction(action.Name, "", "", "") | ||
err = dataprovider.DeleteEventAction(action1.Name, "", "", "") | ||
assert.NoError(t, err) | ||
err = dataprovider.DeleteEventAction(action2.Name, "", "", "") | ||
assert.NoError(t, err) | ||
err = os.RemoveAll(backupsPath) | ||
assert.NoError(t, err) | ||
|
||
stopEventScheduler() | ||
} | ||
|
||
|