@@ -44,18 +44,26 @@ import (
44
44
// This tests the scenario where SummarizeAndPatch is used at the very end of a
45
45
// reconciliation.
46
46
func TestSummarizeAndPatch (t * testing.T ) {
47
+ testBipolarCondition1 := "FooChecked1"
48
+ testBipolarCondition2 := "FooChecked2"
47
49
var testReadyConditions = Conditions {
48
50
Target : meta .ReadyCondition ,
49
51
Owned : []string {
50
52
sourcev1 .FetchFailedCondition ,
51
53
sourcev1 .ArtifactOutdatedCondition ,
54
+ sourcev1 .SourceVerifiedCondition ,
55
+ testBipolarCondition1 ,
56
+ testBipolarCondition2 ,
52
57
meta .ReadyCondition ,
53
58
meta .ReconcilingCondition ,
54
59
meta .StalledCondition ,
55
60
},
56
61
Summarize : []string {
57
62
sourcev1 .FetchFailedCondition ,
58
63
sourcev1 .ArtifactOutdatedCondition ,
64
+ sourcev1 .SourceVerifiedCondition ,
65
+ testBipolarCondition1 ,
66
+ testBipolarCondition2 ,
59
67
meta .StalledCondition ,
60
68
meta .ReconcilingCondition ,
61
69
},
@@ -66,6 +74,7 @@ func TestSummarizeAndPatch(t *testing.T) {
66
74
meta .ReconcilingCondition ,
67
75
},
68
76
}
77
+ var testBipolarConditions = []string {sourcev1 .SourceVerifiedCondition , testBipolarCondition1 , testBipolarCondition2 }
69
78
var testFooConditions = Conditions {
70
79
Target : "Foo" ,
71
80
Owned : []string {
@@ -83,15 +92,16 @@ func TestSummarizeAndPatch(t *testing.T) {
83
92
}
84
93
85
94
tests := []struct {
86
- name string
87
- generation int64
88
- beforeFunc func (obj conditions.Setter )
89
- result reconcile.Result
90
- reconcileErr error
91
- conditions []Conditions
92
- wantErr bool
93
- afterFunc func (t * WithT , obj client.Object )
94
- assertConditions []metav1.Condition
95
+ name string
96
+ generation int64
97
+ beforeFunc func (obj conditions.Setter )
98
+ result reconcile.Result
99
+ reconcileErr error
100
+ conditions []Conditions
101
+ bipolarConditions []string
102
+ wantErr bool
103
+ afterFunc func (t * WithT , obj client.Object )
104
+ assertConditions []metav1.Condition
95
105
}{
96
106
// Success/Fail indicates if a reconciliation succeeded or failed.
97
107
// The object generation is expected to match the observed generation in
@@ -250,6 +260,64 @@ func TestSummarizeAndPatch(t *testing.T) {
250
260
},
251
261
wantErr : true ,
252
262
},
263
+ {
264
+ name : "Fail, reconciling with bipolar condition False, Ready gets bipolar failure value" ,
265
+ generation : 2 ,
266
+ beforeFunc : func (obj conditions.Setter ) {
267
+ conditions .MarkReconciling (obj , "NewRevision" , "new index revision" )
268
+ conditions .MarkFalse (obj , sourcev1 .SourceVerifiedCondition , "VerifyFailed" , "verify failed" )
269
+ },
270
+ result : reconcile .ResultEmpty ,
271
+ reconcileErr : errors .New ("failed to verify source" ),
272
+ conditions : []Conditions {testReadyConditions },
273
+ bipolarConditions : testBipolarConditions ,
274
+ wantErr : true ,
275
+ assertConditions : []metav1.Condition {
276
+ * conditions .FalseCondition (meta .ReadyCondition , "VerifyFailed" , "verify failed" ),
277
+ * conditions .FalseCondition (sourcev1 .SourceVerifiedCondition , "VerifyFailed" , "verify failed" ),
278
+ * conditions .TrueCondition (meta .ReconcilingCondition , "NewRevision" , "new index revision" ),
279
+ },
280
+ },
281
+ {
282
+ name : "Fail, bipolar condition True, negative polarity True, Ready gets negative polarity value" ,
283
+ generation : 2 ,
284
+ beforeFunc : func (obj conditions.Setter ) {
285
+ conditions .MarkReconciling (obj , "NewGeneration" , "new obj gen" )
286
+ conditions .MarkTrue (obj , sourcev1 .ArtifactOutdatedCondition , "NewRevision" , "new digest" )
287
+ conditions .MarkTrue (obj , sourcev1 .SourceVerifiedCondition , "Success" , "verified" )
288
+ },
289
+ result : reconcile .ResultEmpty ,
290
+ reconcileErr : errors .New ("failed to create dir" ),
291
+ conditions : []Conditions {testReadyConditions },
292
+ bipolarConditions : testBipolarConditions ,
293
+ wantErr : true ,
294
+ assertConditions : []metav1.Condition {
295
+ * conditions .FalseCondition (meta .ReadyCondition , "NewRevision" , "new digest" ),
296
+ * conditions .TrueCondition (sourcev1 .ArtifactOutdatedCondition , "NewRevision" , "new digest" ),
297
+ * conditions .TrueCondition (meta .ReconcilingCondition , "NewGeneration" , "new obj gen" ),
298
+ * conditions .TrueCondition (sourcev1 .SourceVerifiedCondition , "Success" , "verified" ),
299
+ },
300
+ },
301
+ {
302
+ name : "Fail, multiple bipolar conditions False, Ready gets the bipolar with high priority" ,
303
+ generation : 2 ,
304
+ beforeFunc : func (obj conditions.Setter ) {
305
+ conditions .MarkTrue (obj , sourcev1 .SourceVerifiedCondition , "Success" , "verified" )
306
+ conditions .MarkFalse (obj , testBipolarCondition1 , "AAA" , "aaa" )
307
+ conditions .MarkFalse (obj , testBipolarCondition2 , "BBB" , "bbb" )
308
+ },
309
+ result : reconcile .ResultEmpty ,
310
+ reconcileErr : errors .New ("some failure" ),
311
+ conditions : []Conditions {testReadyConditions },
312
+ bipolarConditions : testBipolarConditions ,
313
+ wantErr : true ,
314
+ assertConditions : []metav1.Condition {
315
+ * conditions .FalseCondition (meta .ReadyCondition , "AAA" , "aaa" ),
316
+ * conditions .FalseCondition (testBipolarCondition1 , "AAA" , "aaa" ),
317
+ * conditions .FalseCondition (testBipolarCondition2 , "BBB" , "bbb" ),
318
+ * conditions .TrueCondition (sourcev1 .SourceVerifiedCondition , "Success" , "verified" ),
319
+ },
320
+ },
253
321
}
254
322
255
323
for _ , tt := range tests {
@@ -289,6 +357,9 @@ func TestSummarizeAndPatch(t *testing.T) {
289
357
WithProcessors (RecordContextualError , RecordReconcileReq ),
290
358
WithResultBuilder (reconcile.AlwaysRequeueResultBuilder {RequeueAfter : obj .Spec .Interval .Duration }),
291
359
}
360
+ if tt .bipolarConditions != nil {
361
+ summaryOpts = append (summaryOpts , WithBiPolarityConditionTypes (tt .bipolarConditions ... ))
362
+ }
292
363
_ , gotErr := summaryHelper .SummarizeAndPatch (ctx , obj , summaryOpts ... )
293
364
g .Expect (gotErr != nil ).To (Equal (tt .wantErr ))
294
365
0 commit comments