From 7a992d57443f0cfba0b9b8e5d8ef65e06de396da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20Jerman?= Date: Thu, 19 Sep 2019 13:13:11 +0200 Subject: [PATCH] Extra tests --- pkg/automation/scheduled_test.go | 46 ++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/pkg/automation/scheduled_test.go b/pkg/automation/scheduled_test.go index a30ef0856..0b0e93a24 100644 --- a/pkg/automation/scheduled_test.go +++ b/pkg/automation/scheduled_test.go @@ -4,6 +4,8 @@ import ( "reflect" "testing" "time" + + "github.com/DestinyWang/cronexpr" ) func ss2tt(ss ...string) []time.Time { @@ -14,6 +16,14 @@ func ss2tt(ss ...string) []time.Time { return tt } +func ss2ii(ss ...string) []cronexpr.Expression { + ii := make([]cronexpr.Expression, len(ss)) + for i, s := range ss { + ii[i] = *cronexpr.MustParse(s) + } + return ii +} + func TestScheduleBuilder(t *testing.T) { tests := []struct { name string @@ -37,6 +47,23 @@ func TestScheduleBuilder(t *testing.T) { schedule{scriptID: 2, timestamps: ss2tt("2000-01-01T00:02:00+02:00", "2000-01-01T00:03:00+02:00")}, }, }, + {name: "intervals", + ss: ScriptSet{ + &Script{ID: 1, Enabled: true, triggers: TriggerSet{ + &Trigger{Enabled: true, Event: EVENT_TYPE_INTERVAL, Condition: "0 * * * * * *"}, + &Trigger{Enabled: true, Event: EVENT_TYPE_INTERVAL, Condition: "invalid"}, + }}, + &Script{ID: 2, Enabled: true, triggers: TriggerSet{ + &Trigger{Enabled: true, Event: EVENT_TYPE_INTERVAL, Condition: "0 0 * * * * *"}, + &Trigger{Enabled: true, Event: EVENT_TYPE_INTERVAL, Condition: "invalid"}, + }}, + }, + + sch: scheduledSet{ + schedule{scriptID: 1, intervals: ss2ii("0 * * * * * *")}, + schedule{scriptID: 2, intervals: ss2ii("0 0 * * * * *")}, + }, + }, } n, _ := time.Parse(time.RFC3339, "2000-01-01T00:00:00+02:00") @@ -58,20 +85,35 @@ func TestSchedulePicker(t *testing.T) { sch scheduledSet ids []uint64 }{ - {name: "one", + {name: "schedule one", ids: []uint64{1}, sch: scheduledSet{ schedule{scriptID: 1, timestamps: ss2tt("2000-01-01T00:01:00+02:00", "2000-01-01T00:03:00+02:00")}, schedule{scriptID: 2, timestamps: ss2tt("2000-01-01T00:04:00+02:00", "2000-01-01T00:05:00+02:00")}, }, }, - {name: "two", + {name: "schedule two", ids: []uint64{1, 2}, sch: scheduledSet{ schedule{scriptID: 1, timestamps: ss2tt("2000-01-01T00:01:00+02:00")}, schedule{scriptID: 2, timestamps: ss2tt("2000-01-01T00:01:00+02:00", "2000-01-01T00:05:00+02:00")}, }, }, + + {name: "interval one", + ids: []uint64{1}, + sch: scheduledSet{ + schedule{scriptID: 1, intervals: ss2ii("0 * * * * * *")}, + schedule{scriptID: 2, intervals: ss2ii("0 7 * * * * *")}, + }, + }, + {name: "interval two", + ids: []uint64{1, 2}, + sch: scheduledSet{ + schedule{scriptID: 1, intervals: ss2ii("0 * * * * * *")}, + schedule{scriptID: 2, intervals: ss2ii("0 * * * * * *")}, + }, + }, } n, _ := time.Parse(time.RFC3339, "2000-01-01T00:01:50+02:00")