@@ -109,4 +109,67 @@ func TestPostCreateOrUpdateResourceHook(t *testing.T) {
109109 g .Expect (vnet .Tags ).To (Equal (infrav1.Tags {"actual" : "tags" }))
110110 g .Expect (vnet .CIDRBlocks ).To (Equal ([]string {"cidr" }))
111111 })
112+
113+ t .Run ("correctly handles empty and non-empty ASO Status CIDRBlocks" , func (t * testing.T ) {
114+ g := NewGomegaWithT (t )
115+ mockCtrl := gomock .NewController (t )
116+ scope := mock_virtualnetworks .NewMockVNetScope (mockCtrl )
117+
118+ existing := & asonetworkv1.VirtualNetwork {
119+ ObjectMeta : metav1.ObjectMeta {
120+ Name : "vnet" ,
121+ },
122+ Status : asonetworkv1.VirtualNetwork_STATUS {
123+ Id : ptr .To ("id" ),
124+ Tags : map [string ]string {"actual" : "tags" },
125+ AddressSpace : & asonetworkv1.AddressSpace_STATUS {
126+ AddressPrefixes : []string {"cidr" },
127+ },
128+ },
129+ }
130+
131+ vnet := & infrav1.VnetSpec {}
132+ scope .EXPECT ().Vnet ().Return (vnet )
133+
134+ subnets := []client.Object {
135+ & asonetworkv1.VirtualNetworksSubnet {
136+ ObjectMeta : metav1.ObjectMeta {
137+ Name : "empty-cidr-status-subnet" ,
138+ Labels : map [string ]string {
139+ labels .OwnerNameLabel : existing .Name ,
140+ },
141+ },
142+ Spec : asonetworkv1.VirtualNetworksSubnet_Spec {
143+ AzureName : "empty-cidr-status-subnet" ,
144+ },
145+ Status : asonetworkv1.VirtualNetworksSubnet_STATUS {
146+ AddressPrefixes : []string {},
147+ },
148+ },
149+ & asonetworkv1.VirtualNetworksSubnet {
150+ ObjectMeta : metav1.ObjectMeta {
151+ Name : "nonempty-cidr-status-subnet" ,
152+ Labels : map [string ]string {
153+ labels .OwnerNameLabel : existing .Name ,
154+ },
155+ },
156+ Spec : asonetworkv1.VirtualNetworksSubnet_Spec {
157+ AzureName : "nonempty-cidr-status-subnet" ,
158+ },
159+ Status : asonetworkv1.VirtualNetworksSubnet_STATUS {
160+ AddressPrefixes : []string {"cidr" },
161+ },
162+ },
163+ }
164+ s := runtime .NewScheme ()
165+ g .Expect (asonetworkv1 .AddToScheme (s )).To (Succeed ())
166+ c := fakeclient .NewClientBuilder ().
167+ WithScheme (s ).
168+ WithObjects (subnets ... ).
169+ Build ()
170+ scope .EXPECT ().GetClient ().Return (c )
171+ scope .EXPECT ().UpdateSubnetCIDRs ("empty-cidr-status-subnet" , []string {}).Times (0 )
172+ scope .EXPECT ().UpdateSubnetCIDRs ("nonempty-cidr-status-subnet" , []string {"cidr" }).Times (1 )
173+ g .Expect (postCreateOrUpdateResourceHook (context .Background (), scope , existing , nil )).To (Succeed ())
174+ })
112175}
0 commit comments