@@ -34,6 +34,7 @@ func TestSummary(t *testing.T) {
34
34
conditionType string
35
35
options []SummaryOption
36
36
want * metav1.Condition
37
+ wantErr bool
37
38
}{
38
39
{
39
40
name : "One issue" ,
@@ -210,14 +211,14 @@ func TestSummary(t *testing.T) {
210
211
},
211
212
},
212
213
{
213
- name : "Include additional condition" ,
214
+ name : "Override condition" ,
214
215
conditions : []metav1.Condition {
215
216
{Type : "A" , Status : metav1 .ConditionTrue , Reason : "Reason-A" , Message : "Message-A" }, // info
216
217
{Type : "!C" , Status : metav1 .ConditionTrue , Reason : "Reason-C" , Message : "Message-C" }, // issue
217
218
},
218
219
conditionType : clusterv1 .AvailableV1Beta2Condition ,
219
- options : []SummaryOption {ForConditionTypes {"A" }, NegativePolarityConditionTypes {"!C" }, IgnoreTypesIfMissing {"!C" },
220
- AdditionalConditions {
220
+ options : []SummaryOption {ForConditionTypes {"A" , "!C" }, NegativePolarityConditionTypes {"!C" }, IgnoreTypesIfMissing {"!C" },
221
+ OverrideConditions {
221
222
{
222
223
OwnerResource : ConditionOwnerInfo {
223
224
Kind : "Phase3Obj" ,
@@ -227,14 +228,35 @@ func TestSummary(t *testing.T) {
227
228
Type : "!C" , Status : metav1 .ConditionTrue , Reason : "Reason-C-additional" , Message : "Message-C-additional" , // issue
228
229
},
229
230
},
230
- }}, // AdditionalCondition replaces the same condition from the SourceObject
231
+ }}, // OverrideCondition replaces the same condition from the SourceObject
231
232
want : & metav1.Condition {
232
233
Type : clusterv1 .AvailableV1Beta2Condition ,
233
234
Status : metav1 .ConditionFalse , // False because !C is an issue
234
235
Reason : "Reason-C-additional" , // Picking the reason from the additional condition
235
236
Message : "!C: Message-C-additional" , // Picking the message from the additional condition (info dropped)
236
237
},
237
238
},
239
+ {
240
+ name : "Error if override condition does not exist in source object" ,
241
+ conditions : []metav1.Condition {
242
+ {Type : "A" , Status : metav1 .ConditionTrue , Reason : "Reason-A" , Message : "Message-A" }, // info
243
+ // !C is missing in source object
244
+ },
245
+ conditionType : clusterv1 .AvailableV1Beta2Condition ,
246
+ options : []SummaryOption {ForConditionTypes {"A" , "!C" }, NegativePolarityConditionTypes {"!C" }, IgnoreTypesIfMissing {"!C" },
247
+ OverrideConditions {
248
+ {
249
+ OwnerResource : ConditionOwnerInfo {
250
+ Kind : "Phase3Obj" ,
251
+ Name : "SourceObject" ,
252
+ },
253
+ Condition : metav1.Condition {
254
+ Type : "!C" , Status : metav1 .ConditionTrue , Reason : "Reason-C-additional" , Message : "Message-C-additional" , // issue
255
+ },
256
+ },
257
+ }},
258
+ wantErr : true ,
259
+ },
238
260
}
239
261
240
262
for _ , tt := range tests {
@@ -252,7 +274,7 @@ func TestSummary(t *testing.T) {
252
274
}
253
275
254
276
got , err := NewSummaryCondition (obj , tt .conditionType , tt .options ... )
255
- g .Expect (err ). ToNot ( HaveOccurred ( ))
277
+ g .Expect (err != nil ). To ( Equal ( tt . wantErr ))
256
278
257
279
g .Expect (got ).To (Equal (tt .want ))
258
280
})
0 commit comments