-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions_test.go
More file actions
85 lines (63 loc) · 1.75 KB
/
options_test.go
File metadata and controls
85 lines (63 loc) · 1.75 KB
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
package waitfor
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestNewOptions_Defaults(t *testing.T) {
opts := newOptions([]Option{})
assert.Equal(t, time.Duration(5)*time.Second, opts.interval)
assert.Equal(t, time.Duration(60)*time.Second, opts.maxInterval)
assert.Equal(t, uint64(5), opts.attempts)
}
func TestNewOptions_WithSetters(t *testing.T) {
setters := []Option{
WithInterval(10),
WithMaxInterval(120),
WithAttempts(15),
}
opts := newOptions(setters)
assert.Equal(t, time.Duration(10)*time.Second, opts.interval)
assert.Equal(t, time.Duration(120)*time.Second, opts.maxInterval)
assert.Equal(t, uint64(15), opts.attempts)
}
func TestWithInterval(t *testing.T) {
option := WithInterval(30)
opts := &options{}
option(opts)
assert.Equal(t, time.Duration(30)*time.Second, opts.interval)
}
func TestWithMaxInterval(t *testing.T) {
option := WithMaxInterval(90)
opts := &options{}
option(opts)
assert.Equal(t, time.Duration(90)*time.Second, opts.maxInterval)
}
func TestWithAttempts(t *testing.T) {
option := WithAttempts(20)
opts := &options{}
option(opts)
assert.Equal(t, uint64(20), opts.attempts)
}
func TestCombinedOptions(t *testing.T) {
opts := newOptions([]Option{
WithInterval(2),
WithMaxInterval(30),
WithAttempts(8),
})
assert.Equal(t, time.Duration(2)*time.Second, opts.interval)
assert.Equal(t, time.Duration(30)*time.Second, opts.maxInterval)
assert.Equal(t, uint64(8), opts.attempts)
}
func TestWithMultiplier(t *testing.T) {
opts := newOptions([]Option{
WithMultiplier(2.5),
})
assert.Equal(t, 2.5, opts.multiplier)
}
func TestWithRandomizationFactor(t *testing.T) {
opts := newOptions([]Option{
WithRandomizationFactor(0.3),
})
assert.Equal(t, 0.3, opts.randomizationFactor)
}