Skip to content

Commit 22c4422

Browse files
authored
K8SPS-257: fix TestCheckFinalizers unit-test (#387)
https://jira.percona.com/browse/K8SPS-257
1 parent 89edb35 commit 22c4422

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

pkg/controller/psbackup/controller_test.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import (
77
"path/filepath"
88
"reflect"
99
"testing"
10-
"time"
1110

1211
batchv1 "k8s.io/api/batch/v1"
1312
corev1 "k8s.io/api/core/v1"
13+
k8serrors "k8s.io/apimachinery/pkg/api/errors"
1414
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1515
"k8s.io/apimachinery/pkg/runtime"
1616
"k8s.io/apimachinery/pkg/types"
@@ -266,7 +266,6 @@ func TestCheckFinalizers(t *testing.T) {
266266

267267
for _, tt := range tests {
268268
t.Run(tt.name, func(t *testing.T) {
269-
tt.cr.DeletionTimestamp = &metav1.Time{Time: time.Now()}
270269
tt.cr.Status.Storage = storage
271270

272271
job := xtrabackup.GetDeleteJob(tt.cr, new(xtrabackup.BackupConfig))
@@ -285,9 +284,20 @@ func TestCheckFinalizers(t *testing.T) {
285284
Scheme: scheme,
286285
ServerVersion: &platform.ServerVersion{Platform: platform.PlatformKubernetes},
287286
}
287+
err := r.Delete(ctx, tt.cr)
288+
if err != nil {
289+
t.Fatal(err)
290+
}
291+
cr := new(apiv1alpha1.PerconaServerMySQLBackup)
292+
if err := r.Get(ctx, types.NamespacedName{Name: tt.cr.Name, Namespace: tt.cr.Namespace}, cr); err != nil {
293+
if k8serrors.IsNotFound(err) && len(cr.Finalizers) == 0 {
294+
return
295+
}
296+
t.Fatal(err)
297+
}
288298

289-
r.checkFinalizers(ctx, tt.cr)
290-
if !reflect.DeepEqual(tt.cr.Finalizers, tt.expectedFinalizers) {
299+
r.checkFinalizers(ctx, cr)
300+
if !reflect.DeepEqual(cr.Finalizers, tt.expectedFinalizers) {
291301
t.Fatalf("expected finalizers %v, got %v", tt.expectedFinalizers, tt.cr.Finalizers)
292302
}
293303
})

0 commit comments

Comments
 (0)