@@ -36,7 +36,7 @@ import (
36
36
. "github.com/onsi/gomega"
37
37
)
38
38
39
- func setupClusterScope (clusterName string ) * ClusterScope {
39
+ func setupClusterScope (clusterName string , mockvpc * mock. MockVpc ) * ClusterScope {
40
40
cluster := newCluster (clusterName )
41
41
vpcCluster := newVPCCluster (clusterName )
42
42
@@ -93,8 +93,8 @@ func TestNewClusterScope(t *testing.T) {
93
93
}
94
94
95
95
func TestCreateVPC (t * testing.T ) {
96
- mockctrl = gomock .NewController (GinkgoT ())
97
- mockvpc = mock .NewMockVpc (mockctrl )
96
+ mockctrl : = gomock .NewController (GinkgoT ())
97
+ mockvpc : = mock .NewMockVpc (mockctrl )
98
98
g := NewWithT (t )
99
99
100
100
vpcCluster := infrav1beta1.IBMVPCCluster {
@@ -111,7 +111,7 @@ func TestCreateVPC(t *testing.T) {
111
111
}}
112
112
113
113
t .Run ("Create VPC" , func (t * testing.T ) {
114
- scope := setupClusterScope (clusterName )
114
+ scope := setupClusterScope (clusterName , mockvpc )
115
115
listVpcsOptions := & vpcv1.ListVpcsOptions {}
116
116
createVPCOptions := & vpcv1.CreateVPCOptions {}
117
117
vpcCollection := & vpcv1.VPCCollection {
@@ -194,8 +194,8 @@ func TestCreateVPC(t *testing.T) {
194
194
}
195
195
196
196
func TestDeleteVPC (t * testing.T ) {
197
- mockctrl = gomock .NewController (GinkgoT ())
198
- mockvpc = mock .NewMockVpc (mockctrl )
197
+ mockctrl : = gomock .NewController (GinkgoT ())
198
+ mockvpc : = mock .NewMockVpc (mockctrl )
199
199
g := NewWithT (t )
200
200
201
201
vpcCluster := infrav1beta1.IBMVPCCluster {
@@ -209,7 +209,7 @@ func TestDeleteVPC(t *testing.T) {
209
209
}}
210
210
211
211
t .Run ("Delete VPC" , func (t * testing.T ) {
212
- scope := setupClusterScope (clusterName )
212
+ scope := setupClusterScope (clusterName , mockvpc )
213
213
scope .IBMVPCCluster .Spec = vpcCluster .Spec
214
214
scope .IBMVPCCluster .Status = vpcCluster .Status
215
215
deleteVpcOptions := & vpcv1.DeleteVPCOptions {}
@@ -230,8 +230,8 @@ func TestDeleteVPC(t *testing.T) {
230
230
}
231
231
232
232
func TestReserveFIP (t * testing.T ) {
233
- mockctrl = gomock .NewController (GinkgoT ())
234
- mockvpc = mock .NewMockVpc (mockctrl )
233
+ mockctrl : = gomock .NewController (GinkgoT ())
234
+ mockvpc : = mock .NewMockVpc (mockctrl )
235
235
g := NewWithT (t )
236
236
237
237
vpcCluster := infrav1beta1.IBMVPCCluster {
@@ -254,7 +254,7 @@ func TestReserveFIP(t *testing.T) {
254
254
floatingIPOptions := & vpcv1.CreateFloatingIPOptions {}
255
255
256
256
t .Run ("Should reserve FloatingIP" , func (t * testing.T ) {
257
- scope := setupClusterScope (clusterName )
257
+ scope := setupClusterScope (clusterName , mockvpc )
258
258
expectedOutput := & vpcv1.FloatingIP {
259
259
Name : core .StringPtr ("foo-cluster-control-plane" ),
260
260
}
@@ -269,7 +269,7 @@ func TestReserveFIP(t *testing.T) {
269
269
})
270
270
271
271
t .Run ("Return exsisting FloatingIP" , func (t * testing.T ) {
272
- scope := setupClusterScope ("foo-cluster-1" )
272
+ scope := setupClusterScope ("foo-cluster-1" , mockvpc )
273
273
expectedOutput := & vpcv1.FloatingIP {
274
274
Name : core .StringPtr ("foo-cluster-1-control-plane" ),
275
275
}
@@ -281,14 +281,14 @@ func TestReserveFIP(t *testing.T) {
281
281
})
282
282
283
283
t .Run ("Error when listing FloatingIPs" , func (t * testing.T ) {
284
- scope := setupClusterScope (clusterName )
284
+ scope := setupClusterScope (clusterName , mockvpc )
285
285
mockvpc .EXPECT ().ListFloatingIps (gomock .AssignableToTypeOf (listFloatingIpsOptions )).Return (floatingIPCollection , detailedResponse , errors .New ("Error when listing FloatingIPs" ))
286
286
_ , err := scope .ReserveFIP ()
287
287
g .Expect (err ).To (Not (BeNil ()))
288
288
})
289
289
290
290
t .Run ("Error when creating FloatingIP" , func (t * testing.T ) {
291
- scope := setupClusterScope (clusterName )
291
+ scope := setupClusterScope (clusterName , mockvpc )
292
292
scope .IBMVPCCluster .Spec = vpcCluster .Spec
293
293
mockvpc .EXPECT ().ListFloatingIps (gomock .AssignableToTypeOf (listFloatingIpsOptions )).Return (floatingIPCollection , detailedResponse , nil )
294
294
mockvpc .EXPECT ().CreateFloatingIP (gomock .AssignableToTypeOf (floatingIPOptions )).Return (nil , detailedResponse , errors .New ("Error when creating FloatingIP" ))
@@ -299,8 +299,8 @@ func TestReserveFIP(t *testing.T) {
299
299
}
300
300
301
301
func TestDeleteFloatingIP (t * testing.T ) {
302
- mockctrl = gomock .NewController (GinkgoT ())
303
- mockvpc = mock .NewMockVpc (mockctrl )
302
+ mockctrl : = gomock .NewController (GinkgoT ())
303
+ mockvpc : = mock .NewMockVpc (mockctrl )
304
304
g := NewWithT (t )
305
305
306
306
vpcCluster := infrav1beta1.IBMVPCCluster {
@@ -311,7 +311,7 @@ func TestDeleteFloatingIP(t *testing.T) {
311
311
}}
312
312
313
313
t .Run ("Delete FloatingIP" , func (t * testing.T ) {
314
- scope := setupClusterScope (clusterName )
314
+ scope := setupClusterScope (clusterName , mockvpc )
315
315
deleteFIPOption := & vpcv1.DeleteFloatingIPOptions {}
316
316
detailedResponse := & core.DetailedResponse {}
317
317
@@ -344,8 +344,8 @@ func TestDeleteFloatingIP(t *testing.T) {
344
344
}
345
345
346
346
func TestCreateSubnet (t * testing.T ) {
347
- mockctrl = gomock .NewController (GinkgoT ())
348
- mockvpc = mock .NewMockVpc (mockctrl )
347
+ mockctrl : = gomock .NewController (GinkgoT ())
348
+ mockvpc : = mock .NewMockVpc (mockctrl )
349
349
g := NewWithT (t )
350
350
vpcCluster := infrav1beta1.IBMVPCCluster {
351
351
Spec : infrav1beta1.IBMVPCClusterSpec {
@@ -389,7 +389,7 @@ func TestCreateSubnet(t *testing.T) {
389
389
subnetPublicGatewayOptions := & vpcv1.SetSubnetPublicGatewayOptions {}
390
390
391
391
t .Run ("Should create Subnet" , func (t * testing.T ) {
392
- scope := setupClusterScope (clusterName )
392
+ scope := setupClusterScope (clusterName , mockvpc )
393
393
expectedOutput := & vpcv1.Subnet {
394
394
Name : core .StringPtr ("foo-cluster-subnet" ),
395
395
ID : core .StringPtr ("foo-cluster-subnet-id" ),
@@ -412,7 +412,7 @@ func TestCreateSubnet(t *testing.T) {
412
412
})
413
413
414
414
t .Run ("Return exsisting Subnet" , func (t * testing.T ) {
415
- scope := setupClusterScope ("foo-cluster-1" )
415
+ scope := setupClusterScope ("foo-cluster-1" , mockvpc )
416
416
expectedOutput := & vpcv1.Subnet {
417
417
Name : core .StringPtr ("foo-cluster-1-subnet" ),
418
418
ID : core .StringPtr ("foo-cluster-1-subnet-id" ),
@@ -425,14 +425,14 @@ func TestCreateSubnet(t *testing.T) {
425
425
})
426
426
427
427
t .Run ("Error when listing Subnets" , func (t * testing.T ) {
428
- scope := setupClusterScope (clusterName )
428
+ scope := setupClusterScope (clusterName , mockvpc )
429
429
mockvpc .EXPECT ().ListSubnets (gomock .AssignableToTypeOf (listSubnetsOptions )).Return (subnetCollection , detailedResponse , errors .New ("Error when listing subnets" ))
430
430
_ , err := scope .CreateSubnet ()
431
431
g .Expect (err ).To (Not (BeNil ()))
432
432
})
433
433
434
434
t .Run ("Error when listing VPC AddressPerfixes" , func (t * testing.T ) {
435
- scope := setupClusterScope (clusterName )
435
+ scope := setupClusterScope (clusterName , mockvpc )
436
436
scope .IBMVPCCluster .Spec = vpcCluster .Spec
437
437
scope .IBMVPCCluster .Status = vpcCluster .Status
438
438
mockvpc .EXPECT ().ListSubnets (gomock .AssignableToTypeOf (listSubnetsOptions )).Return (subnetCollection , detailedResponse , nil )
@@ -442,7 +442,7 @@ func TestCreateSubnet(t *testing.T) {
442
442
})
443
443
444
444
t .Run ("Error not found a valid CIDR for VPC in zone" , func (t * testing.T ) {
445
- scope := setupClusterScope (clusterName )
445
+ scope := setupClusterScope (clusterName , mockvpc )
446
446
scope .IBMVPCCluster .Spec = vpcCluster .Spec
447
447
scope .IBMVPCCluster .Status = vpcCluster .Status
448
448
scope .IBMVPCCluster .Spec .Zone = "foo-zone-temp"
@@ -453,7 +453,7 @@ func TestCreateSubnet(t *testing.T) {
453
453
})
454
454
455
455
t .Run ("Error when creating PublicGateWay" , func (t * testing.T ) {
456
- scope := setupClusterScope (clusterName )
456
+ scope := setupClusterScope (clusterName , mockvpc )
457
457
scope .IBMVPCCluster .Spec = vpcCluster .Spec
458
458
scope .IBMVPCCluster .Status = vpcCluster .Status
459
459
subnet := & vpcv1.Subnet {}
@@ -466,7 +466,7 @@ func TestCreateSubnet(t *testing.T) {
466
466
})
467
467
468
468
t .Run ("Error when attaching PublicGateWay" , func (t * testing.T ) {
469
- scope := setupClusterScope (clusterName )
469
+ scope := setupClusterScope (clusterName , mockvpc )
470
470
scope .IBMVPCCluster .Spec = vpcCluster .Spec
471
471
scope .IBMVPCCluster .Status = vpcCluster .Status
472
472
subnet := & vpcv1.Subnet {
@@ -483,7 +483,7 @@ func TestCreateSubnet(t *testing.T) {
483
483
})
484
484
485
485
t .Run ("Error when creating Subnet" , func (t * testing.T ) {
486
- scope := setupClusterScope (clusterName )
486
+ scope := setupClusterScope (clusterName , mockvpc )
487
487
scope .IBMVPCCluster .Spec = vpcCluster .Spec
488
488
scope .IBMVPCCluster .Status = vpcCluster .Status
489
489
mockvpc .EXPECT ().ListSubnets (gomock .AssignableToTypeOf (listSubnetsOptions )).Return (subnetCollection , detailedResponse , nil )
@@ -496,8 +496,8 @@ func TestCreateSubnet(t *testing.T) {
496
496
}
497
497
498
498
func TestDeleteSubnet (t * testing.T ) {
499
- mockctrl = gomock .NewController (GinkgoT ())
500
- mockvpc = mock .NewMockVpc (mockctrl )
499
+ mockctrl : = gomock .NewController (GinkgoT ())
500
+ mockvpc : = mock .NewMockVpc (mockctrl )
501
501
g := NewWithT (t )
502
502
503
503
vpcCluster := infrav1beta1.IBMVPCCluster {Spec : infrav1beta1.IBMVPCClusterSpec {
@@ -509,7 +509,7 @@ func TestDeleteSubnet(t *testing.T) {
509
509
}}
510
510
511
511
t .Run ("Delete Subnet" , func (t * testing.T ) {
512
- scope := setupClusterScope (clusterName )
512
+ scope := setupClusterScope (clusterName , mockvpc )
513
513
scope .IBMVPCCluster .Spec = vpcCluster .Spec
514
514
scope .IBMVPCCluster .Status = vpcCluster .Status
515
515
getPGWOptions := & vpcv1.GetSubnetPublicGatewayOptions {}
0 commit comments