-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfield_config_test.go
81 lines (76 loc) · 1.6 KB
/
field_config_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
package cronfab
import (
"fmt"
"testing"
"time"
)
func TestCeil(t *testing.T) {
fc1 := &FieldConfig{
unit: MinuteUnit{},
name: "minute",
min: 0,
max: 59,
getIndex: func(t time.Time) int {
return t.Minute()
},
}
tcases := []struct {
in string
expect string
roll bool
constraint [][3]int
}{
{
in: "2020-10-15T17:00:00Z",
constraint: [][3]int{{3, 32, 5}},
expect: "2020-10-15T17:03:00Z",
roll: false,
},
{
in: "2020-10-15T17:07:00Z",
constraint: [][3]int{{7, 32, 5}},
expect: "2020-10-15T17:07:00Z",
roll: false,
},
{
in: "2020-10-15T17:07:01Z",
constraint: [][3]int{{7, 32, 1}},
expect: "2020-10-15T17:07:01Z",
roll: false,
},
{
in: "2020-10-15T17:32:00Z",
constraint: [][3]int{{0, 30, 5}},
expect: "2020-10-15T17:32:00Z",
roll: true,
},
{
in: "2020-10-15T17:52:01Z",
constraint: [][3]int{{5, 30, 5}},
expect: "2020-10-15T17:52:01Z",
roll: true,
},
}
for i, tc := range tcases {
ok := t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
t0, err := time.Parse(time.RFC3339, tc.in)
if err != nil {
t.Fatalf("err: %v", err)
}
expect, err := time.Parse(time.RFC3339, tc.expect)
if err != nil {
t.Fatalf("err: %v", err)
}
t1, roll := fc1.Ceil(tc.constraint, t0)
if !t1.Equal(expect) {
t.Fatalf("missmatch: %q %q", t1.Format(time.RFC3339), expect.Format(time.RFC3339))
}
if tc.roll != roll {
t.Fatalf("missmatch: %t %t", roll, tc.roll)
}
})
if !ok {
break
}
}
}