VNet.Tests.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# BeforeAll { # # . $PSCommandPath.Replace('.Tests.ps1', '.ps1') # Import-Module $PSScriptRoot\Find-FreeSubnets.psm1 -Force # } using module ./VNet.psm1 using module Az.Network BeforeDiscovery { # Loads and registers my custom assertion. Ignores usage of unapproved verb with -DisableNameChecking Import-Module "$PSScriptRoot/VNetCustomAssertions.psm1" -DisableNameChecking } Describe "Find-FreeSubnets" { It "Returns expected output" { $vnetWithFragmentedSubnets = @" { "AddressSpace": { "AddressPrefixes": [ "10.0.0.0/16" ] }, "DhcpOptions": { "DnsServers": null }, "FlowTimeoutInMinutes": null, "Subnets": [ { "AddressPrefix": [ "10.0.0.0/24" ], "IpConfigurations": [], "ServiceAssociationLinks": [], "ResourceNavigationLinks": [], "NetworkSecurityGroup": null, "RouteTable": null, "NatGateway": null, "ServiceEndpoints": [], "ServiceEndpointPolicies": [], "Delegations": [], "PrivateEndpoints": [], "ProvisioningState": "Succeeded", "PrivateEndpointNetworkPolicies": "Disabled", "PrivateLinkServiceNetworkPolicies": "Enabled", "IpAllocations": [], "Name": "default", "Etag": "W/\"99f7188e-bab9-4a66-a685-a3e5acb123fd\"", "Id": "/subscriptions/b4b2e7e9-66e7-46b5-a56b-cce2b50011d4/resourceGroups/rg-freesubnet-australiaeast/providers/Microsoft.Network/virtualNetworks/vnet-freesubnet-australiaeast/subnets/default" }, { "AddressPrefix": [ "10.0.1.0/28" ], "IpConfigurations": [], "ServiceAssociationLinks": [], "ResourceNavigationLinks": [], "NetworkSecurityGroup": null, "RouteTable": null, "NatGateway": null, "ServiceEndpoints": [], "ServiceEndpointPolicies": [], "Delegations": [], "PrivateEndpoints": [], "ProvisioningState": "Succeeded", "PrivateEndpointNetworkPolicies": "Disabled", "PrivateLinkServiceNetworkPolicies": "Enabled", "IpAllocations": [], "Name": "subnet-freesubnet-australiaeast", "Etag": "W/\"99f7188e-bab9-4a66-a685-a3e5acb123fd\"", "Id": "/subscriptions/b4b2e7e9-66e7-46b5-a56b-cce2b50011d4/resourceGroups/rg-freesubnet-australiaeast/providers/Microsoft.Network/virtualNetworks/vnet-freesubnet-australiaeast/subnets/subnet-freesubnet-australiaeast" }, { "AddressPrefix": [ "10.0.1.88/29" ], "IpConfigurations": [], "ServiceAssociationLinks": [], "ResourceNavigationLinks": [], "NetworkSecurityGroup": null, "RouteTable": null, "NatGateway": null, "ServiceEndpoints": [], "ServiceEndpointPolicies": [], "Delegations": [], "PrivateEndpoints": [], "ProvisioningState": "Succeeded", "PrivateEndpointNetworkPolicies": "Disabled", "PrivateLinkServiceNetworkPolicies": "Enabled", "IpAllocations": [], "Name": "subnet-freesubnet-australiaeast-002", "Etag": "W/\"99f7188e-bab9-4a66-a685-a3e5acb123fd\"", "Id": "/subscriptions/b4b2e7e9-66e7-46b5-a56b-cce2b50011d4/resourceGroups/rg-freesubnet-australiaeast/providers/Microsoft.Network/virtualNetworks/vnet-freesubnet-australiaeast/subnets/subnet-freesubnet-australiaeast-002" }, { "AddressPrefix": [ "10.0.1.64/28" ], "IpConfigurations": [], "ServiceAssociationLinks": [], "ResourceNavigationLinks": [], "NetworkSecurityGroup": null, "RouteTable": null, "NatGateway": null, "ServiceEndpoints": [], "ServiceEndpointPolicies": [], "Delegations": [], "PrivateEndpoints": [], "ProvisioningState": "Succeeded", "PrivateEndpointNetworkPolicies": "Disabled", "PrivateLinkServiceNetworkPolicies": "Enabled", "IpAllocations": [], "Name": "subnet-freesubnet-australiaeast-001", "Etag": "W/\"99f7188e-bab9-4a66-a685-a3e5acb123fd\"", "Id": "/subscriptions/b4b2e7e9-66e7-46b5-a56b-cce2b50011d4/resourceGroups/rg-freesubnet-australiaeast/providers/Microsoft.Network/virtualNetworks/vnet-freesubnet-australiaeast/subnets/subnet-freesubnet-australiaeast-001" } ], "BgpCommunities": null, "Encryption": null, "VirtualNetworkPeerings": [], "ProvisioningState": "Succeeded", "EnableDdosProtection": false, "DdosProtectionPlan": null, "IpAllocations": [], "ExtendedLocation": null, "ResourceGroupName": "rg-freesubnet-australiaeast", "Location": "australiaeast", "ResourceGuid": "c0c009f8-d32b-433c-a30a-b5f4b70a1506", "Type": "Microsoft.Network/virtualNetworks", "Tag": {}, "TagsTable": null, "Name": "vnet-freesubnet-australiaeast", "Etag": "W/\"99f7188e-bab9-4a66-a685-a3e5acb123fd\"", "Id": "/subscriptions/b4b2e7e9-66e7-46b5-a56b-cce2b50011d4/resourceGroups/rg-freesubnet-australiaeast/providers/Microsoft.Network/virtualNetworks/vnet-freesubnet-australiaeast", "AddressSpaceText": "{\r\n \"AddressPrefixes\": [\r\n \"10.0.0.0/16\"\r\n ]\r\n}", "DhcpOptionsText": "{}", "FlowTimeoutInMinutesText": "null", "SubnetsText": "[\r\n {\r\n \"Delegations\": [],\r\n \"Name\": \"default\",\r\n \"Etag\": \"W/\\\"99f7188e-bab9-4a66-a685-a3e5acb123fd\\\"\",\r\n \"Id\": \"/subscriptions/b4b2e7e9-66e7-46b5-a56b-cce2b50011d4/resourceGroups/rg-freesubnet-australiaeast/providers/Microsoft.Network/virtualNetworks/vnet-freesubnet-australiaeast/subnets/default\",\r\n \"AddressPrefix\": [\r\n \"10.0.0.0/24\"\r\n ],\r\n \"IpConfigurations\": [],\r\n \"ServiceAssociationLinks\": [],\r\n \"ResourceNavigationLinks\": [],\r\n \"ServiceEndpoints\": [],\r\n \"ServiceEndpointPolicies\": [],\r\n \"PrivateEndpoints\": [],\r\n \"ProvisioningState\": \"Succeeded\",\r\n \"PrivateEndpointNetworkPolicies\": \"Disabled\",\r\n \"PrivateLinkServiceNetworkPolicies\": \"Enabled\",\r\n \"IpAllocations\": []\r\n },\r\n {\r\n \"Delegations\": [],\r\n \"Name\": \"subnet-freesubnet-australiaeast\",\r\n \"Etag\": \"W/\\\"99f7188e-bab9-4a66-a685-a3e5acb123fd\\\"\",\r\n \"Id\": \"/subscriptions/b4b2e7e9-66e7-46b5-a56b-cce2b50011d4/resourceGroups/rg-freesubnet-australiaeast/providers/Microsoft.Network/virtualNetworks/vnet-freesubnet-australiaeast/subnets/subnet-freesubnet-australiaeast\",\r\n \"AddressPrefix\": [\r\n \"10.0.1.0/28\"\r\n ],\r\n \"IpConfigurations\": [],\r\n \"ServiceAssociationLinks\": [],\r\n \"ResourceNavigationLinks\": [],\r\n \"ServiceEndpoints\": [],\r\n \"ServiceEndpointPolicies\": [],\r\n \"PrivateEndpoints\": [],\r\n \"ProvisioningState\": \"Succeeded\",\r\n \"PrivateEndpointNetworkPolicies\": \"Disabled\",\r\n \"PrivateLinkServiceNetworkPolicies\": \"Enabled\",\r\n \"IpAllocations\": []\r\n },\r\n {\r\n \"Delegations\": [],\r\n \"Name\": \"subnet-freesubnet-australiaeast-002\",\r\n \"Etag\": \"W/\\\"99f7188e-bab9-4a66-a685-a3e5acb123fd\\\"\",\r\n \"Id\": \"/subscriptions/b4b2e7e9-66e7-46b5-a56b-cce2b50011d4/resourceGroups/rg-freesubnet-australiaeast/providers/Microsoft.Network/virtualNetworks/vnet-freesubnet-australiaeast/subnets/subnet-freesubnet-australiaeast-002\",\r\n \"AddressPrefix\": [\r\n \"10.0.1.88/29\"\r\n ],\r\n \"IpConfigurations\": [],\r\n \"ServiceAssociationLinks\": [],\r\n \"ResourceNavigationLinks\": [],\r\n \"ServiceEndpoints\": [],\r\n \"ServiceEndpointPolicies\": [],\r\n \"PrivateEndpoints\": [],\r\n \"ProvisioningState\": \"Succeeded\",\r\n \"PrivateEndpointNetworkPolicies\": \"Disabled\",\r\n \"PrivateLinkServiceNetworkPolicies\": \"Enabled\",\r\n \"IpAllocations\": []\r\n },\r\n {\r\n \"Delegations\": [],\r\n \"Name\": \"subnet-freesubnet-australiaeast-001\",\r\n \"Etag\": \"W/\\\"99f7188e-bab9-4a66-a685-a3e5acb123fd\\\"\",\r\n \"Id\": \"/subscriptions/b4b2e7e9-66e7-46b5-a56b-cce2b50011d4/resourceGroups/rg-freesubnet-australiaeast/providers/Microsoft.Network/virtualNetworks/vnet-freesubnet-australiaeast/subnets/subnet-freesubnet-australiaeast-001\",\r\n \"AddressPrefix\": [\r\n \"10.0.1.64/28\"\r\n ],\r\n \"IpConfigurations\": [],\r\n \"ServiceAssociationLinks\": [],\r\n \"ResourceNavigationLinks\": [],\r\n \"ServiceEndpoints\": [],\r\n \"ServiceEndpointPolicies\": [],\r\n \"PrivateEndpoints\": [],\r\n \"ProvisioningState\": \"Succeeded\",\r\n \"PrivateEndpointNetworkPolicies\": \"Disabled\",\r\n \"PrivateLinkServiceNetworkPolicies\": \"Enabled\",\r\n \"IpAllocations\": []\r\n }\r\n]", "BgpCommunitiesText": "null", "EncryptionText": "null", "VirtualNetworkPeeringsText": "[]", "EnableDdosProtectionText": "false", "DdosProtectionPlanText": "null", "IpAllocationsText": "[]", "ExtendedLocationText": "null" } "@ | ConvertFrom-Json Mock -ModuleName VNet -CommandName Get-AzVirtualNetwork { return $vnetWithFragmentedSubnets } $result = Find-FreeSubnets -ResourceGroup rg-freesubnet-australiaeast -VNetName vnet-freesubnet-australiaeast $expected = [VNetSummary](Get-content .\Find-FreeSubnets.Expected.json | ConvertFrom-Json) $result | Should -BeVNetSummary -ExpectedValue $expected } } |