Skip to content

Commit

Permalink
add test for patchHelper logic around deletionTimestamps/finalizers
Browse files Browse the repository at this point in the history
Signed-off-by: Troy Connor <troy0820@users.noreply.github.com>
  • Loading branch information
troy0820 committed Jul 16, 2024
1 parent 6f06154 commit 79c9e92
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions util/patch/patch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,32 @@ func TestPatchHelper(t *testing.T) {

g.Expect(patcher.Patch(ctx, machineSet)).NotTo(Succeed())
})

t.Run("Should not error if there are no finalizers and deletion timestamp is not nil", func(t *testing.T) {
g := NewWithT(t)
cluster := &clusterv1.Cluster{
ObjectMeta: metav1.ObjectMeta{
Name: "test-cluster",
Namespace: ns.Name,
Finalizers: []string{"block-deletion"},
},
Status: clusterv1.ClusterStatus{},
}
key := client.ObjectKey{Name: cluster.GetName(), Namespace: cluster.GetNamespace()}
g.Expect(env.Create(ctx, cluster)).To(Succeed())
g.Expect(env.Delete(ctx, cluster)).To(Succeed())

// Ensure cluster still exists & get Cluster with deletionTimestamp set
g.Expect(env.Get(ctx, key, cluster)).To(Succeed())

// Patch helper will first remove the finalizer and then it will get a not found error when
// trying to patch status. This test validates that the not found error is ignored.
patcher, err := NewHelper(cluster, env)
g.Expect(err).ToNot(HaveOccurred())
cluster.Finalizers = []string{}
cluster.Status.Phase = "Running"
g.Expect(patcher.Patch(ctx, cluster)).To(Succeed())
})
}

func TestNewHelperNil(t *testing.T) {
Expand Down

0 comments on commit 79c9e92

Please sign in to comment.