-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
loop_test.go
86 lines (83 loc) · 1.68 KB
/
loop_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
package runn
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func TestNewLoop(t *testing.T) {
tests := []struct {
v any
count string
interval string
minInterval string
maxInterval string
jitter float64
multiplier float64
until string
}{
{
map[string]any{},
"3",
"0",
"",
"",
0.0,
*new(float64),
"",
},
{
map[string]any{"count": "1", "interval": "1.0", "until": "5", "minInterval": "0.1", "maxInterval": "0.2", "jitter": 0.3, "multiplier": 0.4},
"1",
"1.0",
"0.1",
"0.2",
0.3,
0.4,
"5",
},
{
map[string]any{"count": "2", "until": "3"},
"2",
"0",
"0ms",
"0ms",
float64(0.0),
float64(1.5),
"3",
},
}
for _, tt := range tests {
got, err := newLoop(tt.v)
if err != nil {
t.Fatal(err)
}
if diff := cmp.Diff(got.Count, tt.count, nil); diff != "" {
t.Errorf("count: %s", diff)
}
if got.Interval != "" {
if diff := cmp.Diff(got.Interval, tt.interval, nil); diff != "" {
t.Errorf("interval: %s", diff)
}
}
if got.MinInterval != "" {
if diff := cmp.Diff(got.MinInterval, tt.minInterval, nil); diff != "" {
t.Errorf("minInterval: %s", diff)
}
}
if got.MaxInterval != "" {
if diff := cmp.Diff(got.MaxInterval, tt.maxInterval, nil); diff != "" {
t.Errorf("maxInterval: %s", diff)
}
}
if diff := cmp.Diff(*got.Jitter, tt.jitter, nil); diff != "" {
t.Errorf("jitter: %s", diff)
}
if got.Multiplier != nil {
if diff := cmp.Diff(*got.Multiplier, tt.multiplier, nil); diff != "" {
t.Errorf("multiplier: %s", diff)
}
}
if diff := cmp.Diff(got.Until, tt.until, nil); diff != "" {
t.Errorf("until: %s", diff)
}
}
}