@@ -930,9 +930,15 @@ func TestRouteTableSpecs(t *testing.T) {
930
930
}
931
931
932
932
func TestNatGatewaySpecs (t * testing.T ) {
933
+ scheme := runtime .NewScheme ()
934
+ _ = asonetworkv1api20201101 .AddToScheme (scheme )
935
+ _ = corev1 .AddToScheme (scheme )
936
+ _ = infrav1 .AddToScheme (scheme )
937
+
933
938
tests := []struct {
934
939
name string
935
940
clusterScope ClusterScope
941
+ vnet asonetworkv1api20201101.VirtualNetwork
936
942
want []azure.ASOResourceSpecGetter [* asonetworkv1api20220701.NatGateway ]
937
943
}{
938
944
{
@@ -993,11 +999,24 @@ func TestNatGatewaySpecs(t *testing.T) {
993
999
},
994
1000
},
995
1001
},
1002
+ Vnet : infrav1.VnetSpec {
1003
+ Name : "fake-vnet-1" ,
1004
+ },
996
1005
},
997
1006
},
998
1007
},
999
1008
cache : & ClusterCache {},
1000
1009
},
1010
+ vnet : asonetworkv1api20201101.VirtualNetwork {
1011
+ ObjectMeta : metav1.ObjectMeta {
1012
+ Name : "fake-vnet-1" ,
1013
+ },
1014
+ Status : asonetworkv1api20201101.VirtualNetwork_STATUS {
1015
+ Tags : map [string ]string {
1016
+ "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster" : "owned" ,
1017
+ },
1018
+ },
1019
+ },
1001
1020
want : []azure.ASOResourceSpecGetter [* asonetworkv1api20220701.NatGateway ]{
1002
1021
& natgateways.NatGatewaySpec {
1003
1022
Name : "fake-nat-gateway-1" ,
@@ -1075,11 +1094,24 @@ func TestNatGatewaySpecs(t *testing.T) {
1075
1094
},
1076
1095
},
1077
1096
},
1097
+ Vnet : infrav1.VnetSpec {
1098
+ Name : "fake-vnet-1" ,
1099
+ },
1078
1100
},
1079
1101
},
1080
1102
},
1081
1103
cache : & ClusterCache {},
1082
1104
},
1105
+ vnet : asonetworkv1api20201101.VirtualNetwork {
1106
+ ObjectMeta : metav1.ObjectMeta {
1107
+ Name : "fake-vnet-1" ,
1108
+ },
1109
+ Status : asonetworkv1api20201101.VirtualNetwork_STATUS {
1110
+ Tags : map [string ]string {
1111
+ "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster" : "owned" ,
1112
+ },
1113
+ },
1114
+ },
1083
1115
want : []azure.ASOResourceSpecGetter [* asonetworkv1api20220701.NatGateway ]{
1084
1116
& natgateways.NatGatewaySpec {
1085
1117
Name : "fake-nat-gateway-1" ,
@@ -1156,11 +1188,24 @@ func TestNatGatewaySpecs(t *testing.T) {
1156
1188
},
1157
1189
},
1158
1190
},
1191
+ Vnet : infrav1.VnetSpec {
1192
+ Name : "fake-vnet-1" ,
1193
+ },
1159
1194
},
1160
1195
},
1161
1196
},
1162
1197
cache : & ClusterCache {},
1163
1198
},
1199
+ vnet : asonetworkv1api20201101.VirtualNetwork {
1200
+ ObjectMeta : metav1.ObjectMeta {
1201
+ Name : "fake-vnet-1" ,
1202
+ },
1203
+ Status : asonetworkv1api20201101.VirtualNetwork_STATUS {
1204
+ Tags : map [string ]string {
1205
+ "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster" : "owned" ,
1206
+ },
1207
+ },
1208
+ },
1164
1209
want : []azure.ASOResourceSpecGetter [* asonetworkv1api20220701.NatGateway ]{
1165
1210
& natgateways.NatGatewaySpec {
1166
1211
Name : "fake-nat-gateway-1" ,
@@ -1182,6 +1227,23 @@ func TestNatGatewaySpecs(t *testing.T) {
1182
1227
tt := tt
1183
1228
t .Run (tt .name , func (t * testing.T ) {
1184
1229
t .Parallel ()
1230
+ fakeIdentity := & infrav1.AzureClusterIdentity {
1231
+ ObjectMeta : metav1.ObjectMeta {
1232
+ Name : "fake-identity" ,
1233
+ Namespace : "default" ,
1234
+ },
1235
+ Spec : infrav1.AzureClusterIdentitySpec {
1236
+ Type : infrav1 .ServicePrincipal ,
1237
+ ClientID : fakeClientID ,
1238
+ TenantID : fakeTenantID ,
1239
+ },
1240
+ }
1241
+ fakeSecret := & corev1.Secret {Data : map [string ][]byte {"clientSecret" : []byte ("fooSecret" )}}
1242
+
1243
+ initObjects := []runtime.Object {& tt .vnet , fakeIdentity , fakeSecret }
1244
+ fakeClient := fake .NewClientBuilder ().WithScheme (scheme ).WithRuntimeObjects (initObjects ... ).Build ()
1245
+ tt .clusterScope .Client = fakeClient
1246
+
1185
1247
if got := tt .clusterScope .NatGatewaySpecs (); ! reflect .DeepEqual (got , tt .want ) {
1186
1248
t .Errorf ("NatGatewaySpecs() = %s, want %s" , specArrayToString (got ), specArrayToString (tt .want ))
1187
1249
}
@@ -1349,9 +1411,15 @@ func TestNSGSpecs(t *testing.T) {
1349
1411
}
1350
1412
1351
1413
func TestSubnetSpecs (t * testing.T ) {
1414
+ scheme := runtime .NewScheme ()
1415
+ _ = asonetworkv1api20201101 .AddToScheme (scheme )
1416
+ _ = corev1 .AddToScheme (scheme )
1417
+ _ = infrav1 .AddToScheme (scheme )
1418
+
1352
1419
tests := []struct {
1353
1420
name string
1354
1421
clusterScope ClusterScope
1422
+ vnet asonetworkv1api20201101.VirtualNetwork
1355
1423
want []azure.ASOResourceSpecGetter [* asonetworkv1api20201101.VirtualNetworksSubnet ]
1356
1424
}{
1357
1425
{
@@ -1431,6 +1499,11 @@ func TestSubnetSpecs(t *testing.T) {
1431
1499
},
1432
1500
cache : & ClusterCache {},
1433
1501
},
1502
+ vnet : asonetworkv1api20201101.VirtualNetwork {
1503
+ ObjectMeta : metav1.ObjectMeta {
1504
+ Name : "fake-vnet-1" ,
1505
+ },
1506
+ },
1434
1507
want : []azure.ASOResourceSpecGetter [* asonetworkv1api20201101.VirtualNetworksSubnet ]{
1435
1508
& subnets.SubnetSpec {
1436
1509
Name : "fake-subnet-1" ,
@@ -1536,6 +1609,11 @@ func TestSubnetSpecs(t *testing.T) {
1536
1609
},
1537
1610
cache : & ClusterCache {},
1538
1611
},
1612
+ vnet : asonetworkv1api20201101.VirtualNetwork {
1613
+ ObjectMeta : metav1.ObjectMeta {
1614
+ Name : "fake-vnet-1" ,
1615
+ },
1616
+ },
1539
1617
want : []azure.ASOResourceSpecGetter [* asonetworkv1api20201101.VirtualNetworksSubnet ]{
1540
1618
& subnets.SubnetSpec {
1541
1619
Name : "fake-subnet-1" ,
@@ -1568,6 +1646,23 @@ func TestSubnetSpecs(t *testing.T) {
1568
1646
tt := tt
1569
1647
t .Run (tt .name , func (t * testing.T ) {
1570
1648
t .Parallel ()
1649
+ fakeIdentity := & infrav1.AzureClusterIdentity {
1650
+ ObjectMeta : metav1.ObjectMeta {
1651
+ Name : "fake-identity" ,
1652
+ Namespace : "default" ,
1653
+ },
1654
+ Spec : infrav1.AzureClusterIdentitySpec {
1655
+ Type : infrav1 .ServicePrincipal ,
1656
+ ClientID : fakeClientID ,
1657
+ TenantID : fakeTenantID ,
1658
+ },
1659
+ }
1660
+ fakeSecret := & corev1.Secret {Data : map [string ][]byte {"clientSecret" : []byte ("fooSecret" )}}
1661
+
1662
+ initObjects := []runtime.Object {& tt .vnet , fakeIdentity , fakeSecret }
1663
+ fakeClient := fake .NewClientBuilder ().WithScheme (scheme ).WithRuntimeObjects (initObjects ... ).Build ()
1664
+ tt .clusterScope .Client = fakeClient
1665
+
1571
1666
if got := tt .clusterScope .SubnetSpecs (); ! reflect .DeepEqual (got , tt .want ) {
1572
1667
t .Errorf ("SubnetSpecs() = \n %s, want \n %s" , specArrayToString (got ), specArrayToString (tt .want ))
1573
1668
}
@@ -1576,13 +1671,19 @@ func TestSubnetSpecs(t *testing.T) {
1576
1671
}
1577
1672
1578
1673
func TestIsVnetManaged (t * testing.T ) {
1674
+ scheme := runtime .NewScheme ()
1675
+ _ = asonetworkv1api20201101 .AddToScheme (scheme )
1676
+ _ = corev1 .AddToScheme (scheme )
1677
+ _ = infrav1 .AddToScheme (scheme )
1678
+
1579
1679
tests := []struct {
1580
1680
name string
1581
1681
clusterScope ClusterScope
1682
+ vnet asonetworkv1api20201101.VirtualNetwork
1582
1683
want bool
1583
1684
}{
1584
1685
{
1585
- name : "VNET ID is empty " ,
1686
+ name : "Wrong tags " ,
1586
1687
clusterScope : ClusterScope {
1587
1688
Cluster : & clusterv1.Cluster {
1588
1689
ObjectMeta : metav1.ObjectMeta {
@@ -1593,36 +1694,22 @@ func TestIsVnetManaged(t *testing.T) {
1593
1694
Spec : infrav1.AzureClusterSpec {
1594
1695
NetworkSpec : infrav1.NetworkSpec {
1595
1696
Vnet : infrav1.VnetSpec {
1596
- ID : "" ,
1697
+ Name : "fake-vnet-1 " ,
1597
1698
},
1598
1699
},
1599
1700
},
1600
1701
},
1601
1702
cache : & ClusterCache {},
1602
1703
},
1603
- want : true ,
1604
- },
1605
- {
1606
- name : "Wrong tags" ,
1607
- clusterScope : ClusterScope {
1608
- Cluster : & clusterv1.Cluster {
1609
- ObjectMeta : metav1.ObjectMeta {
1610
- Name : "my-cluster" ,
1611
- },
1704
+ vnet : asonetworkv1api20201101.VirtualNetwork {
1705
+ ObjectMeta : metav1.ObjectMeta {
1706
+ Name : "fake-vnet-1" ,
1612
1707
},
1613
- AzureCluster : & infrav1.AzureCluster {
1614
- Spec : infrav1.AzureClusterSpec {
1615
- NetworkSpec : infrav1.NetworkSpec {
1616
- Vnet : infrav1.VnetSpec {
1617
- ID : "my-id" ,
1618
- VnetClassSpec : infrav1.VnetClassSpec {Tags : map [string ]string {
1619
- "key" : "value" ,
1620
- }},
1621
- },
1622
- },
1708
+ Status : asonetworkv1api20201101.VirtualNetwork_STATUS {
1709
+ Tags : map [string ]string {
1710
+ "key" : "value" ,
1623
1711
},
1624
1712
},
1625
- cache : & ClusterCache {},
1626
1713
},
1627
1714
want : false ,
1628
1715
},
@@ -1638,16 +1725,23 @@ func TestIsVnetManaged(t *testing.T) {
1638
1725
Spec : infrav1.AzureClusterSpec {
1639
1726
NetworkSpec : infrav1.NetworkSpec {
1640
1727
Vnet : infrav1.VnetSpec {
1641
- ID : "my-id" ,
1642
- VnetClassSpec : infrav1.VnetClassSpec {Tags : map [string ]string {
1643
- "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster" : "owned" ,
1644
- }},
1728
+ Name : "fake-vnet-1" ,
1645
1729
},
1646
1730
},
1647
1731
},
1648
1732
},
1649
1733
cache : & ClusterCache {},
1650
1734
},
1735
+ vnet : asonetworkv1api20201101.VirtualNetwork {
1736
+ ObjectMeta : metav1.ObjectMeta {
1737
+ Name : "fake-vnet-1" ,
1738
+ },
1739
+ Status : asonetworkv1api20201101.VirtualNetwork_STATUS {
1740
+ Tags : map [string ]string {
1741
+ "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster" : "owned" ,
1742
+ },
1743
+ },
1744
+ },
1651
1745
want : true ,
1652
1746
},
1653
1747
{
@@ -1680,6 +1774,23 @@ func TestIsVnetManaged(t *testing.T) {
1680
1774
tt := tt
1681
1775
t .Run (tt .name , func (t * testing.T ) {
1682
1776
t .Parallel ()
1777
+ fakeIdentity := & infrav1.AzureClusterIdentity {
1778
+ ObjectMeta : metav1.ObjectMeta {
1779
+ Name : "fake-identity" ,
1780
+ Namespace : "default" ,
1781
+ },
1782
+ Spec : infrav1.AzureClusterIdentitySpec {
1783
+ Type : infrav1 .ServicePrincipal ,
1784
+ ClientID : fakeClientID ,
1785
+ TenantID : fakeTenantID ,
1786
+ },
1787
+ }
1788
+ fakeSecret := & corev1.Secret {Data : map [string ][]byte {"clientSecret" : []byte ("fooSecret" )}}
1789
+
1790
+ initObjects := []runtime.Object {& tt .vnet , fakeIdentity , fakeSecret }
1791
+ fakeClient := fake .NewClientBuilder ().WithScheme (scheme ).WithRuntimeObjects (initObjects ... ).Build ()
1792
+ tt .clusterScope .Client = fakeClient
1793
+
1683
1794
got := tt .clusterScope .IsVnetManaged ()
1684
1795
if ! reflect .DeepEqual (got , tt .want ) {
1685
1796
t .Errorf ("IsVnetManaged() = \n %t, want \n %t" , got , tt .want )
0 commit comments