@@ -202,6 +202,67 @@ func TestSetCRDCondition(t *testing.T) {
202
202
},
203
203
},
204
204
},
205
+ {
206
+ name : "set new condition which doesn't have lastTransitionTime set" ,
207
+ crdCondition : []CustomResourceDefinitionCondition {
208
+ {
209
+ Type : Established ,
210
+ Status : ConditionTrue ,
211
+ Reason : "Accepted" ,
212
+ Message : "the initial names have been accepted" ,
213
+ LastTransitionTime : metav1 .Date (2018 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ),
214
+ },
215
+ },
216
+ newCondition : CustomResourceDefinitionCondition {
217
+ Type : Established ,
218
+ Status : ConditionFalse ,
219
+ Reason : "NotAccepted" ,
220
+ Message : "Not accepted" ,
221
+ },
222
+ expectedcrdCondition : []CustomResourceDefinitionCondition {
223
+ {
224
+ Type : Established ,
225
+ Status : ConditionFalse ,
226
+ Reason : "NotAccepted" ,
227
+ Message : "Not accepted" ,
228
+ LastTransitionTime : metav1 .Date (2018 , 1 , 2 , 0 , 0 , 0 , 0 , time .UTC ),
229
+ },
230
+ },
231
+ },
232
+ {
233
+ name : "append new condition which doesn't have lastTransitionTime set" ,
234
+ crdCondition : []CustomResourceDefinitionCondition {
235
+ {
236
+ Type : Established ,
237
+ Status : ConditionTrue ,
238
+ Reason : "Accepted" ,
239
+ Message : "the initial names have been accepted" ,
240
+ LastTransitionTime : metav1 .Date (2018 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ),
241
+ },
242
+ },
243
+ newCondition : CustomResourceDefinitionCondition {
244
+ Type : Terminating ,
245
+ Status : ConditionFalse ,
246
+ Reason : "NeverEstablished" ,
247
+ Message : "resource was never established" ,
248
+ },
249
+ expectedcrdCondition : []CustomResourceDefinitionCondition {
250
+ {
251
+ Type : Established ,
252
+ Status : ConditionTrue ,
253
+ Reason : "Accepted" ,
254
+ Message : "the initial names have been accepted" ,
255
+ LastTransitionTime : metav1 .Date (2018 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ),
256
+ },
257
+ {
258
+ Type : Terminating ,
259
+ Status : ConditionFalse ,
260
+ Reason : "NeverEstablished" ,
261
+ Message : "resource was never established" ,
262
+ LastTransitionTime : metav1 .Date (2018 , 2 , 1 , 0 , 0 , 0 , 0 , time .UTC ),
263
+ },
264
+ },
265
+ },
205
266
}
206
267
for _ , tc := range tests {
207
268
crd := generateCRDwithCondition (tc .crdCondition )
@@ -213,6 +274,9 @@ func TestSetCRDCondition(t *testing.T) {
213
274
if ! IsCRDConditionEquivalent (& tc .expectedcrdCondition [i ], & crd .Status .Conditions [i ]) {
214
275
t .Errorf ("%v expected %v, got %v" , tc .name , tc .expectedcrdCondition , crd .Status .Conditions )
215
276
}
277
+ if crd .Status .Conditions [i ].LastTransitionTime .IsZero () {
278
+ t .Errorf ("%q lastTransitionTime should not be null: %v" , tc .name , i , crd .Status .Conditions )
279
+ }
216
280
}
217
281
}
218
282
}
0 commit comments