Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#10866 from troy0820/troy0820/add-t…
Browse files Browse the repository at this point in the history
…est-for-patchHelper

🌱 Add test for patchHelper logic around deletionTimestamps/finalizers
  • Loading branch information
k8s-ci-robot authored Jul 16, 2024
2 parents 377bd19 + 79c9e92 commit f4b6762
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 f4b6762

Please sign in to comment.