@@ -302,15 +302,15 @@ var _ = Describe("AggregatesController", func() {
302302 Expect (cond .Message ).To (ContainSubstring (expectedMessage ))
303303 }
304304
305- Context ("when GetAggregates fails" , func () {
305+ Context ("when ApplyAggregates fails" , func () {
306306 BeforeEach (func (ctx SpecContext ) {
307307 By ("Setting a missing aggregate" )
308308 hypervisor := & kvmv1.Hypervisor {}
309309 Expect (k8sClient .Get (ctx , hypervisorName , hypervisor )).To (Succeed ())
310310 hypervisor .Spec .Aggregates = []string {"test-aggregate1" }
311311 Expect (k8sClient .Update (ctx , hypervisor )).To (Succeed ())
312312
313- By ("Mocking GetAggregates to fail" )
313+ By ("Mocking GET /os-aggregates to fail (first API call in ApplyAggregates) " )
314314 fakeServer .Mux .HandleFunc ("GET /os-aggregates" , func (w http.ResponseWriter , r * http.Request ) {
315315 w .Header ().Add ("Content-Type" , "application/json" )
316316 w .WriteHeader (http .StatusInternalServerError )
@@ -322,79 +322,7 @@ var _ = Describe("AggregatesController", func() {
322322 It ("should set error condition" , func (ctx SpecContext ) {
323323 _ , err := aggregatesController .Reconcile (ctx , reconcileRequest )
324324 Expect (err ).To (HaveOccurred ())
325- sharedErrorConditionChecks (ctx , "failed listing aggregates" )
326- })
327- })
328-
329- Context ("when AddToAggregate fails" , func () {
330- BeforeEach (func (ctx SpecContext ) {
331- By ("Setting a missing aggregate" )
332- hypervisor := & kvmv1.Hypervisor {}
333- Expect (k8sClient .Get (ctx , hypervisorName , hypervisor )).To (Succeed ())
334- hypervisor .Spec .Aggregates = []string {"test-aggregate1" }
335- Expect (k8sClient .Update (ctx , hypervisor )).To (Succeed ())
336-
337- By ("Mocking GetAggregates" )
338- fakeServer .Mux .HandleFunc ("GET /os-aggregates" , func (w http.ResponseWriter , r * http.Request ) {
339- w .Header ().Add ("Content-Type" , "application/json" )
340- w .WriteHeader (http .StatusOK )
341- _ , err := fmt .Fprint (w , AggregateListBodyEmpty )
342- Expect (err ).NotTo (HaveOccurred ())
343- })
344-
345- By ("Mocking CreateAggregate" )
346- fakeServer .Mux .HandleFunc ("POST /os-aggregates" , func (w http.ResponseWriter , r * http.Request ) {
347- w .Header ().Add ("Content-Type" , "application/json" )
348- w .WriteHeader (http .StatusOK )
349- _ , err := fmt .Fprint (w , AggregatesPostBody )
350- Expect (err ).NotTo (HaveOccurred ())
351- })
352-
353- By ("Mocking AddHost to fail" )
354- fakeServer .Mux .HandleFunc ("POST /os-aggregates/42/action" , func (w http.ResponseWriter , r * http.Request ) {
355- w .Header ().Add ("Content-Type" , "application/json" )
356- w .WriteHeader (http .StatusConflict )
357- _ , err := fmt .Fprint (w , `{"conflictingRequest": {"message": "Cannot add host to aggregate", "code": 409}}` )
358- Expect (err ).NotTo (HaveOccurred ())
359- })
360- })
361-
362- It ("should set error condition" , func (ctx SpecContext ) {
363- _ , err := aggregatesController .Reconcile (ctx , reconcileRequest )
364- Expect (err ).To (HaveOccurred ())
365- sharedErrorConditionChecks (ctx , "encountered errors during aggregate update" )
366- })
367- })
368-
369- Context ("when RemoveFromAggregate fails" , func () {
370- BeforeEach (func (ctx SpecContext ) {
371- By ("Setting existing aggregate in status" )
372- hypervisor := & kvmv1.Hypervisor {}
373- Expect (k8sClient .Get (ctx , hypervisorName , hypervisor )).To (Succeed ())
374- hypervisor .Status .Aggregates = []string {"test-aggregate2" }
375- Expect (k8sClient .Status ().Update (ctx , hypervisor )).To (Succeed ())
376-
377- By ("Mocking GetAggregates" )
378- fakeServer .Mux .HandleFunc ("GET /os-aggregates" , func (w http.ResponseWriter , r * http.Request ) {
379- w .Header ().Add ("Content-Type" , "application/json" )
380- w .WriteHeader (http .StatusOK )
381- _ , err := fmt .Fprint (w , AggregateListBodyFull )
382- Expect (err ).NotTo (HaveOccurred ())
383- })
384-
385- By ("Mocking RemoveHost to fail" )
386- fakeServer .Mux .HandleFunc ("POST /os-aggregates/100001/action" , func (w http.ResponseWriter , r * http.Request ) {
387- w .Header ().Add ("Content-Type" , "application/json" )
388- w .WriteHeader (http .StatusConflict )
389- _ , err := fmt .Fprint (w , `{"conflictingRequest": {"message": "Cannot remove host from aggregate", "code": 409}}` )
390- Expect (err ).NotTo (HaveOccurred ())
391- })
392- })
393-
394- It ("should set error condition" , func (ctx SpecContext ) {
395- _ , err := aggregatesController .Reconcile (ctx , reconcileRequest )
396- Expect (err ).To (HaveOccurred ())
397- sharedErrorConditionChecks (ctx , "encountered errors during aggregate update" )
325+ sharedErrorConditionChecks (ctx , "failed to get aggregates" )
398326 })
399327 })
400328
0 commit comments