-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask_test.go
75 lines (73 loc) · 1.87 KB
/
task_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
// Copyright (c) 2018, dmc ([email protected]),
//
// Authors: dmc,
//
// Distribution:.
package gotask
import (
"reflect"
"testing"
"time"
)
func TestTask_refreshExecuteTime(t *testing.T) {
type fields struct {
executeTime time.Time
nextExecuteTime func(time.Time) time.Time
taskType int
}
tests := []struct {
name string
fields fields
wantTime time.Time
}{
{
name: "yaer",
fields: fields{
executeTime: time.Date(2020, 2, 28, 12, 12, 12, 0, time.Now().Location()),
nextExecuteTime: yearlyNextFunc,
taskType: yearly,
},
wantTime: time.Date(2021, 2, 28, 12, 12, 12, 0, time.Now().Location()),
},
{
name: "yaer29",
fields: fields{
executeTime: time.Date(2020, 2, 29, 12, 12, 12, 0, time.Now().Location()),
nextExecuteTime: yearlyNextFunc,
taskType: yearly,
},
wantTime: time.Date(2024, 2, 29, 12, 12, 12, 0, time.Now().Location()),
},
{
name: "month",
fields: fields{
executeTime: time.Date(2020, 2, 29, 12, 12, 12, 0, time.Now().Location()),
nextExecuteTime: monthlyNextFunc,
taskType: monthly,
},
wantTime: time.Date(2020, 3, 29, 12, 12, 12, 0, time.Now().Location()),
},
{
name: "month31",
fields: fields{
executeTime: time.Date(2020, 3, 31, 12, 12, 12, 0, time.Now().Location()),
nextExecuteTime: monthlyNextFunc,
taskType: monthly,
},
wantTime: time.Date(2020, 5, 31, 12, 12, 12, 0, time.Now().Location()),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
task := &Task{
executeTime: tt.fields.executeTime,
nextExecuteTime: tt.fields.nextExecuteTime,
taskType: tt.fields.taskType,
}
task.refreshExecuteTime()
if !reflect.DeepEqual(task.ExecuteTime(), tt.wantTime) {
t.Errorf("yearlyParse.Parse() = %v, want %v", task.ExecuteTime(), tt.wantTime)
}
})
}
}