-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththresholds_test.go
More file actions
87 lines (80 loc) · 2.05 KB
/
Copy paththresholds_test.go
File metadata and controls
87 lines (80 loc) · 2.05 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
package chaoskit
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSuccessThresholds_Validate(t *testing.T) {
tests := []struct {
name string
thresholds *SuccessThresholds
wantErr bool
}{
{
name: "valid default",
thresholds: DefaultThresholds(),
wantErr: false,
},
{
name: "invalid success rate too high",
thresholds: &SuccessThresholds{
MinSuccessRate: 1.5,
},
wantErr: true,
},
{
name: "invalid success rate too low",
thresholds: &SuccessThresholds{
MinSuccessRate: -0.1,
},
wantErr: true,
},
{
name: "invalid max failed iterations",
thresholds: &SuccessThresholds{
MinSuccessRate: 0.95,
MaxFailedIterations: -1,
},
wantErr: true,
},
{
name: "valid strict thresholds",
thresholds: StrictThresholds(),
wantErr: false,
},
{
name: "valid relaxed thresholds",
thresholds: RelaxedThresholds(),
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.thresholds.Validate()
if tt.wantErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
})
}
}
func TestDefaultThresholds(t *testing.T) {
thresholds := DefaultThresholds()
assert.Equal(t, 0.95, thresholds.MinSuccessRate)
assert.Contains(t, thresholds.CriticalValidators, "goroutine-limit")
assert.Contains(t, thresholds.CriticalValidators, "recursion-depth")
assert.Contains(t, thresholds.CriticalValidators, "slow-iteration")
assert.Contains(t, thresholds.CriticalValidators, "memory-limit")
}
func TestStrictThresholds(t *testing.T) {
thresholds := StrictThresholds()
assert.Equal(t, 1.0, thresholds.MinSuccessRate)
assert.True(t, thresholds.RequireAllValidatorsPassing)
assert.Contains(t, thresholds.CriticalValidators, "panic-recovery")
}
func TestRelaxedThresholds(t *testing.T) {
thresholds := RelaxedThresholds()
assert.Equal(t, 0.80, thresholds.MinSuccessRate)
assert.Equal(t, 200, thresholds.MaxFailedIterations)
assert.Contains(t, thresholds.CriticalValidators, "goroutine-limit")
}