Skip to content

Commit

Permalink
Merge pull request #3231 from vincepri/use-patch
Browse files Browse the repository at this point in the history
🌱 Use patch in tests instead of update
  • Loading branch information
k8s-ci-robot authored Jun 23, 2020
2 parents 4a5d66b + 3c8814e commit 024d170
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions controllers/machinehealthcheck_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,23 @@ var _ = Describe("MachineHealthCheck", func() {
Expect(testEnv.Create(ctx, machine)).To(Succeed())

node := node.DeepCopy()
nodeStatus := node.Status
Expect(testEnv.Create(ctx, node)).To(Succeed())
Expect(testEnv.Status().Update(ctx, node)).To(Succeed())
nodePatch := client.MergeFrom(node.DeepCopy())
node.Status = nodeStatus
Expect(testEnv.Status().Patch(ctx, node, nodePatch)).To(Succeed())
nodes = append(nodes, node)

if nodeRef {
machinePatch := client.MergeFrom(machine.DeepCopy())
machine.Status = machineStatus
machine.Status.NodeRef = &corev1.ObjectReference{
Name: node.Name,
}

now := metav1.NewTime(time.Now())
machine.Status.LastUpdated = &now
Expect(testEnv.Status().Update(ctx, machine)).To(Succeed())
Expect(testEnv.Status().Patch(ctx, machine, machinePatch)).To(Succeed())
}

machines = append(machines, machine)
Expand Down Expand Up @@ -439,8 +443,9 @@ var _ = Describe("MachineHealthCheck", func() {

// Fake an earlier NodeStartupTimeout.
lastUpdatedTwiceNodeStartupTimeout := metav1.NewTime(time.Now().Add(-2 * mhc.Spec.NodeStartupTimeout.Duration))
machinePatch := client.MergeFrom(machines[2].DeepCopy())
machines[2].Status.LastUpdated = &lastUpdatedTwiceNodeStartupTimeout
Expect(testEnv.Status().Update(ctx, machines[2]))
Expect(testEnv.Status().Patch(ctx, machines[2], machinePatch))

// Make sure the status matches.
Eventually(func() *clusterv1.MachineHealthCheckStatus {
Expand Down Expand Up @@ -577,14 +582,15 @@ var _ = Describe("MachineHealthCheck", func() {

// Transition the node to unhealthy.
node := nodes[0]
nodePatch := client.MergeFrom(node.DeepCopy())
node.Status.Conditions = []corev1.NodeCondition{
{
Type: corev1.NodeReady,
Status: corev1.ConditionUnknown,
LastTransitionTime: metav1.NewTime(time.Now().Add(-10 * time.Minute)),
},
}
Expect(testEnv.Status().Update(ctx, node)).To(Succeed())
Expect(testEnv.Status().Patch(ctx, node, nodePatch)).To(Succeed())

// Make sure the status matches.
Eventually(func() *clusterv1.MachineHealthCheckStatus {
Expand Down

0 comments on commit 024d170

Please sign in to comment.