-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathoption_test.go
121 lines (115 loc) · 2.23 KB
/
option_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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package cronv
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestNewCronvOption(t *testing.T) {
baseTime := time.Date(1985, 12, 8, 11, 30, 0, 0, time.UTC)
type args struct {
t time.Time
}
tests := []struct {
name string
args args
want *Option
}{
{
name: "set default properties",
args: args{
t: baseTime,
},
want: &Option{
OutputFilePath: optDefaultOutputPath,
Duration: optDefaultDuration,
FromDate: "1985/12/08",
FromTime: "11:30",
Title: optDefaultTitle,
Width: optDefaultWidth,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ret := NewCronvOption(tt.args.t)
assert.Equal(t, tt.want, ret)
})
}
}
func TestOption_toDurationMinutes(t *testing.T) {
tests := []struct {
name string
duration string
want float64
wantErr bool
}{
{
name: "valid (1m)",
duration: "1m",
want: float64(1),
},
{
name: "valid (2h)",
duration: "2h",
want: float64(1 * 60 * 2),
},
{
name: "valid (3d)",
duration: "3d",
want: float64(1 * 60 * 24 * 3),
},
{
name: "invalid (not a duration string)",
duration: "INVALID",
wantErr: true,
},
{
name: "invalid (unknown suffix)",
duration: "1F",
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := NewCronvOption(time.Now())
c.Duration = tt.duration
ret, err := c.toDurationMinutes()
if tt.wantErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
assert.Equal(t, tt.want, ret)
})
}
}
func TestOption_toFromTime(t *testing.T) {
tests := []struct {
name string
fromDate string
fromTime string
want time.Time
wantErr bool
}{
{
name: "successfully",
fromDate: "2016/11/08",
fromTime: "01:30",
want: time.Date(2016, 11, 8, 1, 30, 0, 0, time.UTC),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := NewCronvOption(time.Now())
c.FromDate = tt.fromDate
c.FromTime = tt.fromTime
ret, err := c.toFromTime()
if tt.wantErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
assert.Equal(t, tt.want, ret)
})
}
}