-
Notifications
You must be signed in to change notification settings - Fork 32
/
export_test.go
55 lines (44 loc) · 1.21 KB
/
export_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
package retry
import (
. "github.com/stretchr/testify/assert"
"testing"
"time"
)
// RetryWithBackoffConfig holds the configuration for WithBackoff.
type RetryWithBackoffConfig interface {
GetFactor() float64
GetJitter() bool
GetMin() time.Duration
GetMax() time.Duration
GetMaxAttempts() int
}
func (r *retryWithBackoffConfig) GetFactor() float64 {
return r.factor
}
func (r *retryWithBackoffConfig) GetJitter() bool {
return r.jitter
}
func (r *retryWithBackoffConfig) GetMin() time.Duration {
return r.min
}
func (r *retryWithBackoffConfig) GetMax() time.Duration {
return r.max
}
func (r *retryWithBackoffConfig) GetMaxAttempts() int {
return r.maxAttempts
}
// DefaultConfig returns a default RetryWithBackoffConfig.
func DefaultConfig() RetryWithBackoffConfig {
cfg := defaultConfig()
return &cfg
}
// Configurator returns a RetryWithBackoffConfig with the given configurators applied.
func Configurator(tb testing.TB, configurator RetryWithBackoffConfig, apply ...WithBackoffConfigurator) RetryWithBackoffConfig {
tb.Helper()
for _, cfg := range apply {
res, ok := configurator.(*retryWithBackoffConfig)
True(tb, ok, "configurator is not a *retryWithBackoffConfig")
cfg(res)
}
return configurator
}