-
Notifications
You must be signed in to change notification settings - Fork 4
/
interval_flag_test.go
95 lines (88 loc) · 1.7 KB
/
interval_flag_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
package goworker
import (
"testing"
"time"
)
var intervalFlagSetTests = []struct {
v string
expected intervalFlag
}{
{
"0",
intervalFlag(0),
},
{
"1",
intervalFlag(1 * time.Second),
},
{
"1.5",
intervalFlag(1500 * time.Millisecond),
},
}
func TestIntervalFlagSet(t *testing.T) {
for _, tt := range intervalFlagSetTests {
actual := new(intervalFlag)
if err := actual.Set(tt.v); err != nil {
t.Errorf("IntervalFlag(%#v): set to %s error %s", actual, tt.v, err)
} else {
if *actual != tt.expected {
t.Errorf("IntervalFlag: set to %s expected %v, actual %v", tt.v, tt.expected, actual)
}
}
}
}
var intervalFlagSetFloatTests = []struct {
v float64
expected intervalFlag
}{
{
0.0,
intervalFlag(0),
},
{
1.0,
intervalFlag(1 * time.Second),
},
{
1.5,
intervalFlag(1500 * time.Millisecond),
},
}
func TestIntervalFlagSetFloat(t *testing.T) {
for _, tt := range intervalFlagSetFloatTests {
actual := new(intervalFlag)
if err := actual.SetFloat(tt.v); err != nil {
t.Errorf("IntervalFlag(%#v): set to %f error %s", actual, tt.v, err)
} else {
if *actual != tt.expected {
t.Errorf("IntervalFlag: set to %f expected %v, actual %v", tt.v, tt.expected, actual)
}
}
}
}
var intervalFlagStringTests = []struct {
i intervalFlag
expected string
}{
{
intervalFlag(0),
"0",
},
{
intervalFlag(1 * time.Second),
"1000000000",
},
{
intervalFlag(1500 * time.Millisecond),
"1500000000",
},
}
func TestIntervalFlagString(t *testing.T) {
for _, tt := range intervalFlagStringTests {
actual := tt.i.String()
if actual != tt.expected {
t.Errorf("IntervalFlag(%#v): expected %s, actual %s", tt.i, tt.expected, actual)
}
}
}