@@ -26,7 +26,7 @@ import (
2626 . "github.com/onsi/ginkgo/v2"
2727 . "github.com/onsi/gomega"
2828 "k8s.io/apimachinery/pkg/api/meta"
29- v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3030 "k8s.io/apimachinery/pkg/types"
3131 ctrl "sigs.k8s.io/controller-runtime"
3232
@@ -98,49 +98,53 @@ var _ = Describe("AggregatesController", func() {
9898 )
9999
100100 var (
101- tc * AggregatesController
102- fakeServer testhelper.FakeServer
103- hypervisorName = types.NamespacedName {Name : "hv-test" }
101+ aggregatesController * AggregatesController
102+ fakeServer testhelper.FakeServer
103+ hypervisorName = types.NamespacedName {Name : "hv-test" }
104104 )
105- // Setup and teardown
106105
107106 BeforeEach (func (ctx SpecContext ) {
108107 By ("Setting up the OpenStack http mock server" )
109108 fakeServer = testhelper .SetupHTTP ()
110109 DeferCleanup (fakeServer .Teardown )
111110
111+ // Install default handler to fail unhandled requests
112+ fakeServer .Mux .HandleFunc ("/" , func (w http.ResponseWriter , r * http.Request ) {
113+ Fail ("Unhandled request to fake server: " + r .Method + " " + r .URL .Path )
114+ })
115+
112116 hypervisor := & kvmv1.Hypervisor {
113- ObjectMeta : v1 .ObjectMeta {
117+ ObjectMeta : metav1 .ObjectMeta {
114118 Name : hypervisorName .Name ,
115119 },
116120 Spec : kvmv1.HypervisorSpec {
117121 LifecycleEnabled : true ,
118122 },
119123 }
120124 Expect (k8sClient .Create (ctx , hypervisor )).To (Succeed ())
125+ DeferCleanup (func (ctx SpecContext ) {
126+ Expect (k8sClient .Delete (ctx , hypervisor )).To (Succeed ())
127+ })
128+
121129 Expect (k8sClient .Get (ctx , hypervisorName , hypervisor )).To (Succeed ())
122- meta .SetStatusCondition (& hypervisor .Status .Conditions , v1 .Condition {
130+ meta .SetStatusCondition (& hypervisor .Status .Conditions , metav1 .Condition {
123131 Type : kvmv1 .ConditionTypeOnboarding ,
124- Status : v1 .ConditionFalse ,
132+ Status : metav1 .ConditionFalse ,
125133 Reason : "dontcare" ,
126134 Message : "dontcare" ,
127135 })
128136 Expect (k8sClient .Status ().Update (ctx , hypervisor )).To (Succeed ())
129137
130138 By ("Creating the AggregatesController" )
131- tc = & AggregatesController {
139+ aggregatesController = & AggregatesController {
132140 Client : k8sClient ,
133141 Scheme : k8sClient .Scheme (),
134142 computeClient : client .ServiceClient (fakeServer ),
135143 }
136-
137- DeferCleanup (func (ctx SpecContext ) {
138- Expect (tc .Client .Delete (ctx , hypervisor )).To (Succeed ())
139- })
140144 })
141145
142146 JustBeforeEach (func (ctx SpecContext ) {
143- _ , err := tc .Reconcile (ctx , ctrl.Request {NamespacedName : hypervisorName })
147+ _ , err := aggregatesController .Reconcile (ctx , ctrl.Request {NamespacedName : hypervisorName })
144148 Expect (err ).NotTo (HaveOccurred ())
145149 })
146150
@@ -190,7 +194,7 @@ var _ = Describe("AggregatesController", func() {
190194
191195 It ("should update Aggregates and set status condition as Aggregates differ" , func (ctx SpecContext ) {
192196 updated := & kvmv1.Hypervisor {}
193- Expect (tc .Client .Get (ctx , hypervisorName , updated )).To (Succeed ())
197+ Expect (aggregatesController .Client .Get (ctx , hypervisorName , updated )).To (Succeed ())
194198 Expect (updated .Status .Aggregates ).To (ContainElements ("test-aggregate1" ))
195199 Expect (meta .IsStatusConditionTrue (updated .Status .Conditions , kvmv1 .ConditionTypeAggregatesUpdated )).To (BeTrue ())
196200 })
@@ -234,7 +238,7 @@ var _ = Describe("AggregatesController", func() {
234238
235239 It ("should update Aggregates and set status condition when Aggregates differ" , func (ctx SpecContext ) {
236240 updated := & kvmv1.Hypervisor {}
237- Expect (tc .Client .Get (ctx , hypervisorName , updated )).To (Succeed ())
241+ Expect (aggregatesController .Client .Get (ctx , hypervisorName , updated )).To (Succeed ())
238242 Expect (updated .Status .Aggregates ).To (BeEmpty ())
239243 Expect (meta .IsStatusConditionTrue (updated .Status .Conditions , kvmv1 .ConditionTypeAggregatesUpdated )).To (BeTrue ())
240244 })
@@ -245,13 +249,13 @@ var _ = Describe("AggregatesController", func() {
245249 hypervisor := & kvmv1.Hypervisor {}
246250 Expect (k8sClient .Get (ctx , hypervisorName , hypervisor )).To (Succeed ())
247251 // Remove the onboarding condition
248- hypervisor .Status .Conditions = []v1 .Condition {}
252+ hypervisor .Status .Conditions = []metav1 .Condition {}
249253 Expect (k8sClient .Status ().Update (ctx , hypervisor )).To (Succeed ())
250254 })
251255
252256 It ("should neither update Aggregates and nor set status condition" , func (ctx SpecContext ) {
253257 updated := & kvmv1.Hypervisor {}
254- Expect (tc .Client .Get (ctx , hypervisorName , updated )).To (Succeed ())
258+ Expect (aggregatesController .Client .Get (ctx , hypervisorName , updated )).To (Succeed ())
255259 Expect (updated .Status .Aggregates ).To (BeEmpty ())
256260 Expect (meta .IsStatusConditionTrue (updated .Status .Conditions , kvmv1 .ConditionTypeAggregatesUpdated )).To (BeFalse ())
257261 })
@@ -262,9 +266,9 @@ var _ = Describe("AggregatesController", func() {
262266 hypervisor := & kvmv1.Hypervisor {}
263267 Expect (k8sClient .Get (ctx , hypervisorName , hypervisor )).To (Succeed ())
264268 // Remove the onboarding condition
265- meta .SetStatusCondition (& hypervisor .Status .Conditions , v1 .Condition {
269+ meta .SetStatusCondition (& hypervisor .Status .Conditions , metav1 .Condition {
266270 Type : kvmv1 .ConditionTypeTerminating ,
267- Status : v1 .ConditionTrue ,
271+ Status : metav1 .ConditionTrue ,
268272 Reason : "dontcare" ,
269273 Message : "dontcare" ,
270274 })
@@ -273,7 +277,7 @@ var _ = Describe("AggregatesController", func() {
273277
274278 It ("should neither update Aggregates and nor set status condition" , func (ctx SpecContext ) {
275279 updated := & kvmv1.Hypervisor {}
276- Expect (tc .Client .Get (ctx , hypervisorName , updated )).To (Succeed ())
280+ Expect (aggregatesController .Client .Get (ctx , hypervisorName , updated )).To (Succeed ())
277281 Expect (updated .Status .Aggregates ).To (BeEmpty ())
278282 Expect (meta .IsStatusConditionTrue (updated .Status .Conditions , kvmv1 .ConditionTypeAggregatesUpdated )).To (BeFalse ())
279283 })
0 commit comments