-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathoptions_test.go
More file actions
104 lines (89 loc) · 2.33 KB
/
Copy pathoptions_test.go
File metadata and controls
104 lines (89 loc) · 2.33 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright (c) 2026 Onur Cinar.
// The source code is provided under MIT License.
// https://github.com/cinar/resile
package resile
import (
"errors"
"testing"
"time"
"github.com/cinar/resile/circuit"
)
func TestOptions(t *testing.T) {
t.Parallel()
c := DefaultConfig()
t.Run("WithName", func(t *testing.T) {
WithName("test-op")(c)
if c.Name != "test-op" {
t.Errorf("expected test-op, got %s", c.Name)
}
})
t.Run("WithMaxAttempts", func(t *testing.T) {
WithMaxAttempts(10)(c)
if c.MaxAttempts != 10 {
t.Errorf("expected 10, got %d", c.MaxAttempts)
}
})
t.Run("WithBaseDelay", func(t *testing.T) {
WithBaseDelay(500 * time.Millisecond)(c)
if c.BaseDelay != 500*time.Millisecond {
t.Errorf("expected 500ms, got %v", c.BaseDelay)
}
if fj, ok := c.Backoff.(*fullJitter); ok {
if fj.base != 500*time.Millisecond {
t.Errorf("expected fj.base 500ms, got %v", fj.base)
}
}
})
t.Run("WithMaxDelay", func(t *testing.T) {
WithMaxDelay(60 * time.Second)(c)
if c.MaxDelay != 60*time.Second {
t.Errorf("expected 60s, got %v", c.MaxDelay)
}
if fj, ok := c.Backoff.(*fullJitter); ok {
if fj.cap != 60*time.Second {
t.Errorf("expected fj.cap 60s, got %v", fj.cap)
}
}
})
t.Run("WithBackoff", func(t *testing.T) {
custom := NewFullJitter(1, 1)
WithBackoff(custom)(c)
if c.Backoff != custom {
t.Error("expected custom backoff")
}
})
t.Run("WithRetryIf", func(t *testing.T) {
err := errors.New("custom")
WithRetryIf(err)(c)
if c.Policy.retryIf != err {
t.Error("expected custom retryIf")
}
})
t.Run("WithRetryIfFunc", func(t *testing.T) {
f := func(err error) bool { return true }
WithRetryIfFunc(f)(c)
if c.Policy.retryIfFunc == nil {
t.Error("expected custom retryIfFunc")
}
})
t.Run("WithInstrumenter", func(t *testing.T) {
instr := &mockInstrumenter{}
WithInstrumenter(instr)(c)
if c.Instrumenter != instr {
t.Error("expected custom instrumenter")
}
})
t.Run("WithCircuitBreaker", func(t *testing.T) {
cb := circuit.New(circuit.Config{})
WithCircuitBreaker(cb)(c)
if c.CircuitBreaker != cb {
t.Error("expected custom circuit breaker")
}
})
t.Run("WithHedgingDelay", func(t *testing.T) {
WithHedgingDelay(50 * time.Millisecond)(c)
if c.HedgingDelay != 50*time.Millisecond {
t.Errorf("expected 50ms, got %v", c.HedgingDelay)
}
})
}