-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschedule_test.go
More file actions
66 lines (50 loc) · 1.43 KB
/
schedule_test.go
File metadata and controls
66 lines (50 loc) · 1.43 KB
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
package cron
import (
"testing"
"time"
)
const nextNCount = 5
func TestNextNExpectedCount(t *testing.T) {
t.Parallel()
parser := NewSpecParser(Second | Minute | Hour | Dom | Month | Dow | Descriptor)
sched, err := parser.Parse("0 * * * * *")
if err != nil {
t.Fatal(err)
}
times := NextN(sched, baseTime, nextNCount)
if len(times) != nextNCount {
t.Fatalf("expected 5 times, got %d", len(times))
}
for idx := 1; idx < len(times); idx++ {
diff := times[idx].Sub(times[idx-1])
if diff != time.Minute {
t.Errorf("expected 1m between fires %d and %d, got %v", idx-1, idx, diff)
}
}
}
func TestNextNUnsatisfiable(t *testing.T) {
t.Parallel()
parser := NewSpecParser(Second | Minute | Hour | Dom | Month | Dow | Descriptor)
sched, err := parser.Parse("0 0 0 30 Feb *")
if err != nil {
t.Fatal(err)
}
times := NextN(sched, baseTime, nextNCount)
if len(times) != 0 {
t.Errorf("expected 0 times for unsatisfiable schedule, got %d", len(times))
}
}
func TestNextNZeroAndNegativeCount(t *testing.T) {
t.Parallel()
parser := NewSpecParser(Second | Minute | Hour | Dom | Month | Dow | Descriptor)
sched, err := parser.Parse("0 * * * * *")
if err != nil {
t.Fatal(err)
}
if times := NextN(sched, baseTime, 0); len(times) != 0 {
t.Errorf("expected 0 times for count=0, got %d", len(times))
}
if times := NextN(sched, baseTime, -1); len(times) != 0 {
t.Errorf("expected 0 times for count=-1, got %d", len(times))
}
}