Skip to content

Commit 455877c

Browse files
author
Anna
committed
Refactor tests to use 'When' for deletion policy scenarios in queue, shovel, and vhost
1 parent 570acb9 commit 455877c

File tree

3 files changed

+100
-94
lines changed

3 files changed

+100
-94
lines changed

system_tests/queue_system_test.go

+34-32
Original file line numberDiff line numberDiff line change
@@ -103,43 +103,45 @@ var _ = Describe("Queue Controller", func() {
103103
Expect(err.Error()).To(ContainSubstring("Object Not Found"))
104104
})
105105

106-
It("with DeletionPolicy=retain, deletes k8s resource but keeps the queue in RabbitMQ", func() {
107-
queueWithRetain := &topology.Queue{
108-
ObjectMeta: metav1.ObjectMeta{
109-
Name: "retain-policy-test",
110-
Namespace: namespace,
111-
},
112-
Spec: topology.QueueSpec{
113-
Name: "retain-policy-test",
114-
Type: "classic",
115-
Durable: true,
116-
DeletionPolicy: "retain",
117-
RabbitmqClusterReference: topology.RabbitmqClusterReference{
118-
Name: rmq.Name,
106+
When("deletion policy is retain", func() {
107+
It("deletes k8s resource but keeps the queue in RabbitMQ", func() {
108+
queueWithRetain := &topology.Queue{
109+
ObjectMeta: metav1.ObjectMeta{
110+
Name: "retain-policy-test",
111+
Namespace: namespace,
119112
},
120-
},
121-
}
113+
Spec: topology.QueueSpec{
114+
Name: "retain-policy-test",
115+
Type: "classic",
116+
Durable: true,
117+
DeletionPolicy: "retain",
118+
RabbitmqClusterReference: topology.RabbitmqClusterReference{
119+
Name: rmq.Name,
120+
},
121+
},
122+
}
122123

123-
By("creating a queue with retain policy")
124-
Expect(k8sClient.Create(ctx, queueWithRetain, &client.CreateOptions{})).To(Succeed())
124+
By("creating a queue with retain policy")
125+
Expect(k8sClient.Create(ctx, queueWithRetain, &client.CreateOptions{})).To(Succeed())
125126

126-
By("waiting for the queue to be created in RabbitMQ")
127-
Eventually(func() error {
128-
_, err := rabbitClient.GetQueue("/", queueWithRetain.Spec.Name)
129-
return err
130-
}, 30, 2).ShouldNot(HaveOccurred())
127+
By("waiting for the queue to be created in RabbitMQ")
128+
Eventually(func() error {
129+
_, err := rabbitClient.GetQueue("/", queueWithRetain.Spec.Name)
130+
return err
131+
}, 30, 2).ShouldNot(HaveOccurred())
131132

132-
By("deleting the k8s resource")
133-
Expect(k8sClient.Delete(ctx, queueWithRetain)).To(Succeed())
133+
By("deleting the k8s resource")
134+
Expect(k8sClient.Delete(ctx, queueWithRetain)).To(Succeed())
134135

135-
By("verifying k8s resource is gone")
136-
Eventually(func() bool {
137-
err := k8sClient.Get(ctx, types.NamespacedName{Name: queueWithRetain.Name, Namespace: queueWithRetain.Namespace}, &topology.Queue{})
138-
return apierrors.IsNotFound(err)
139-
}, 30, 2).Should(BeTrue())
136+
By("verifying k8s resource is gone")
137+
Eventually(func() bool {
138+
err := k8sClient.Get(ctx, types.NamespacedName{Name: queueWithRetain.Name, Namespace: queueWithRetain.Namespace}, &topology.Queue{})
139+
return apierrors.IsNotFound(err)
140+
}, 30, 2).Should(BeTrue())
140141

141-
By("verifying queue still exists in RabbitMQ")
142-
_, err := rabbitClient.GetQueue("/", queueWithRetain.Spec.Name)
143-
Expect(err).NotTo(HaveOccurred())
142+
By("verifying queue still exists in RabbitMQ")
143+
_, err := rabbitClient.GetQueue("/", queueWithRetain.Spec.Name)
144+
Expect(err).NotTo(HaveOccurred())
145+
})
144146
})
145147
})

system_tests/shovel_system_test.go

+34-32
Original file line numberDiff line numberDiff line change
@@ -147,44 +147,46 @@ var _ = Describe("Shovel", func() {
147147
assertShovelDeleted(shovel)
148148
})
149149

150-
It("with DeletionPolicy=retain, deletes k8s resource but keeps the shovel in RabbitMQ", func() {
151-
shovelWithRetain := &topology.Shovel{
152-
ObjectMeta: metav1.ObjectMeta{
153-
Name: "retain-policy-test",
154-
Namespace: namespace,
155-
},
156-
Spec: topology.ShovelSpec{
157-
Name: "retain-policy-test",
158-
UriSecret: &corev1.LocalObjectReference{Name: shovelSecret.Name},
159-
DeletionPolicy: "retain",
160-
SourceQueue: "test-queue",
161-
RabbitmqClusterReference: topology.RabbitmqClusterReference{
162-
Name: rmq.Name,
150+
When("deletion policy is retain", func() {
151+
It("deletes k8s resource but keeps the shovel in RabbitMQ", func() {
152+
shovelWithRetain := &topology.Shovel{
153+
ObjectMeta: metav1.ObjectMeta{
154+
Name: "retain-policy-test",
155+
Namespace: namespace,
163156
},
164-
},
165-
}
157+
Spec: topology.ShovelSpec{
158+
Name: "retain-policy-test",
159+
UriSecret: &corev1.LocalObjectReference{Name: shovelSecret.Name},
160+
DeletionPolicy: "retain",
161+
SourceQueue: "test-queue",
162+
RabbitmqClusterReference: topology.RabbitmqClusterReference{
163+
Name: rmq.Name,
164+
},
165+
},
166+
}
166167

167-
By("creating a shovel with retain policy")
168-
Expect(k8sClient.Create(ctx, shovelWithRetain, &client.CreateOptions{})).To(Succeed())
168+
By("creating a shovel with retain policy")
169+
Expect(k8sClient.Create(ctx, shovelWithRetain, &client.CreateOptions{})).To(Succeed())
169170

170-
By("waiting for the shovel to be created in RabbitMQ")
171-
Eventually(func() error {
172-
_, err := rabbitClient.GetShovel("/", shovelWithRetain.Spec.Name)
173-
return err
174-
}, 30, 2).ShouldNot(HaveOccurred())
171+
By("waiting for the shovel to be created in RabbitMQ")
172+
Eventually(func() error {
173+
_, err := rabbitClient.GetShovel("/", shovelWithRetain.Spec.Name)
174+
return err
175+
}, 30, 2).ShouldNot(HaveOccurred())
175176

176-
By("deleting the k8s resource")
177-
Expect(k8sClient.Delete(ctx, shovelWithRetain)).To(Succeed())
177+
By("deleting the k8s resource")
178+
Expect(k8sClient.Delete(ctx, shovelWithRetain)).To(Succeed())
178179

179-
By("verifying k8s resource is gone")
180-
Eventually(func() bool {
181-
err := k8sClient.Get(ctx, types.NamespacedName{Name: shovelWithRetain.Name, Namespace: shovelWithRetain.Namespace}, &topology.Shovel{})
182-
return apierrors.IsNotFound(err)
183-
}, 30, 2).Should(BeTrue())
180+
By("verifying k8s resource is gone")
181+
Eventually(func() bool {
182+
err := k8sClient.Get(ctx, types.NamespacedName{Name: shovelWithRetain.Name, Namespace: shovelWithRetain.Namespace}, &topology.Shovel{})
183+
return apierrors.IsNotFound(err)
184+
}, 30, 2).Should(BeTrue())
184185

185-
By("verifying shovel still exists in RabbitMQ")
186-
_, err := rabbitClient.GetShovel("/", shovelWithRetain.Spec.Name)
187-
Expect(err).NotTo(HaveOccurred())
186+
By("verifying shovel still exists in RabbitMQ")
187+
_, err := rabbitClient.GetShovel("/", shovelWithRetain.Spec.Name)
188+
Expect(err).NotTo(HaveOccurred())
189+
})
188190
})
189191
})
190192

system_tests/vhost_system_test.go

+32-30
Original file line numberDiff line numberDiff line change
@@ -100,41 +100,43 @@ var _ = Describe("vhost", func() {
100100
Expect(err.Error()).To(ContainSubstring("Object Not Found"))
101101
})
102102

103-
It("with DeletionPolicy=retain, deletes k8s resource but keeps the vhost in RabbitMQ", func() {
104-
vhostWithRetain := &topology.Vhost{
105-
ObjectMeta: metav1.ObjectMeta{
106-
Name: "retain-policy-test",
107-
Namespace: namespace,
108-
},
109-
Spec: topology.VhostSpec{
110-
Name: "retain-policy-test",
111-
DeletionPolicy: "retain",
112-
RabbitmqClusterReference: topology.RabbitmqClusterReference{
113-
Name: rmq.Name,
103+
When("deletion policy is retain", func() {
104+
It("deletes k8s resource but keeps the vhost in RabbitMQ", func() {
105+
vhostWithRetain := &topology.Vhost{
106+
ObjectMeta: metav1.ObjectMeta{
107+
Name: "retain-policy-test",
108+
Namespace: namespace,
114109
},
115-
},
116-
}
110+
Spec: topology.VhostSpec{
111+
Name: "retain-policy-test",
112+
DeletionPolicy: "retain",
113+
RabbitmqClusterReference: topology.RabbitmqClusterReference{
114+
Name: rmq.Name,
115+
},
116+
},
117+
}
117118

118-
By("creating a vhost with retain policy")
119-
Expect(k8sClient.Create(ctx, vhostWithRetain, &client.CreateOptions{})).To(Succeed())
119+
By("creating a vhost with retain policy")
120+
Expect(k8sClient.Create(ctx, vhostWithRetain, &client.CreateOptions{})).To(Succeed())
120121

121-
By("waiting for the vhost to be created in RabbitMQ")
122-
Eventually(func() error {
123-
_, err := rabbitClient.GetVhost(vhostWithRetain.Spec.Name)
124-
return err
125-
}, 30, 2).ShouldNot(HaveOccurred())
122+
By("waiting for the vhost to be created in RabbitMQ")
123+
Eventually(func() error {
124+
_, err := rabbitClient.GetVhost(vhostWithRetain.Spec.Name)
125+
return err
126+
}, 30, 2).ShouldNot(HaveOccurred())
126127

127-
By("deleting the k8s resource")
128-
Expect(k8sClient.Delete(ctx, vhostWithRetain)).To(Succeed())
128+
By("deleting the k8s resource")
129+
Expect(k8sClient.Delete(ctx, vhostWithRetain)).To(Succeed())
129130

130-
By("verifying k8s resource is gone")
131-
Eventually(func() bool {
132-
err := k8sClient.Get(ctx, types.NamespacedName{Name: vhostWithRetain.Name, Namespace: vhostWithRetain.Namespace}, &topology.Vhost{})
133-
return apierrors.IsNotFound(err)
134-
}, 30, 2).Should(BeTrue())
131+
By("verifying k8s resource is gone")
132+
Eventually(func() bool {
133+
err := k8sClient.Get(ctx, types.NamespacedName{Name: vhostWithRetain.Name, Namespace: vhostWithRetain.Namespace}, &topology.Vhost{})
134+
return apierrors.IsNotFound(err)
135+
}, 30, 2).Should(BeTrue())
135136

136-
By("verifying vhost still exists in RabbitMQ")
137-
_, err := rabbitClient.GetVhost(vhostWithRetain.Spec.Name)
138-
Expect(err).NotTo(HaveOccurred())
137+
By("verifying vhost still exists in RabbitMQ")
138+
_, err := rabbitClient.GetVhost(vhostWithRetain.Spec.Name)
139+
Expect(err).NotTo(HaveOccurred())
140+
})
139141
})
140142
})

0 commit comments

Comments
 (0)