Skip to content

Commit 1ca6565

Browse files
committed
Add cleanup to creation tests to avoid race conditions and test interference.
1 parent 8108c00 commit 1ca6565

13 files changed

+176
-98
lines changed

controllers/binding_controller_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ var _ = Describe("bindingController", func() {
9595
})
9696

9797
When("creating a binding", func() {
98+
AfterEach(func() {
99+
Expect(k8sClient.Delete(ctx, &binding)).To(Succeed())
100+
})
101+
98102
When("the RabbitMQ Client returns a HTTP error response", func() {
99103
BeforeEach(func() {
100104
bindingName = "test-binding-http-error"

controllers/exchange_controller_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ var _ = Describe("exchange-controller", func() {
9797
})
9898

9999
Context("creation", func() {
100+
AfterEach(func() {
101+
Expect(k8sClient.Delete(ctx, &exchange)).To(Succeed())
102+
})
103+
100104
When("the RabbitMQ Client returns a HTTP error response", func() {
101105
BeforeEach(func() {
102106
exchangeName = "test-http-error"
@@ -150,6 +154,7 @@ var _ = Describe("exchange-controller", func() {
150154
})
151155
})
152156
})
157+
153158
Context("LastTransitionTime", func() {
154159
BeforeEach(func() {
155160
exchangeName = "test-last-transition-time"
@@ -158,6 +163,11 @@ var _ = Describe("exchange-controller", func() {
158163
StatusCode: http.StatusCreated,
159164
}, nil)
160165
})
166+
167+
AfterEach(func() {
168+
Expect(k8sClient.Delete(ctx, &exchange)).To(Succeed())
169+
})
170+
161171
It("changes only if status changes", func() {
162172
By("setting LastTransitionTime when transitioning to status Ready=true")
163173
Expect(k8sClient.Create(ctx, &exchange)).To(Succeed())

controllers/federation_controller_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ var _ = Describe("federation-controller", func() {
9898
})
9999

100100
When("creation", func() {
101+
AfterEach(func() {
102+
Expect(k8sClient.Delete(ctx, &federation)).To(Succeed())
103+
})
104+
101105
When("the RabbitMQ Client returns a HTTP error response", func() {
102106
BeforeEach(func() {
103107
federationName = "test-federation-http-error"

controllers/operatorpolicy_controller_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ var _ = Describe("operatorpolicy-controller", func() {
101101
})
102102

103103
Context("creation", func() {
104+
AfterEach(func() {
105+
Expect(k8sClient.Delete(ctx, &policy)).To(Succeed())
106+
})
107+
104108
When("the RabbitMQ Client returns a HTTP error response", func() {
105109
BeforeEach(func() {
106110
policyName = "test-http-error"

controllers/permission_controller_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ var _ = Describe("permission-controller", func() {
101101
})
102102

103103
Context("creation", func() {
104+
AfterEach(func() {
105+
Expect(k8sClient.Delete(ctx, &permission)).To(Succeed())
106+
})
107+
104108
When("the RabbitMQ Client returns a HTTP error response", func() {
105109
BeforeEach(func() {
106110
permissionName = "test-with-username-http-error"
@@ -272,6 +276,10 @@ var _ = Describe("permission-controller", func() {
272276
})
273277

274278
Context("creation", func() {
279+
AfterEach(func() {
280+
Expect(k8sClient.Delete(ctx, &permission)).To(Succeed())
281+
})
282+
275283
When("user not exist", func() {
276284
BeforeEach(func() {
277285
permissionName = "test-with-userref-create-not-exist"
@@ -415,12 +423,16 @@ var _ = Describe("permission-controller", func() {
415423
})
416424
})
417425

418-
Context("ownerref", func() {
426+
When("the user already exists", func() {
419427
BeforeEach(func() {
420428
permissionName = "ownerref-with-userref-test"
421429
userName = "example-ownerref"
422430
})
423431

432+
AfterEach(func() {
433+
Expect(k8sClient.Delete(ctx, &user)).To(Succeed())
434+
})
435+
424436
It("sets the correct deletion ownerref to the object", func() {
425437
Expect(k8sClient.Create(ctx, &user)).To(Succeed())
426438
user.Status.Username = userName

controllers/policy_controller_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ var _ = Describe("policy-controller", func() {
100100
})
101101

102102
Context("creation", func() {
103+
AfterEach(func() {
104+
Expect(k8sClient.Delete(ctx, &policy)).To(Succeed())
105+
})
106+
103107
When("the RabbitMQ Client returns a HTTP error response", func() {
104108
BeforeEach(func() {
105109
policyName = "test-http-error"

controllers/queue_controller_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ var _ = Describe("queue-controller", func() {
9696
})
9797

9898
Context("creation", func() {
99+
AfterEach(func() {
100+
Expect(k8sClient.Delete(ctx, &queue)).To(Succeed())
101+
})
102+
99103
When("the RabbitMQ Client returns a HTTP error response", func() {
100104
BeforeEach(func() {
101105
queueName = "test-http-error"

controllers/schemareplication_controller_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ var _ = Describe("schema-replication-controller", func() {
103103
})
104104

105105
When("creation", func() {
106+
AfterEach(func() {
107+
Expect(k8sClient.Delete(ctx, &replication)).To(Succeed())
108+
})
109+
106110
When("the RabbitMQ Client returns a HTTP error response", func() {
107111
BeforeEach(func() {
108112
replicationName = "test-replication-http-error"
@@ -257,6 +261,7 @@ var _ = Describe("schema-replication-controller", func() {
257261
})
258262

259263
AfterEach(func() {
264+
Expect(k8sClient.Delete(ctx, &replication)).To(Succeed())
260265
rabbitmqclient.SecretStoreClientProvider = rabbitmqclient.GetSecretStoreClient
261266
})
262267

controllers/shovel_controller_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ var _ = Describe("shovel-controller", func() {
100100
})
101101

102102
When("creation", func() {
103+
AfterEach(func() {
104+
Expect(k8sClient.Delete(ctx, &shovel)).To(Succeed())
105+
})
106+
103107
When("the RabbitMQ Client returns a HTTP error response", func() {
104108
BeforeEach(func() {
105109
shovelName = "test-shovel-http-error"

controllers/super_stream_controller_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ var _ = Describe("super-stream-controller", func() {
124124
})
125125

126126
Context("creation", func() {
127+
AfterEach(func() {
128+
Expect(k8sClient.Delete(ctx, &superStream)).To(Succeed())
129+
})
130+
127131
When("an underlying resource is deleted", func() {
128132
JustBeforeEach(func() {
129133
Expect(k8sClient.Create(ctx, &superStream)).To(Succeed())

0 commit comments

Comments
 (0)