@@ -583,6 +583,11 @@ func TestDeleteSubnet(t *testing.T) {
583
583
publicGateway := & vpcv1.PublicGateway {
584
584
ID : core .StringPtr ("foo-public-gateway-id" ),
585
585
}
586
+ subnet := & vpcv1.SubnetCollection {
587
+ Subnets : []vpcv1.Subnet {
588
+ {ID : core .StringPtr ("foo-vpc-subnet-id" )},
589
+ },
590
+ }
586
591
587
592
t .Run ("Should delete subnet" , func (t * testing.T ) {
588
593
g := NewWithT (t )
@@ -591,6 +596,7 @@ func TestDeleteSubnet(t *testing.T) {
591
596
scope := setupClusterScope (clusterName , mockvpc )
592
597
scope .IBMVPCCluster .Spec = vpcCluster .Spec
593
598
scope .IBMVPCCluster .Status = vpcCluster .Status
599
+ mockvpc .EXPECT ().ListSubnets (gomock .AssignableToTypeOf (& vpcv1.ListSubnetsOptions {})).Return (subnet , & core.DetailedResponse {}, nil )
594
600
mockvpc .EXPECT ().GetSubnetPublicGateway (gomock .AssignableToTypeOf (& vpcv1.GetSubnetPublicGatewayOptions {})).Return (publicGateway , & core.DetailedResponse {}, nil )
595
601
mockvpc .EXPECT ().UnsetSubnetPublicGateway (gomock .AssignableToTypeOf (& vpcv1.UnsetSubnetPublicGatewayOptions {})).Return (& core.DetailedResponse {}, nil )
596
602
mockvpc .EXPECT ().DeletePublicGateway (gomock .AssignableToTypeOf (& vpcv1.DeletePublicGatewayOptions {})).Return (& core.DetailedResponse {}, nil )
@@ -606,6 +612,7 @@ func TestDeleteSubnet(t *testing.T) {
606
612
scope := setupClusterScope (clusterName , mockvpc )
607
613
scope .IBMVPCCluster .Spec = vpcCluster .Spec
608
614
scope .IBMVPCCluster .Status = vpcCluster .Status
615
+ mockvpc .EXPECT ().ListSubnets (gomock .AssignableToTypeOf (& vpcv1.ListSubnetsOptions {})).Return (subnet , & core.DetailedResponse {}, nil )
609
616
mockvpc .EXPECT ().GetSubnetPublicGateway (gomock .AssignableToTypeOf (& vpcv1.GetSubnetPublicGatewayOptions {})).Return (publicGateway , & core.DetailedResponse {}, nil )
610
617
mockvpc .EXPECT ().UnsetSubnetPublicGateway (gomock .AssignableToTypeOf (& vpcv1.UnsetSubnetPublicGatewayOptions {})).Return (& core.DetailedResponse {}, errors .New ("Error when unsetting publicgateway for subnet" ))
611
618
err := scope .DeleteSubnet ()
@@ -619,6 +626,7 @@ func TestDeleteSubnet(t *testing.T) {
619
626
scope := setupClusterScope (clusterName , mockvpc )
620
627
scope .IBMVPCCluster .Spec = vpcCluster .Spec
621
628
scope .IBMVPCCluster .Status = vpcCluster .Status
629
+ mockvpc .EXPECT ().ListSubnets (gomock .AssignableToTypeOf (& vpcv1.ListSubnetsOptions {})).Return (subnet , & core.DetailedResponse {}, nil )
622
630
mockvpc .EXPECT ().GetSubnetPublicGateway (gomock .AssignableToTypeOf (& vpcv1.GetSubnetPublicGatewayOptions {})).Return (publicGateway , & core.DetailedResponse {}, nil )
623
631
mockvpc .EXPECT ().UnsetSubnetPublicGateway (gomock .AssignableToTypeOf (& vpcv1.UnsetSubnetPublicGatewayOptions {})).Return (& core.DetailedResponse {}, nil )
624
632
mockvpc .EXPECT ().DeletePublicGateway (gomock .AssignableToTypeOf (& vpcv1.DeletePublicGatewayOptions {})).Return (& core.DetailedResponse {}, errors .New ("Error when deleting publicgateway for subnet" ))
@@ -633,13 +641,37 @@ func TestDeleteSubnet(t *testing.T) {
633
641
scope := setupClusterScope (clusterName , mockvpc )
634
642
scope .IBMVPCCluster .Spec = vpcCluster .Spec
635
643
scope .IBMVPCCluster .Status = vpcCluster .Status
644
+ mockvpc .EXPECT ().ListSubnets (gomock .AssignableToTypeOf (& vpcv1.ListSubnetsOptions {})).Return (subnet , & core.DetailedResponse {}, nil )
636
645
mockvpc .EXPECT ().GetSubnetPublicGateway (gomock .AssignableToTypeOf (& vpcv1.GetSubnetPublicGatewayOptions {})).Return (publicGateway , & core.DetailedResponse {}, nil )
637
646
mockvpc .EXPECT ().UnsetSubnetPublicGateway (gomock .AssignableToTypeOf (& vpcv1.UnsetSubnetPublicGatewayOptions {})).Return (& core.DetailedResponse {}, nil )
638
647
mockvpc .EXPECT ().DeletePublicGateway (gomock .AssignableToTypeOf (& vpcv1.DeletePublicGatewayOptions {})).Return (& core.DetailedResponse {}, nil )
639
648
mockvpc .EXPECT ().DeleteSubnet (gomock .AssignableToTypeOf (& vpcv1.DeleteSubnetOptions {})).Return (& core.DetailedResponse {}, errors .New ("Error when deleting subnet" ))
640
649
err := scope .DeleteSubnet ()
641
650
g .Expect (err ).To (Not (BeNil ()))
642
651
})
652
+
653
+ t .Run ("Error listing subnets" , func (t * testing.T ) {
654
+ g := NewWithT (t )
655
+ mockController , mockvpc := setup (t )
656
+ t .Cleanup (mockController .Finish )
657
+ scope := setupClusterScope (clusterName , mockvpc )
658
+ scope .IBMVPCCluster .Spec = vpcCluster .Spec
659
+ scope .IBMVPCCluster .Status = vpcCluster .Status
660
+ mockvpc .EXPECT ().ListSubnets (gomock .AssignableToTypeOf (& vpcv1.ListSubnetsOptions {})).Return (nil , & core.DetailedResponse {}, errors .New ("Error listing subnets" ))
661
+ err := scope .DeleteSubnet ()
662
+ g .Expect (err ).To (Not (BeNil ()))
663
+ })
664
+ t .Run ("Subnet doesn't exist" , func (t * testing.T ) {
665
+ g := NewWithT (t )
666
+ mockController , mockvpc := setup (t )
667
+ t .Cleanup (mockController .Finish )
668
+ scope := setupClusterScope (clusterName , mockvpc )
669
+ scope .IBMVPCCluster .Spec = vpcCluster .Spec
670
+ scope .IBMVPCCluster .Status = vpcCluster .Status
671
+ mockvpc .EXPECT ().ListSubnets (gomock .AssignableToTypeOf (& vpcv1.ListSubnetsOptions {})).Return (& vpcv1.SubnetCollection {Subnets : []vpcv1.Subnet {}}, & core.DetailedResponse {}, nil )
672
+ err := scope .DeleteSubnet ()
673
+ g .Expect (err ).To (BeNil ())
674
+ })
643
675
})
644
676
}
645
677
0 commit comments