Skip to content

Commit 79c9e92

Browse files
committed
add test for patchHelper logic around deletionTimestamps/finalizers
Signed-off-by: Troy Connor <[email protected]>
1 parent 6f06154 commit 79c9e92

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

util/patch/patch_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,32 @@ func TestPatchHelper(t *testing.T) {
958958

959959
g.Expect(patcher.Patch(ctx, machineSet)).NotTo(Succeed())
960960
})
961+
962+
t.Run("Should not error if there are no finalizers and deletion timestamp is not nil", func(t *testing.T) {
963+
g := NewWithT(t)
964+
cluster := &clusterv1.Cluster{
965+
ObjectMeta: metav1.ObjectMeta{
966+
Name: "test-cluster",
967+
Namespace: ns.Name,
968+
Finalizers: []string{"block-deletion"},
969+
},
970+
Status: clusterv1.ClusterStatus{},
971+
}
972+
key := client.ObjectKey{Name: cluster.GetName(), Namespace: cluster.GetNamespace()}
973+
g.Expect(env.Create(ctx, cluster)).To(Succeed())
974+
g.Expect(env.Delete(ctx, cluster)).To(Succeed())
975+
976+
// Ensure cluster still exists & get Cluster with deletionTimestamp set
977+
g.Expect(env.Get(ctx, key, cluster)).To(Succeed())
978+
979+
// Patch helper will first remove the finalizer and then it will get a not found error when
980+
// trying to patch status. This test validates that the not found error is ignored.
981+
patcher, err := NewHelper(cluster, env)
982+
g.Expect(err).ToNot(HaveOccurred())
983+
cluster.Finalizers = []string{}
984+
cluster.Status.Phase = "Running"
985+
g.Expect(patcher.Patch(ctx, cluster)).To(Succeed())
986+
})
961987
}
962988

963989
func TestNewHelperNil(t *testing.T) {

0 commit comments

Comments
 (0)