-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
batch_test.go
40 lines (35 loc) · 980 Bytes
/
batch_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
package gronx
import (
"fmt"
"testing"
"time"
)
func TestBatch(t *testing.T) {
gron := New()
t.Run("batch no error", func(t *testing.T) {
ref := time.Now()
exprs := []string{"@everysecond", "* * * * * *", "* * * * * *"}
exprs = append(exprs, fmt.Sprintf("* %d * * * * %d", ref.Minute(), ref.Year()))
exprs = append(exprs, fmt.Sprintf("* * * * * * %d-%d", ref.Year()-1, ref.Year()+1))
for _, expr := range gron.BatchDue(exprs) {
if expr.Err != nil {
t.Errorf("%s error: %#v", expr.Expr, expr.Err)
}
if !expr.Due {
t.Errorf("%s must be due", expr.Expr)
}
}
})
t.Run("batch error", func(t *testing.T) {
exprs := []string{"* * * *", "A B C D E F"}
ref, _ := time.Parse(FullDateFormat, "2022-02-02 02:02:02")
for _, expr := range gron.BatchDue(exprs, ref) {
if expr.Err == nil {
t.Errorf("%s expected error", expr.Expr)
}
if expr.Due {
t.Errorf("%s must not be due when there is error", expr.Expr)
}
}
})
}