@@ -3,6 +3,7 @@ package chaoskube
3
3
import (
4
4
"context"
5
5
"math/rand"
6
+ "net/url"
6
7
"regexp"
7
8
"testing"
8
9
"time"
@@ -46,13 +47,14 @@ func (suite *Suite) TestNew() {
46
47
includedPodNames = regexp .MustCompile ("foo" )
47
48
excludedPodNames = regexp .MustCompile ("bar" )
48
49
excludedWeekdays = []time.Weekday {time .Friday }
49
- excludedTimesOfDay = []util.TimePeriod {util. TimePeriod {}}
50
+ excludedTimesOfDay = []util.TimePeriod {{}}
50
51
excludedDaysOfYear = []time.Time {time .Now ()}
51
52
minimumAge = time .Duration (42 )
52
53
dryRun = true
53
54
terminator = terminator .NewDeletePodTerminator (client , logger , 10 * time .Second )
54
55
)
55
56
57
+ webhook , _ := url .Parse ("" )
56
58
chaoskube := New (
57
59
client ,
58
60
labelSelector ,
@@ -69,6 +71,7 @@ func (suite *Suite) TestNew() {
69
71
logger ,
70
72
dryRun ,
71
73
terminator ,
74
+ * webhook ,
72
75
)
73
76
suite .Require ().NotNil (chaoskube )
74
77
@@ -105,6 +108,7 @@ func (suite *Suite) TestRunContextCanceled() {
105
108
time .Duration (0 ),
106
109
false ,
107
110
10 ,
111
+ url.URL {},
108
112
)
109
113
110
114
ctx , cancel := context .WithCancel (context .Background ())
@@ -122,19 +126,20 @@ func (suite *Suite) TestCandidates() {
122
126
labelSelector string
123
127
annotationSelector string
124
128
namespaceSelector string
129
+ webhook string
125
130
pods []map [string ]string
126
131
}{
127
- {"" , "" , "" , []map [string ]string {foo , bar }},
128
- {"app=foo" , "" , "" , []map [string ]string {foo }},
129
- {"app!=foo" , "" , "" , []map [string ]string {bar }},
130
- {"" , "chaos=foo" , "" , []map [string ]string {foo }},
131
- {"" , "chaos!=foo" , "" , []map [string ]string {bar }},
132
- {"" , "" , "default" , []map [string ]string {foo }},
133
- {"" , "" , "default,testing" , []map [string ]string {foo , bar }},
134
- {"" , "" , "!testing" , []map [string ]string {foo }},
135
- {"" , "" , "!default,!testing" , []map [string ]string {}},
136
- {"" , "" , "default,!testing" , []map [string ]string {foo }},
137
- {"" , "" , "default,!default" , []map [string ]string {}},
132
+ {"" , "" , "" , "" , []map [string ]string {foo , bar }},
133
+ {"app=foo" , "" , "" , "" , []map [string ]string {foo }},
134
+ {"app!=foo" , "" , "" , "" , []map [string ]string {bar }},
135
+ {"" , "chaos=foo" , "" , "" , []map [string ]string {foo }},
136
+ {"" , "chaos!=foo" , "" , "" , []map [string ]string {bar }},
137
+ {"" , "" , "default" , "" , []map [string ]string {foo }},
138
+ {"" , "" , "default,testing" , "" , []map [string ]string {foo , bar }},
139
+ {"" , "" , "!testing" , "" , []map [string ]string {foo }},
140
+ {"" , "" , "!default,!testing" , "" , []map [string ]string {}},
141
+ {"" , "" , "default,!testing" , "" , []map [string ]string {foo }},
142
+ {"" , "" , "default,!default" , "" , []map [string ]string {}},
138
143
} {
139
144
labelSelector , err := labels .Parse (tt .labelSelector )
140
145
suite .Require ().NoError (err )
@@ -159,6 +164,7 @@ func (suite *Suite) TestCandidates() {
159
164
time .Duration (0 ),
160
165
false ,
161
166
10 ,
167
+ url.URL {},
162
168
)
163
169
164
170
suite .assertCandidates (chaoskube , tt .pods )
@@ -203,6 +209,7 @@ func (suite *Suite) TestCandidatesNamespaceLabels() {
203
209
time .Duration (0 ),
204
210
false ,
205
211
10 ,
212
+ url.URL {},
206
213
)
207
214
208
215
suite .assertCandidates (chaoskube , tt .pods )
@@ -245,6 +252,7 @@ func (suite *Suite) TestCandidatesPodNameRegexp() {
245
252
time .Duration (0 ),
246
253
false ,
247
254
10 ,
255
+ url.URL {},
248
256
)
249
257
250
258
suite .assertCandidates (chaoskube , tt .pods )
@@ -284,6 +292,7 @@ func (suite *Suite) TestVictim() {
284
292
time .Duration (0 ),
285
293
false ,
286
294
10 ,
295
+ url.URL {},
287
296
)
288
297
289
298
suite .assertVictim (chaoskube , tt .victim )
@@ -306,6 +315,7 @@ func (suite *Suite) TestNoVictimReturnsError() {
306
315
time .Duration (0 ),
307
316
false ,
308
317
10 ,
318
+ url.URL {},
309
319
)
310
320
311
321
_ , err := chaoskube .Victim ()
@@ -339,6 +349,7 @@ func (suite *Suite) TestDeletePod() {
339
349
time .Duration (0 ),
340
350
tt .dryRun ,
341
351
10 ,
352
+ url.URL {},
342
353
)
343
354
344
355
victim := util .NewPod ("default" , "foo" , v1 .PodRunning )
@@ -367,6 +378,7 @@ func (suite *Suite) TestDeletePodNotFound() {
367
378
time .Duration (0 ),
368
379
false ,
369
380
10 ,
381
+ url.URL {},
370
382
)
371
383
372
384
victim := util .NewPod ("default" , "foo" , v1 .PodRunning )
@@ -597,6 +609,7 @@ func (suite *Suite) TestTerminateVictim() {
597
609
time .Duration (0 ),
598
610
false ,
599
611
10 ,
612
+ url.URL {},
600
613
)
601
614
chaoskube .Now = tt .now
602
615
@@ -626,6 +639,7 @@ func (suite *Suite) TestTerminateNoVictimLogsInfo() {
626
639
time .Duration (0 ),
627
640
false ,
628
641
10 ,
642
+ url.URL {},
629
643
)
630
644
631
645
err := chaoskube .TerminateVictim ()
@@ -650,7 +664,7 @@ func (suite *Suite) assertVictim(chaoskube *Chaoskube, expected map[string]strin
650
664
suite .AssertPod (victim , expected )
651
665
}
652
666
653
- func (suite * Suite ) setupWithPods (labelSelector labels.Selector , annotations labels.Selector , namespaces labels.Selector , namespaceLabels labels.Selector , includedPodNames * regexp.Regexp , excludedPodNames * regexp.Regexp , excludedWeekdays []time.Weekday , excludedTimesOfDay []util.TimePeriod , excludedDaysOfYear []time.Time , timezone * time.Location , minimumAge time.Duration , dryRun bool , gracePeriod time.Duration ) * Chaoskube {
667
+ func (suite * Suite ) setupWithPods (labelSelector labels.Selector , annotations labels.Selector , namespaces labels.Selector , namespaceLabels labels.Selector , includedPodNames * regexp.Regexp , excludedPodNames * regexp.Regexp , excludedWeekdays []time.Weekday , excludedTimesOfDay []util.TimePeriod , excludedDaysOfYear []time.Time , timezone * time.Location , minimumAge time.Duration , dryRun bool , gracePeriod time.Duration , webhook url. URL ) * Chaoskube {
654
668
chaoskube := suite .setup (
655
669
labelSelector ,
656
670
annotations ,
@@ -665,6 +679,7 @@ func (suite *Suite) setupWithPods(labelSelector labels.Selector, annotations lab
665
679
minimumAge ,
666
680
dryRun ,
667
681
gracePeriod ,
682
+ webhook ,
668
683
)
669
684
670
685
for _ , namespace := range []v1.Namespace {
@@ -689,7 +704,7 @@ func (suite *Suite) setupWithPods(labelSelector labels.Selector, annotations lab
689
704
return chaoskube
690
705
}
691
706
692
- func (suite * Suite ) setup (labelSelector labels.Selector , annotations labels.Selector , namespaces labels.Selector , namespaceLabels labels.Selector , includedPodNames * regexp.Regexp , excludedPodNames * regexp.Regexp , excludedWeekdays []time.Weekday , excludedTimesOfDay []util.TimePeriod , excludedDaysOfYear []time.Time , timezone * time.Location , minimumAge time.Duration , dryRun bool , gracePeriod time.Duration ) * Chaoskube {
707
+ func (suite * Suite ) setup (labelSelector labels.Selector , annotations labels.Selector , namespaces labels.Selector , namespaceLabels labels.Selector , includedPodNames * regexp.Regexp , excludedPodNames * regexp.Regexp , excludedWeekdays []time.Weekday , excludedTimesOfDay []util.TimePeriod , excludedDaysOfYear []time.Time , timezone * time.Location , minimumAge time.Duration , dryRun bool , gracePeriod time.Duration , webhook url. URL ) * Chaoskube {
693
708
logOutput .Reset ()
694
709
695
710
client := fake .NewSimpleClientset ()
@@ -711,6 +726,7 @@ func (suite *Suite) setup(labelSelector labels.Selector, annotations labels.Sele
711
726
logger ,
712
727
dryRun ,
713
728
terminator .NewDeletePodTerminator (client , nullLogger , gracePeriod ),
729
+ url.URL {},
714
730
)
715
731
}
716
732
@@ -814,6 +830,7 @@ func (suite *Suite) TestMinimumAge() {
814
830
tt .minimumAge ,
815
831
false ,
816
832
10 ,
833
+ url.URL {},
817
834
)
818
835
chaoskube .Now = tt .now
819
836
0 commit comments