Skip to content

Commit abc5737

Browse files
committed
Delete duplicated test specs from integration
- this commit removes 35 specs from integration tests - delete successful create and delete test cases that verify status conditions are covered in system tests already - delete namespace permission checks which are done in rabbitmqclient package 'ParseReference'; it's not necessary to check namespace permission for every single controller - asserts correct finalizer in system tests for CRs since they are removed from integration tests - adds the same set of tests about namespace permission to rabbitmqclient packge, where 'ParceReference' func lives
1 parent a763056 commit abc5737

25 files changed

+172
-2053
lines changed

controllers/binding_controller_test.go

Lines changed: 0 additions & 165 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"errors"
66
"io/ioutil"
77
"net/http"
8-
"sigs.k8s.io/controller-runtime/pkg/envtest/komega"
98
"time"
109

1110
. "github.com/onsi/ginkgo/v2"
@@ -89,37 +88,6 @@ var _ = Describe("bindingController", func() {
8988
})))
9089
})
9190
})
92-
93-
Context("success", func() {
94-
BeforeEach(func() {
95-
bindingName = "test-binding-success"
96-
fakeRabbitMQClient.DeclareBindingReturns(&http.Response{
97-
Status: "201 Created",
98-
StatusCode: http.StatusCreated,
99-
}, nil)
100-
})
101-
102-
It("works", func() {
103-
Expect(client.Create(ctx, &binding)).To(Succeed())
104-
By("setting the correct finalizer")
105-
Eventually(komega.Object(&binding)).WithTimeout(2 * time.Second).Should(HaveField("ObjectMeta.Finalizers", ConsistOf("deletion.finalizers.bindings.rabbitmq.com")))
106-
107-
By("sets the status condition 'Ready' to 'true'")
108-
EventuallyWithOffset(1, func() []topology.Condition {
109-
_ = client.Get(
110-
ctx,
111-
types.NamespacedName{Name: binding.Name, Namespace: binding.Namespace},
112-
&binding,
113-
)
114-
115-
return binding.Status.Conditions
116-
}, statusEventsUpdateTimeout, 1*time.Second).Should(ContainElement(MatchFields(IgnoreExtras, Fields{
117-
"Type": Equal(topology.ConditionType("Ready")),
118-
"Reason": Equal("SuccessfulCreateOrUpdate"),
119-
"Status": Equal(corev1.ConditionTrue),
120-
})))
121-
})
122-
})
12391
})
12492

12593
When("Deleting a binding", func() {
@@ -179,138 +147,5 @@ var _ = Describe("bindingController", func() {
179147
Expect(observedEvents()).To(ContainElement("Warning FailedDelete failed to delete binding"))
180148
})
181149
})
182-
183-
When("the RabbitMQ Client successfully deletes a binding", func() {
184-
BeforeEach(func() {
185-
bindingName = "delete-binding-success"
186-
fakeRabbitMQClient.DeleteBindingReturns(&http.Response{
187-
Status: "204 No Content",
188-
StatusCode: http.StatusNoContent,
189-
}, nil)
190-
})
191-
192-
It("raises an event to indicate a successful deletion", func() {
193-
Expect(client.Delete(ctx, &binding)).To(Succeed())
194-
Eventually(func() bool {
195-
err := client.Get(ctx, types.NamespacedName{Name: binding.Name, Namespace: binding.Namespace}, &topology.Binding{})
196-
return apierrors.IsNotFound(err)
197-
}, 5).Should(BeTrue())
198-
Expect(observedEvents()).To(SatisfyAll(
199-
Not(ContainElement("Warning FailedDelete failed to delete binding")),
200-
ContainElement("Normal SuccessfulDelete successfully deleted binding"),
201-
))
202-
})
203-
})
204-
})
205-
206-
When("a binding references a cluster from a prohibited namespace", func() {
207-
JustBeforeEach(func() {
208-
bindingName = "test-binding-prohibited"
209-
binding = topology.Binding{
210-
ObjectMeta: metav1.ObjectMeta{
211-
Name: bindingName,
212-
Namespace: "prohibited",
213-
},
214-
Spec: topology.BindingSpec{
215-
RabbitmqClusterReference: topology.RabbitmqClusterReference{
216-
Name: "example-rabbit",
217-
Namespace: "default",
218-
},
219-
},
220-
}
221-
})
222-
It("should throw an error about a cluster being prohibited", func() {
223-
Expect(client.Create(ctx, &binding)).To(Succeed())
224-
EventuallyWithOffset(1, func() []topology.Condition {
225-
_ = client.Get(
226-
ctx,
227-
types.NamespacedName{Name: binding.Name, Namespace: binding.Namespace},
228-
&binding,
229-
)
230-
231-
return binding.Status.Conditions
232-
}, statusEventsUpdateTimeout, 1*time.Second).Should(ContainElement(MatchFields(IgnoreExtras, Fields{
233-
"Type": Equal(topology.ConditionType("Ready")),
234-
"Reason": Equal("FailedCreateOrUpdate"),
235-
"Status": Equal(corev1.ConditionFalse),
236-
"Message": ContainSubstring("not allowed to reference"),
237-
})))
238-
})
239-
})
240-
241-
When("a binding references a cluster from an allowed namespace", func() {
242-
JustBeforeEach(func() {
243-
bindingName = "test-binding-allowed"
244-
binding = topology.Binding{
245-
ObjectMeta: metav1.ObjectMeta{
246-
Name: bindingName,
247-
Namespace: "allowed",
248-
},
249-
Spec: topology.BindingSpec{
250-
RabbitmqClusterReference: topology.RabbitmqClusterReference{
251-
Name: "example-rabbit",
252-
Namespace: "default",
253-
},
254-
},
255-
}
256-
fakeRabbitMQClient.DeclareBindingReturns(&http.Response{
257-
Status: "201 Created",
258-
StatusCode: http.StatusCreated,
259-
}, nil)
260-
})
261-
It("should be created", func() {
262-
Expect(client.Create(ctx, &binding)).To(Succeed())
263-
EventuallyWithOffset(1, func() []topology.Condition {
264-
_ = client.Get(
265-
ctx,
266-
types.NamespacedName{Name: binding.Name, Namespace: binding.Namespace},
267-
&binding,
268-
)
269-
270-
return binding.Status.Conditions
271-
}, statusEventsUpdateTimeout, 1*time.Second).Should(ContainElement(MatchFields(IgnoreExtras, Fields{
272-
"Type": Equal(topology.ConditionType("Ready")),
273-
"Reason": Equal("SuccessfulCreateOrUpdate"),
274-
"Status": Equal(corev1.ConditionTrue),
275-
})))
276-
})
277-
})
278-
279-
When("a binding references a cluster that allows all namespaces", func() {
280-
JustBeforeEach(func() {
281-
bindingName = "test-binding-allowed-when-allow-all"
282-
binding = topology.Binding{
283-
ObjectMeta: metav1.ObjectMeta{
284-
Name: bindingName,
285-
Namespace: "prohibited",
286-
},
287-
Spec: topology.BindingSpec{
288-
RabbitmqClusterReference: topology.RabbitmqClusterReference{
289-
Name: "allow-all-rabbit",
290-
Namespace: "default",
291-
},
292-
},
293-
}
294-
fakeRabbitMQClient.DeclareBindingReturns(&http.Response{
295-
Status: "201 Created",
296-
StatusCode: http.StatusCreated,
297-
}, nil)
298-
})
299-
It("should be created", func() {
300-
Expect(client.Create(ctx, &binding)).To(Succeed())
301-
EventuallyWithOffset(1, func() []topology.Condition {
302-
_ = client.Get(
303-
ctx,
304-
types.NamespacedName{Name: binding.Name, Namespace: binding.Namespace},
305-
&binding,
306-
)
307-
308-
return binding.Status.Conditions
309-
}, statusEventsUpdateTimeout, 1*time.Second).Should(ContainElement(MatchFields(IgnoreExtras, Fields{
310-
"Type": Equal(topology.ConditionType("Ready")),
311-
"Reason": Equal("SuccessfulCreateOrUpdate"),
312-
"Status": Equal(corev1.ConditionTrue),
313-
})))
314-
})
315150
})
316151
})

controllers/exchange_controller_test.go

Lines changed: 0 additions & 165 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"errors"
66
"io/ioutil"
77
"net/http"
8-
"sigs.k8s.io/controller-runtime/pkg/envtest/komega"
98
"time"
109

1110
. "github.com/onsi/ginkgo/v2"
@@ -89,37 +88,6 @@ var _ = Describe("exchange-controller", func() {
8988
})))
9089
})
9190
})
92-
93-
When("success", func() {
94-
BeforeEach(func() {
95-
exchangeName = "test-create-success"
96-
fakeRabbitMQClient.DeclareExchangeReturns(&http.Response{
97-
Status: "201 Created",
98-
StatusCode: http.StatusCreated,
99-
}, nil)
100-
})
101-
102-
It("works", func() {
103-
Expect(client.Create(ctx, &exchange)).To(Succeed())
104-
By("setting the correct finalizer")
105-
Eventually(komega.Object(&exchange)).WithTimeout(2 * time.Second).Should(HaveField("ObjectMeta.Finalizers", ConsistOf("deletion.finalizers.exchanges.rabbitmq.com")))
106-
107-
By("sets the status condition 'Ready' to 'true'")
108-
EventuallyWithOffset(1, func() []topology.Condition {
109-
_ = client.Get(
110-
ctx,
111-
types.NamespacedName{Name: exchange.Name, Namespace: exchange.Namespace},
112-
&exchange,
113-
)
114-
115-
return exchange.Status.Conditions
116-
}, statusEventsUpdateTimeout, 1*time.Second).Should(ContainElement(MatchFields(IgnoreExtras, Fields{
117-
"Type": Equal(topology.ConditionType("Ready")),
118-
"Reason": Equal("SuccessfulCreateOrUpdate"),
119-
"Status": Equal(corev1.ConditionTrue),
120-
})))
121-
})
122-
})
12391
})
12492
Context("LastTransitionTime", func() {
12593
BeforeEach(func() {
@@ -247,138 +215,5 @@ var _ = Describe("exchange-controller", func() {
247215
Expect(observedEvents()).To(ContainElement("Warning FailedDelete failed to delete exchange"))
248216
})
249217
})
250-
251-
When("the RabbitMQ Client successfully deletes a exchange", func() {
252-
BeforeEach(func() {
253-
exchangeName = "delete-exchange-success"
254-
fakeRabbitMQClient.DeleteExchangeReturns(&http.Response{
255-
Status: "204 No Content",
256-
StatusCode: http.StatusNoContent,
257-
}, nil)
258-
})
259-
260-
It("publishes a normal event", func() {
261-
Expect(client.Delete(ctx, &exchange)).To(Succeed())
262-
Eventually(func() bool {
263-
err := client.Get(ctx, types.NamespacedName{Name: exchange.Name, Namespace: exchange.Namespace}, &topology.Exchange{})
264-
return apierrors.IsNotFound(err)
265-
}, statusEventsUpdateTimeout).Should(BeTrue())
266-
Expect(observedEvents()).To(SatisfyAll(
267-
Not(ContainElement("Warning FailedDelete failed to delete exchange")),
268-
ContainElement("Normal SuccessfulDelete successfully deleted exchange"),
269-
))
270-
})
271-
})
272-
})
273-
274-
When("an exchange references a cluster from a prohibited namespace", func() {
275-
JustBeforeEach(func() {
276-
exchangeName = "test-exchange-prohibited"
277-
exchange = topology.Exchange{
278-
ObjectMeta: metav1.ObjectMeta{
279-
Name: exchangeName,
280-
Namespace: "prohibited",
281-
},
282-
Spec: topology.ExchangeSpec{
283-
RabbitmqClusterReference: topology.RabbitmqClusterReference{
284-
Name: "example-rabbit",
285-
Namespace: "default",
286-
},
287-
},
288-
}
289-
})
290-
It("should throw an error about a cluster being prohibited", func() {
291-
Expect(client.Create(ctx, &exchange)).To(Succeed())
292-
EventuallyWithOffset(1, func() []topology.Condition {
293-
_ = client.Get(
294-
ctx,
295-
types.NamespacedName{Name: exchange.Name, Namespace: exchange.Namespace},
296-
&exchange,
297-
)
298-
299-
return exchange.Status.Conditions
300-
}, statusEventsUpdateTimeout, 1*time.Second).Should(ContainElement(MatchFields(IgnoreExtras, Fields{
301-
"Type": Equal(topology.ConditionType("Ready")),
302-
"Reason": Equal("FailedCreateOrUpdate"),
303-
"Status": Equal(corev1.ConditionFalse),
304-
"Message": ContainSubstring("not allowed to reference"),
305-
})))
306-
})
307-
})
308-
309-
When("an exchange references a cluster from an allowed namespace", func() {
310-
JustBeforeEach(func() {
311-
exchangeName = "test-exchange-allowed"
312-
exchange = topology.Exchange{
313-
ObjectMeta: metav1.ObjectMeta{
314-
Name: exchangeName,
315-
Namespace: "allowed",
316-
},
317-
Spec: topology.ExchangeSpec{
318-
RabbitmqClusterReference: topology.RabbitmqClusterReference{
319-
Name: "example-rabbit",
320-
Namespace: "default",
321-
},
322-
},
323-
}
324-
fakeRabbitMQClient.DeclareExchangeReturns(&http.Response{
325-
Status: "201 Created",
326-
StatusCode: http.StatusCreated,
327-
}, nil)
328-
})
329-
It("should be created", func() {
330-
Expect(client.Create(ctx, &exchange)).To(Succeed())
331-
EventuallyWithOffset(1, func() []topology.Condition {
332-
_ = client.Get(
333-
ctx,
334-
types.NamespacedName{Name: exchange.Name, Namespace: exchange.Namespace},
335-
&exchange,
336-
)
337-
338-
return exchange.Status.Conditions
339-
}, statusEventsUpdateTimeout, 1*time.Second).Should(ContainElement(MatchFields(IgnoreExtras, Fields{
340-
"Type": Equal(topology.ConditionType("Ready")),
341-
"Reason": Equal("SuccessfulCreateOrUpdate"),
342-
"Status": Equal(corev1.ConditionTrue),
343-
})))
344-
})
345-
})
346-
347-
When("an exchange references a cluster that allows all namespaces", func() {
348-
JustBeforeEach(func() {
349-
exchangeName = "test-exchange-allowed-when-allow-all"
350-
exchange = topology.Exchange{
351-
ObjectMeta: metav1.ObjectMeta{
352-
Name: exchangeName,
353-
Namespace: "prohibited",
354-
},
355-
Spec: topology.ExchangeSpec{
356-
RabbitmqClusterReference: topology.RabbitmqClusterReference{
357-
Name: "allow-all-rabbit",
358-
Namespace: "default",
359-
},
360-
},
361-
}
362-
fakeRabbitMQClient.DeclareExchangeReturns(&http.Response{
363-
Status: "201 Created",
364-
StatusCode: http.StatusCreated,
365-
}, nil)
366-
})
367-
It("should be created", func() {
368-
Expect(client.Create(ctx, &exchange)).To(Succeed())
369-
EventuallyWithOffset(1, func() []topology.Condition {
370-
_ = client.Get(
371-
ctx,
372-
types.NamespacedName{Name: exchange.Name, Namespace: exchange.Namespace},
373-
&exchange,
374-
)
375-
376-
return exchange.Status.Conditions
377-
}, statusEventsUpdateTimeout, 1*time.Second).Should(ContainElement(MatchFields(IgnoreExtras, Fields{
378-
"Type": Equal(topology.ConditionType("Ready")),
379-
"Reason": Equal("SuccessfulCreateOrUpdate"),
380-
"Status": Equal(corev1.ConditionTrue),
381-
})))
382-
})
383218
})
384219
})

0 commit comments

Comments
 (0)