-
Notifications
You must be signed in to change notification settings - Fork 0
/
schedule_test.go
89 lines (74 loc) · 1.2 KB
/
schedule_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package cronjob
import (
"testing"
"time"
)
func TestSchedule(t *testing.T) {
nowTesting := time.Date(
2022, // year
10, // month
7, // day
10, // hour
5, // min
0, // sec
0,
time.Local,
)
cases := []struct {
schedule Schedule
expectedDur time.Duration
}{
// At.
{
schedule: At(time.Date(
2022,
10,
7,
10,
5,
0,
0,
time.Local,
)),
expectedDur: nowTesting.Sub(time.Date(
2022,
10,
7,
10,
5,
0,
0,
time.Local,
)),
},
// In.
{
schedule: In(nowTesting, 5*time.Minute),
expectedDur: 5 * time.Minute,
},
// Every.
{
schedule: Every(5 * time.Minute),
expectedDur: 5 * time.Minute,
},
// EveryFixed.
{
schedule: EveryFixed(10 * time.Minute),
expectedDur: 5 * time.Minute,
},
}
for _, c := range cases {
var got time.Duration
switch c.schedule.(type) {
case CyclicSchedule:
sched := c.schedule.(CyclicSchedule)
sched.MoveNextAvtivation(nowTesting)
got = sched.Calculate(nowTesting)
case Schedule:
got = c.schedule.Calculate(nowTesting)
}
if want := c.expectedDur; got != want {
t.Fatalf("want: %v got: %v\n", want, got)
}
}
}