forked from gljubojevic/gocron
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathgocron_test.go
92 lines (86 loc) · 1.6 KB
/
gocron_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
90
91
92
package gocron
import (
"fmt"
"testing"
"time"
)
var err = 1
func task() {
fmt.Println("I am a running job.")
}
func taskWithParams(a int, b string) {
fmt.Println(a, b)
}
func TestSecond(*testing.T) {
defaultScheduler.Every(1).Second().Do(task)
defaultScheduler.Every(1).Second().Do(taskWithParams, 1, "hello")
defaultScheduler.Start()
time.Sleep(10 * time.Second)
}
func Test_formatTime(t *testing.T) {
tests := []struct {
name string
args string
wantHour int
wantMin int
wantErr bool
}{
{
name: "normal",
args: "16:18",
wantHour: 16,
wantMin: 18,
wantErr: false,
},
{
name: "normal",
args: "6:18",
wantHour: 6,
wantMin: 18,
wantErr: false,
},
{
name: "notnumber",
args: "e:18",
wantHour: 0,
wantMin: 0,
wantErr: true,
},
{
name: "outofrange",
args: "25:18",
wantHour: 25,
wantMin: 18,
wantErr: true,
},
{
name: "wrongformat",
args: "19:18:17",
wantHour: 0,
wantMin: 0,
wantErr: true,
},
{
name: "wrongminute",
args: "19:1e",
wantHour: 19,
wantMin: 0,
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotHour, gotMin, err := formatTime(tt.args)
if (err != nil) != tt.wantErr {
t.Errorf("formatTime() error = %v, wantErr %v", err, tt.wantErr)
return
}
if gotHour != tt.wantHour {
t.Errorf("formatTime() gotHour = %v, want %v", gotHour, tt.wantHour)
}
if gotMin != tt.wantMin {
t.Errorf("formatTime() gotMin = %v, want %v", gotMin, tt.wantMin)
}
})
}
}