-
Notifications
You must be signed in to change notification settings - Fork 24
/
injector_reject_test.go
90 lines (77 loc) · 1.63 KB
/
injector_reject_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
87
88
89
90
package fault
import (
"testing"
"github.com/stretchr/testify/assert"
)
// TestNewRejectInjector tests NewRejectInjector.
func TestNewRejectInjector(t *testing.T) {
t.Parallel()
tests := []struct {
name string
giveOptions []RejectInjectorOption
want *RejectInjector
wantErr error
}{
{
name: "no options",
giveOptions: []RejectInjectorOption{},
want: &RejectInjector{
reporter: NewNoopReporter(),
},
wantErr: nil,
},
{
name: "custom reporter",
giveOptions: []RejectInjectorOption{
WithReporter(newTestReporter()),
},
want: &RejectInjector{
reporter: newTestReporter(),
},
wantErr: nil,
},
{
name: "option error",
giveOptions: []RejectInjectorOption{
withError(),
},
want: nil,
wantErr: errErrorOption,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
ri, err := NewRejectInjector(tt.giveOptions...)
assert.Equal(t, tt.wantErr, err)
assert.Equal(t, tt.want, ri)
})
}
}
// TestRejectInjectorHandler tests RejectInjector.Handler.
func TestRejectInjectorHandler(t *testing.T) {
t.Parallel()
tests := []struct {
name string
giveOptions []RejectInjectorOption
}{
{
name: "valid",
giveOptions: []RejectInjectorOption{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
ri, err := NewRejectInjector(tt.giveOptions...)
assert.NoError(t, err)
f, err := NewFault(ri,
WithEnabled(true),
WithParticipation(1.0),
)
assert.NoError(t, err)
rr := testRequestExpectPanic(t, f)
assert.Nil(t, rr)
})
}
}