Skip to content

Commit

Permalink
fix: linter issues
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriele Quaresima <gabriele.quaresima@enterprisedb.com>
  • Loading branch information
gabriele-wolfox committed Sep 25, 2024
1 parent fd36b48 commit 1024a9e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
1 change: 0 additions & 1 deletion internal/controller/finalizers_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ func (r *ClusterReconciler) deleteDatabaseFinalizers(ctx context.Context, namesp
"oldFinalizerList", database.ObjectMeta.Finalizers,
"newFinalizerList", dbWithoutFinalizer.ObjectMeta.Finalizers,
)
continue
}
}
}
Expand Down
30 changes: 17 additions & 13 deletions internal/controller/finalizers_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"

"github.com/cloudnative-pg/cloudnative-pg/api/v1"
apiv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1"
schemeBuilder "github.com/cloudnative-pg/cloudnative-pg/internal/scheme"
"github.com/cloudnative-pg/cloudnative-pg/pkg/utils"

Expand Down Expand Up @@ -52,61 +52,65 @@ var _ = Describe("Database CRD finalizers", func() {

It("should be deleted when the cluster name matches with the database cluster ref name",
func(ctx SpecContext) {
databaseList := &v1.DatabaseList{
Items: []v1.Database{
databaseList := &apiv1.DatabaseList{
Items: []apiv1.Database{
{
ObjectMeta: metav1.ObjectMeta{
Finalizers: []string{
utils.DatabaseFinalizerName,
},
Name: "db-1",
Namespace: "test"},
Spec: v1.DatabaseSpec{
Namespace: "test",
},
Spec: apiv1.DatabaseSpec{
Name: "db-test",
ClusterRef: corev1.LocalObjectReference{
Name: "cluster",
},
},
},
}}
},
}

cli := fake.NewClientBuilder().WithScheme(scheme).WithLists(databaseList).Build()
r.Client = cli
err := r.deleteDatabaseFinalizers(ctx, namespacedName)
Expect(err).ToNot(HaveOccurred())

database := &v1.Database{}
database := &apiv1.Database{}
err = cli.Get(ctx, client.ObjectKeyFromObject(&databaseList.Items[0]), database)
Expect(err).ToNot(HaveOccurred())
Expect(database.Finalizers).To(BeZero())
})

It("should not be deleted when the cluster name does not match with the database cluster ref name",
func(ctx SpecContext) {
databaseList := &v1.DatabaseList{
Items: []v1.Database{
databaseList := &apiv1.DatabaseList{
Items: []apiv1.Database{
{
ObjectMeta: metav1.ObjectMeta{
Finalizers: []string{
utils.DatabaseFinalizerName,
},
Name: "db-1",
Namespace: "test"},
Spec: v1.DatabaseSpec{
Namespace: "test",
},
Spec: apiv1.DatabaseSpec{
Name: "db-test",
ClusterRef: corev1.LocalObjectReference{
Name: "wrong-cluster",
},
},
},
}}
},
}

cli := fake.NewClientBuilder().WithScheme(scheme).WithLists(databaseList).Build()
r.Client = cli
err := r.deleteDatabaseFinalizers(ctx, namespacedName)
Expect(err).ToNot(HaveOccurred())

database := &v1.Database{}
database := &apiv1.Database{}
err = cli.Get(ctx, client.ObjectKeyFromObject(&databaseList.Items[0]), database)
Expect(err).ToNot(HaveOccurred())
Expect(database.Finalizers).To(BeEquivalentTo([]string{utils.DatabaseFinalizerName}))
Expand Down

0 comments on commit 1024a9e

Please # to comment.