Skip to content

Commit

Permalink
Fix finalizer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Barber committed Aug 16, 2021
1 parent 95e1966 commit 1761736
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 126 deletions.
30 changes: 15 additions & 15 deletions controllers/binding_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,21 @@ var _ = Describe("bindingController", func() {
})
})
})

Context("finalizer", func() {
BeforeEach(func() {
bindingName = "finalizer-test"
})

It("sets the correct deletion finalizer to the object", func() {
Expect(client.Create(ctx, &binding)).To(Succeed())
Eventually(func() []string {
var fetched topology.Binding
Expect(client.Get(ctx, types.NamespacedName{Name: binding.Name, Namespace: binding.Namespace}, &fetched)).To(Succeed())
return fetched.ObjectMeta.Finalizers
}, 5).Should(ConsistOf("deletion.finalizers.bindings.rabbitmq.com"))
})
})
})

When("a binding references a cluster from a prohibited namespace", func() {
Expand Down Expand Up @@ -235,21 +250,6 @@ var _ = Describe("bindingController", func() {
})
})

Context("finalizer", func() {
BeforeEach(func() {
bindingName = "finalizer-test"
})

It("sets the correct deletion finalizer to the object", func() {
Expect(client.Create(ctx, &binding)).To(Succeed())
Eventually(func() []string {
var fetched topology.Binding
Expect(client.Get(ctx, types.NamespacedName{Name: binding.Name, Namespace: binding.Namespace}, &fetched)).To(Succeed())
return fetched.ObjectMeta.Finalizers
}, 5).Should(ConsistOf("deletion.finalizers.bindings.rabbitmq.com"))
})
})

When("a binding references a cluster from an allowed namespace", func() {
JustBeforeEach(func() {
bindingName = "test-binding-allowed"
Expand Down
24 changes: 12 additions & 12 deletions controllers/exchange_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,20 @@ var _ = Describe("exchange-controller", func() {
})
})
})
})

Context("finalizer", func() {
BeforeEach(func() {
exchangeName = "finalizer-test"
})
Context("finalizer", func() {
BeforeEach(func() {
exchangeName = "finalizer-test"
})

It("sets the correct deletion finalizer to the object", func() {
Expect(client.Create(ctx, &exchange)).To(Succeed())
Eventually(func() []string {
var fetched topology.Exchange
Expect(client.Get(ctx, types.NamespacedName{Name: exchange.Name, Namespace: exchange.Namespace}, &fetched)).To(Succeed())
return fetched.ObjectMeta.Finalizers
}, 5).Should(ConsistOf("deletion.finalizers.exchanges.rabbitmq.com"))
It("sets the correct deletion finalizer to the object", func() {
Expect(client.Create(ctx, &exchange)).To(Succeed())
Eventually(func() []string {
var fetched topology.Exchange
Expect(client.Get(ctx, types.NamespacedName{Name: exchange.Name, Namespace: exchange.Namespace}, &fetched)).To(Succeed())
return fetched.ObjectMeta.Finalizers
}, 5).Should(ConsistOf("deletion.finalizers.exchanges.rabbitmq.com"))
})
})
})

Expand Down
24 changes: 12 additions & 12 deletions controllers/federation_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,20 +201,20 @@ var _ = Describe("federation-controller", func() {
})
})
})
})

Context("finalizer", func() {
BeforeEach(func() {
name = "finalizer-test"
})
Context("finalizer", func() {
BeforeEach(func() {
federationName = "finalizer-test"
})

It("sets the correct deletion finalizer to the object", func() {
Expect(client.Create(ctx, &federation)).To(Succeed())
Eventually(func() []string {
var fetched topology.Federation
Expect(client.Get(ctx, types.NamespacedName{Name: federation.Name, Namespace: federation.Namespace}, &fetched)).To(Succeed())
return fetched.ObjectMeta.Finalizers
}, 5).Should(ConsistOf("deletion.finalizers.federations.rabbitmq.com"))
It("sets the correct deletion finalizer to the object", func() {
Expect(client.Create(ctx, &federation)).To(Succeed())
Eventually(func() []string {
var fetched topology.Federation
Expect(client.Get(ctx, types.NamespacedName{Name: federation.Name, Namespace: federation.Namespace}, &fetched)).To(Succeed())
return fetched.ObjectMeta.Finalizers
}, 5).Should(ConsistOf("deletion.finalizers.federations.rabbitmq.com"))
})
})
})

Expand Down
24 changes: 12 additions & 12 deletions controllers/permission_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,20 +197,20 @@ var _ = Describe("permission-controller", func() {
})
})
})
})

Context("finalizer", func() {
BeforeEach(func() {
permissionName = "finalizer-test"
})
Context("finalizer", func() {
BeforeEach(func() {
permissionName = "finalizer-test"
})

It("sets the correct deletion finalizer to the object", func() {
Expect(client.Create(ctx, &permission)).To(Succeed())
Eventually(func() []string {
var fetched topology.Permission
Expect(client.Get(ctx, types.NamespacedName{Name: permission.Name, Namespace: permission.Namespace}, &fetched)).To(Succeed())
return fetched.ObjectMeta.Finalizers
}, 5).Should(ConsistOf("deletion.finalizers.permissions.rabbitmq.com"))
It("sets the correct deletion finalizer to the object", func() {
Expect(client.Create(ctx, &permission)).To(Succeed())
Eventually(func() []string {
var fetched topology.Permission
Expect(client.Get(ctx, types.NamespacedName{Name: permission.Name, Namespace: permission.Namespace}, &fetched)).To(Succeed())
return fetched.ObjectMeta.Finalizers
}, 5).Should(ConsistOf("deletion.finalizers.permissions.rabbitmq.com"))
})
})
})

Expand Down
24 changes: 12 additions & 12 deletions controllers/policy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,20 +203,20 @@ var _ = Describe("policy-controller", func() {
})
})
})
})

Context("finalizer", func() {
BeforeEach(func() {
policyName = "finalizer-test"
})
Context("finalizer", func() {
BeforeEach(func() {
policyName = "finalizer-test"
})

It("sets the correct deletion finalizer to the object", func() {
Expect(client.Create(ctx, &policy)).To(Succeed())
Eventually(func() []string {
var fetched topology.Policy
Expect(client.Get(ctx, types.NamespacedName{Name: policy.Name, Namespace: policy.Namespace}, &fetched)).To(Succeed())
return fetched.ObjectMeta.Finalizers
}, 5).Should(ConsistOf("deletion.finalizers.policies.rabbitmq.com"))
It("sets the correct deletion finalizer to the object", func() {
Expect(client.Create(ctx, &policy)).To(Succeed())
Eventually(func() []string {
var fetched topology.Policy
Expect(client.Get(ctx, types.NamespacedName{Name: policy.Name, Namespace: policy.Namespace}, &fetched)).To(Succeed())
return fetched.ObjectMeta.Finalizers
}, 5).Should(ConsistOf("deletion.finalizers.policies.rabbitmq.com"))
})
})
})

Expand Down
6 changes: 3 additions & 3 deletions controllers/queue_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (r *QueueReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
return ctrl.Result{}, r.deleteQueue(ctx, rabbitClient, queue)
}

if err := addFinalizerIfNeeded(ctx, r.Client, q); err != nil {
if err := addFinalizerIfNeeded(ctx, r.Client, queue); err != nil {
return ctrl.Result{}, err
}

Expand Down Expand Up @@ -170,8 +170,8 @@ func (r *QueueReconciler) deleteQueue(ctx context.Context, client internal.Rabbi
logger.Error(err, msg, "queue", queue.Spec.Name)
return err
}
r.Recorder.Event(q, corev1.EventTypeNormal, "SuccessfulDelete", "successfully deleted queue")
return removeFinalizer(ctx, r.Client, q)
r.Recorder.Event(queue, corev1.EventTypeNormal, "SuccessfulDelete", "successfully deleted queue")
return removeFinalizer(ctx, r.Client, queue)
}

func (r *QueueReconciler) SetupWithManager(mgr ctrl.Manager) error {
Expand Down
24 changes: 12 additions & 12 deletions controllers/queue_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,20 @@ var _ = Describe("queue-controller", func() {
})
})
})
})

Context("finalizer", func() {
BeforeEach(func() {
qName = "finalizer-test"
})
Context("finalizer", func() {
BeforeEach(func() {
queueName = "finalizer-test"
})

It("sets the correct deletion finalizer to the object", func() {
Expect(client.Create(ctx, &q)).To(Succeed())
Eventually(func() []string {
var fetched topology.Queue
Expect(client.Get(ctx, types.NamespacedName{Name: q.Name, Namespace: q.Namespace}, &fetched)).To(Succeed())
return fetched.ObjectMeta.Finalizers
}, 5).Should(ConsistOf("deletion.finalizers.queues.rabbitmq.com"))
It("sets the correct deletion finalizer to the object", func() {
Expect(client.Create(ctx, &queue)).To(Succeed())
Eventually(func() []string {
var fetched topology.Queue
Expect(client.Get(ctx, types.NamespacedName{Name: queue.Name, Namespace: queue.Namespace}, &fetched)).To(Succeed())
return fetched.ObjectMeta.Finalizers
}, 5).Should(ConsistOf("deletion.finalizers.queues.rabbitmq.com"))
})
})
})

Expand Down
24 changes: 12 additions & 12 deletions controllers/schemareplication_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,20 +201,20 @@ var _ = Describe("schema-replication-controller", func() {
})
})
})
})

Context("finalizer", func() {
BeforeEach(func() {
name = "finalizer-test"
})
Context("finalizer", func() {
BeforeEach(func() {
replicationName = "finalizer-test"
})

It("sets the correct deletion finalizer to the object", func() {
Expect(client.Create(ctx, &replication)).To(Succeed())
Eventually(func() []string {
var fetched topology.SchemaReplication
Expect(client.Get(ctx, types.NamespacedName{Name: replication.Name, Namespace: replication.Namespace}, &fetched)).To(Succeed())
return fetched.ObjectMeta.Finalizers
}, 5).Should(ConsistOf("deletion.finalizers.schemareplications.rabbitmq.com"))
It("sets the correct deletion finalizer to the object", func() {
Expect(client.Create(ctx, &replication)).To(Succeed())
Eventually(func() []string {
var fetched topology.SchemaReplication
Expect(client.Get(ctx, types.NamespacedName{Name: replication.Name, Namespace: replication.Namespace}, &fetched)).To(Succeed())
return fetched.ObjectMeta.Finalizers
}, 5).Should(ConsistOf("deletion.finalizers.schemareplications.rabbitmq.com"))
})
})
})

Expand Down
24 changes: 12 additions & 12 deletions controllers/shovel_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,20 +201,20 @@ var _ = Describe("shovel-controller", func() {
})
})
})
})

Context("finalizer", func() {
BeforeEach(func() {
name = "finalizer-test"
})
Context("finalizer", func() {
BeforeEach(func() {
shovelName = "finalizer-test"
})

It("sets the correct deletion finalizer to the object", func() {
Expect(client.Create(ctx, &shovel)).To(Succeed())
Eventually(func() []string {
var fetched topology.Shovel
Expect(client.Get(ctx, types.NamespacedName{Name: shovel.Name, Namespace: shovel.Namespace}, &fetched)).To(Succeed())
return fetched.ObjectMeta.Finalizers
}, 5).Should(ConsistOf("deletion.finalizers.shovels.rabbitmq.com"))
It("sets the correct deletion finalizer to the object", func() {
Expect(client.Create(ctx, &shovel)).To(Succeed())
Eventually(func() []string {
var fetched topology.Shovel
Expect(client.Get(ctx, types.NamespacedName{Name: shovel.Name, Namespace: shovel.Namespace}, &fetched)).To(Succeed())
return fetched.ObjectMeta.Finalizers
}, 5).Should(ConsistOf("deletion.finalizers.shovels.rabbitmq.com"))
})
})
})

Expand Down
24 changes: 12 additions & 12 deletions controllers/user_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,20 +230,20 @@ var _ = Describe("UserController", func() {
})
})
})
})

Context("finalizer", func() {
BeforeEach(func() {
userName = "finalizer-test"
})
Context("finalizer", func() {
BeforeEach(func() {
userName = "finalizer-test"
})

It("sets the correct deletion finalizer to the object", func() {
Expect(client.Create(ctx, &user)).To(Succeed())
Eventually(func() []string {
var fetched topology.User
Expect(client.Get(ctx, types.NamespacedName{Name: user.Name, Namespace: user.Namespace}, &fetched)).To(Succeed())
return fetched.ObjectMeta.Finalizers
}, 5).Should(ConsistOf("deletion.finalizers.users.rabbitmq.com"))
It("sets the correct deletion finalizer to the object", func() {
Expect(client.Create(ctx, &user)).To(Succeed())
Eventually(func() []string {
var fetched topology.User
Expect(client.Get(ctx, types.NamespacedName{Name: user.Name, Namespace: user.Namespace}, &fetched)).To(Succeed())
return fetched.ObjectMeta.Finalizers
}, 5).Should(ConsistOf("deletion.finalizers.users.rabbitmq.com"))
})
})
})

Expand Down
24 changes: 12 additions & 12 deletions controllers/vhost_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,20 @@ var _ = Describe("vhost-controller", func() {
})
})
})
})

Context("finalizer", func() {
BeforeEach(func() {
vhostName = "finalizer-test"
})
Context("finalizer", func() {
BeforeEach(func() {
vhostName = "finalizer-test"
})

It("sets the correct deletion finalizer to the object", func() {
Expect(client.Create(ctx, &vhost)).To(Succeed())
Eventually(func() []string {
var fetched topology.Vhost
Expect(client.Get(ctx, types.NamespacedName{Name: vhost.Name, Namespace: vhost.Namespace}, &fetched)).To(Succeed())
return fetched.ObjectMeta.Finalizers
}, 5).Should(ConsistOf("deletion.finalizers.vhosts.rabbitmq.com"))
It("sets the correct deletion finalizer to the object", func() {
Expect(client.Create(ctx, &vhost)).To(Succeed())
Eventually(func() []string {
var fetched topology.Vhost
Expect(client.Get(ctx, types.NamespacedName{Name: vhost.Name, Namespace: vhost.Namespace}, &fetched)).To(Succeed())
return fetched.ObjectMeta.Finalizers
}, 5).Should(ConsistOf("deletion.finalizers.vhosts.rabbitmq.com"))
})
})
})

Expand Down

0 comments on commit 1761736

Please sign in to comment.