mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-07 06:40:54 +03:00
add builtin rules hook
Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
@@ -800,6 +800,75 @@ func TestEventManagerErrors(t *testing.T) {
|
||||
stopEventScheduler()
|
||||
}
|
||||
|
||||
func TestBuiltinRules(t *testing.T) {
|
||||
startEventScheduler()
|
||||
rule1 := util.GenerateUniqueID()
|
||||
loadBuiltinRulesFn = func() []dataprovider.EventRule {
|
||||
return []dataprovider.EventRule{
|
||||
{
|
||||
Name: rule1,
|
||||
Status: 1,
|
||||
CreatedAt: util.GetTimeAsMsSinceEpoch(time.Now()),
|
||||
UpdatedAt: util.GetTimeAsMsSinceEpoch(time.Now()),
|
||||
Trigger: dataprovider.EventTriggerSchedule,
|
||||
Conditions: dataprovider.EventConditions{
|
||||
Schedules: []dataprovider.Schedule{
|
||||
{
|
||||
Hours: "0",
|
||||
DayOfWeek: "*",
|
||||
DayOfMonth: "*",
|
||||
Month: "*",
|
||||
},
|
||||
},
|
||||
},
|
||||
Actions: []dataprovider.EventAction{
|
||||
{
|
||||
BaseEventAction: dataprovider.BaseEventAction{
|
||||
Name: "backup",
|
||||
Type: dataprovider.ActionTypeBackup,
|
||||
Options: dataprovider.BaseEventActionOptions{},
|
||||
},
|
||||
Order: 1,
|
||||
Options: dataprovider.EventActionOptions{},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
eventManager.loadRules()
|
||||
|
||||
eventManager.RLock()
|
||||
assert.Len(t, eventManager.FsEvents, 0)
|
||||
assert.Len(t, eventManager.ProviderEvents, 0)
|
||||
assert.Len(t, eventManager.Schedules, 1)
|
||||
eventManager.RUnlock()
|
||||
|
||||
cronJob := eventCronJob{
|
||||
ruleName: rule1,
|
||||
}
|
||||
r, err := cronJob.getEventRule()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, rule1, r.Name)
|
||||
assert.Len(t, r.Actions, 1)
|
||||
assert.Equal(t, dataprovider.EventTriggerSchedule, r.Trigger)
|
||||
|
||||
eventManager.RLock()
|
||||
eventManager.Schedules = nil
|
||||
eventManager.RUnlock()
|
||||
|
||||
loadBuiltinRulesFn = nil
|
||||
|
||||
eventManager.loadRules()
|
||||
|
||||
eventManager.RLock()
|
||||
assert.Len(t, eventManager.FsEvents, 0)
|
||||
assert.Len(t, eventManager.ProviderEvents, 0)
|
||||
assert.Len(t, eventManager.Schedules, 0)
|
||||
eventManager.RUnlock()
|
||||
stopEventScheduler()
|
||||
}
|
||||
|
||||
func TestEventRuleActions(t *testing.T) {
|
||||
actionName := "test rule action"
|
||||
action := dataprovider.BaseEventAction{
|
||||
|
||||
Reference in New Issue
Block a user