@@ -213,12 +213,12 @@ func TestReconcileMachinePhases(t *testing.T) {
213
213
214
214
g .Expect (env .Create (ctx , bootstrapConfig )).To (Succeed ())
215
215
g .Expect (env .Create (ctx , infraMachine )).To (Succeed ())
216
+ // We have to subtract 2 seconds, because .status.lastUpdated does not contain miliseconds.
217
+ preUpdate := time .Now ().Add (- 2 * time .Second )
216
218
g .Expect (env .Create (ctx , machine )).To (Succeed ())
217
219
218
220
// Set the LastUpdated to be able to verify it is updated when the phase changes
219
221
modifiedMachine := machine .DeepCopy ()
220
- lastUpdated := metav1 .NewTime (time .Now ().Add (- 10 * time .Second ))
221
- machine .Status .LastUpdated = & lastUpdated
222
222
g .Expect (env .Status ().Patch (ctx , modifiedMachine , client .MergeFrom (machine ))).To (Succeed ())
223
223
224
224
// Set bootstrap ready.
@@ -235,7 +235,7 @@ func TestReconcileMachinePhases(t *testing.T) {
235
235
g .Expect (machine .Status .GetTypedPhase ()).To (Equal (clusterv1 .MachinePhaseProvisioning ))
236
236
// Verify that the LastUpdated timestamp was updated
237
237
g .Expect (machine .Status .LastUpdated ).NotTo (BeNil ())
238
- g .Expect (machine .Status .LastUpdated .After (lastUpdated . Time )).To (BeTrue ())
238
+ g .Expect (machine .Status .LastUpdated .After (preUpdate )).To (BeTrue ())
239
239
return true
240
240
}, 10 * time .Second ).Should (BeTrue ())
241
241
})
@@ -281,14 +281,13 @@ func TestReconcileMachinePhases(t *testing.T) {
281
281
282
282
g .Expect (env .Create (ctx , bootstrapConfig )).To (Succeed ())
283
283
g .Expect (env .Create (ctx , infraMachine )).To (Succeed ())
284
+ // We have to subtract 2 seconds, because .status.lastUpdated does not contain miliseconds.
285
+ preUpdate := time .Now ().Add (- 2 * time .Second )
284
286
g .Expect (env .Create (ctx , machine )).To (Succeed ())
285
287
286
288
modifiedMachine := machine .DeepCopy ()
287
289
// Set NodeRef.
288
290
machine .Status .NodeRef = & corev1.ObjectReference {Kind : "Node" , Name : node .Name }
289
- // Set the LastUpdated to be able to verify it is updated when the phase changes
290
- lastUpdated := metav1 .NewTime (time .Now ().Add (- 10 * time .Second ))
291
- machine .Status .LastUpdated = & lastUpdated
292
291
g .Expect (env .Status ().Patch (ctx , modifiedMachine , client .MergeFrom (machine ))).To (Succeed ())
293
292
294
293
// Set bootstrap ready.
@@ -322,7 +321,7 @@ func TestReconcileMachinePhases(t *testing.T) {
322
321
g .Expect (machine .Status .GetTypedPhase ()).To (Equal (clusterv1 .MachinePhaseRunning ))
323
322
// Verify that the LastUpdated timestamp was updated
324
323
g .Expect (machine .Status .LastUpdated ).NotTo (BeNil ())
325
- g .Expect (machine .Status .LastUpdated .After (lastUpdated . Time )).To (BeTrue ())
324
+ g .Expect (machine .Status .LastUpdated .After (preUpdate )).To (BeTrue ())
326
325
return true
327
326
}, 10 * time .Second ).Should (BeTrue ())
328
327
})
@@ -441,14 +440,13 @@ func TestReconcileMachinePhases(t *testing.T) {
441
440
442
441
g .Expect (env .Create (ctx , bootstrapConfig )).To (Succeed ())
443
442
g .Expect (env .Create (ctx , infraMachine )).To (Succeed ())
443
+ // We have to subtract 2 seconds, because .status.lastUpdated does not contain miliseconds.
444
+ preUpdate := time .Now ().Add (- 2 * time .Second )
444
445
g .Expect (env .Create (ctx , machine )).To (Succeed ())
445
446
446
447
modifiedMachine := machine .DeepCopy ()
447
448
// Set NodeRef.
448
449
machine .Status .NodeRef = & corev1.ObjectReference {Kind : "Node" , Name : node .Name }
449
- // Set the LastUpdated to be able to verify it is updated when the phase changes
450
- lastUpdated := metav1 .NewTime (time .Now ().Add (- 10 * time .Second ))
451
- machine .Status .LastUpdated = & lastUpdated
452
450
g .Expect (env .Status ().Patch (ctx , modifiedMachine , client .MergeFrom (machine ))).To (Succeed ())
453
451
454
452
// Set bootstrap ready.
@@ -470,7 +468,7 @@ func TestReconcileMachinePhases(t *testing.T) {
470
468
g .Expect (machine .Status .GetTypedPhase ()).To (Equal (clusterv1 .MachinePhaseRunning ))
471
469
// Verify that the LastUpdated timestamp was updated
472
470
g .Expect (machine .Status .LastUpdated ).NotTo (BeNil ())
473
- g .Expect (machine .Status .LastUpdated .After (lastUpdated . Time )).To (BeTrue ())
471
+ g .Expect (machine .Status .LastUpdated .After (preUpdate )).To (BeTrue ())
474
472
return true
475
473
}, 10 * time .Second ).Should (BeTrue ())
476
474
})
@@ -573,6 +571,8 @@ func TestReconcileMachinePhases(t *testing.T) {
573
571
574
572
g .Expect (env .Create (ctx , bootstrapConfig )).To (Succeed ())
575
573
g .Expect (env .Create (ctx , infraMachine )).To (Succeed ())
574
+ // We have to subtract 2 seconds, because .status.lastUpdated does not contain miliseconds.
575
+ preUpdate := time .Now ().Add (- 2 * time .Second )
576
576
g .Expect (env .Create (ctx , machine )).To (Succeed ())
577
577
578
578
// Set bootstrap ready.
@@ -597,9 +597,6 @@ func TestReconcileMachinePhases(t *testing.T) {
597
597
modifiedMachine := machine .DeepCopy ()
598
598
// Set NodeRef.
599
599
machine .Status .NodeRef = & corev1.ObjectReference {Kind : "Node" , Name : node .Name }
600
- // Set the LastUpdated to be able to verify it is updated when the phase changes
601
- lastUpdated := metav1 .NewTime (time .Now ().Add (- 10 * time .Second ))
602
- machine .Status .LastUpdated = & lastUpdated
603
600
g .Expect (env .Status ().Patch (ctx , modifiedMachine , client .MergeFrom (machine ))).To (Succeed ())
604
601
605
602
modifiedMachine = machine .DeepCopy ()
@@ -621,7 +618,7 @@ func TestReconcileMachinePhases(t *testing.T) {
621
618
g .Expect (nodeHealthyCondition .Reason ).To (Equal (clusterv1 .DeletingReason ))
622
619
// Verify that the LastUpdated timestamp was updated
623
620
g .Expect (machine .Status .LastUpdated ).NotTo (BeNil ())
624
- g .Expect (machine .Status .LastUpdated .After (lastUpdated . Time )).To (BeTrue ())
621
+ g .Expect (machine .Status .LastUpdated .After (preUpdate )).To (BeTrue ())
625
622
return true
626
623
}, 10 * time .Second ).Should (BeTrue ())
627
624
})
0 commit comments