3
0

Extra tests

This commit is contained in:
Tomaž Jerman 2019-09-19 13:13:11 +02:00
parent 1971d922be
commit 7a992d5744

View File

@ -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")