Skip to content

Commit 9d144cb

Browse files
committed
Replaced hardcoded location in Network tests
1 parent be58079 commit 9d144cb

13 files changed

+97
-127
lines changed

src/ResourceManager/Network/Commands.Network.Test/ScenarioTests/ApplicationGatewayTests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ function Test-ApplicationGatewayCRUD3
572572
)
573573

574574
# Setup
575-
$location = "westus2"
575+
$location = Get-ProviderLocation "Microsoft.Network/applicationGateways" "West US 2"
576576

577577
$rgname = Get-ResourceGroupName
578578
$appgwName = Get-ResourceName

src/ResourceManager/Network/Commands.Network.Test/ScenarioTests/AzureFirewallTests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function Test-AzureFirewallCRUD
2222
$rgname = Get-ResourceGroupName
2323
$azureFirewallName = Get-ResourceName
2424
$resourceTypeParent = "Microsoft.Network/AzureFirewalls"
25-
$location = "westcentralus" #Get-ProviderLocation $resourceTypeParent
25+
$location = Get-ProviderLocation $resourceTypeParent "West Central US"
2626

2727
$vnetName = Get-ResourceName
2828
$subnetName = "AzureFirewallSubnet"
@@ -349,7 +349,7 @@ function Test-AzureFirewallAllocateAndDeallocate
349349
$rgname = Get-ResourceGroupName
350350
$azureFirewallName = Get-ResourceName
351351
$resourceTypeParent = "Microsoft.Network/AzureFirewalls"
352-
$location = "westcentralus" #Get-ProviderLocation $resourceTypeParent
352+
$location = Get-ProviderLocation $resourceTypeParent "West Central US"
353353

354354
$vnetName = Get-ResourceName
355355
$subnetName = "AzureFirewallSubnet"

src/ResourceManager/Network/Commands.Network.Test/ScenarioTests/Common.ps1

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -57,36 +57,29 @@ function Get-NetworkTestMode {
5757
.SYNOPSIS
5858
Gets the default location for a provider
5959
#>
60-
function Get-ProviderLocation($provider)
60+
function Get-ProviderLocation($provider, $preferredLocation = "West US")
6161
{
62-
return "westcentralus";
63-
if ((Get-NetworkTestMode) -ne 'Playback')
64-
{
65-
$namespace = $provider.Split("/")[0]
66-
if($provider.Contains("/"))
67-
{
68-
$type = $provider.Substring($namespace.Length + 1)
69-
$location = Get-AzureRmResourceProvider -ProviderNamespace $namespace | where {$_.ResourceTypes[0].ResourceTypeName -eq $type}
70-
71-
if ($location -eq $null)
72-
{
73-
return "WestUS2"
74-
}
75-
else
76-
{
77-
if($location.Locations[0] -eq "West US")
78-
{
79-
return $location.Locations[1]
80-
}
81-
else
82-
{
83-
return $location.Locations[0]
84-
}
85-
}
86-
}
87-
return "West US"
88-
}
89-
return "WestUS"
62+
if((Get-NetworkTestMode) -ne 'Playback')
63+
{
64+
if(-not $preferredLocation.Contains(" "))
65+
{
66+
# TODO: implement UseCanonical switch after PR is merged: https://github.com/Azure/azure-powershell-common/pull/90
67+
return $preferredLocation;
68+
}
69+
if($provider.Contains("/"))
70+
{
71+
$providerNamespace, $resourceType = $provider.Split("/");
72+
return Get-Location $providerNamespace $resourceType $preferredLocation;
73+
}
74+
else
75+
{
76+
return $preferredLocation;
77+
}
78+
}
79+
else
80+
{
81+
return $preferredLocation;
82+
}
9083
}
9184

9285
<#
@@ -110,4 +103,4 @@ function Start-TestSleep($milliseconds)
110103
{
111104
Start-Sleep -Milliseconds $milliseconds
112105
}
113-
}
106+
}

src/ResourceManager/Network/Commands.Network.Test/ScenarioTests/ExpressRouteCircuitTests.ps1

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ Tests ExpressRouteCircuitCRUD.
3232
#>
3333
function Test-ExpressRouteRouteFilters
3434
{
35-
$rgname = "filter"
36-
$location = "westus"
35+
$location = Get-ProviderLocation "Microsoft.Network/expressRouteCircuits" "West US"
36+
$rgname = "filter"
3737
$filterName = "filter"
3838
$ruleName = "rule"
3939

@@ -93,9 +93,9 @@ function Test-ExpressRouteCircuitStageCRUD
9393
# Setup
9494
$rgname = 'movecircuit'
9595
$circuitName = Get-ResourceName
96-
$rglocation = "brazilSouth"
97-
$resourceTypeParent = "Microsoft.Network/expressRouteCircuits"
98-
$location = "brazilSouth"
96+
$rglocation = Get-ProviderLocation ResourceManagement "Brazil South"
97+
$location = Get-ProviderLocation "Microsoft.Network/expressRouteCircuits" "Brazil South"
98+
9999
try
100100
{
101101
# Create the resource group
@@ -145,9 +145,8 @@ function Test-ExpressRouteCircuitCRUD
145145
$rgname = Get-ResourceGroupName
146146
$circuitName = Get-ResourceName
147147
$rglocation = Get-ProviderLocation ResourceManagement
148-
$resourceTypeParent = "Microsoft.Network/expressRouteCircuits"
149-
$location = Get-ProviderLocation $resourceTypeParent
150-
$location = "brazilSouth"
148+
$location = Get-ProviderLocation "Microsoft.Network/expressRouteCircuits" "Brazil South"
149+
151150
try
152151
{
153152
# Create the resource group
@@ -225,10 +224,9 @@ function Test-ExpressRouteCircuitPrivatePublicPeeringCRUD
225224
# Setup
226225
$rgname = Get-ResourceGroupName
227226
$circuitName = Get-ResourceName
228-
$rglocation = Get-ProviderLocation ResourceManagement
229-
$resourceTypeParent = "Microsoft.Network/expressRouteCircuits"
230-
$location = Get-ProviderLocation $resourceTypeParent
231-
$location = "brazilSouth"
227+
$rglocation = Get-ProviderLocation ResourceManagement
228+
$location = Get-ProviderLocation "Microsoft.Network/expressRouteCircuits" "Brazil South"
229+
232230
try
233231
{
234232
# Create the resource group
@@ -325,12 +323,11 @@ function Test-ExpressRouteCircuitMicrosoftPeeringCRUD
325323
# Setup
326324
$rgname = Get-ResourceGroupName
327325
$circuitName = Get-ResourceName
328-
$rglocation = Get-ProviderLocation ResourceManagement
329-
$resourceTypeParent = "Microsoft.Network/expressRouteCircuits"
330-
$location = Get-ProviderLocation $resourceTypeParent
331-
$location = "brazilSouth"
332-
$filterName = "filter"
333-
$ruleName = "rule"
326+
$filterName = "filter"
327+
$ruleName = "rule"
328+
$rglocation = Get-ProviderLocation ResourceManagement
329+
$location = Get-ProviderLocation "Microsoft.Network/expressRouteCircuits" "Brazil South"
330+
334331
try
335332
{
336333
# Create the resource group
@@ -480,11 +477,9 @@ function Test-ExpressRouteCircuitAuthorizationCRUD
480477
# Setup
481478
$rgname = Get-ResourceGroupName
482479
$circuitName = Get-ResourceName
483-
$rglocation = Get-ProviderLocation ResourceManagement
484-
$resourceTypeParent = "Microsoft.Network/expressRouteCircuits"
485-
$location = Get-ProviderLocation $resourceTypeParent
486-
$location = "brazilSouth"
487480
$authorizationName = "testkey"
481+
$rglocation = Get-ProviderLocation ResourceManagement
482+
$location = Get-ProviderLocation "Microsoft.Network/expressRouteCircuits" "Brazil South"
488483

489484
try
490485
{
@@ -550,8 +545,7 @@ function Test-ExpressRouteCircuitConnectionCRUD
550545
$peerCircuitName = Get-ResourceName
551546
$rgname = Get-ResourceGroupName
552547
$resourceTypeParent = "Microsoft.Network/expressRouteCircuits"
553-
$rglocation = Get-ProviderLocation $resourceTypeParent
554-
$rglocation = "brazilSouth"
548+
$rglocation = Get-ProviderLocation $resourceTypeParent "Brazil South"
555549
$connectionName = Get-ResourceName
556550
$addressPrefix = "30.0.0.0/29"
557551

src/ResourceManager/Network/Commands.Network.Test/ScenarioTests/ExpressRouteCrossConnectionTests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ function Test-ExpressRouteCrossConnectionApis
2323
$circuitName = Get-ResourceName
2424
$rglocation = Get-ProviderLocation ResourceManagement
2525
$resourceTypeParent = "Microsoft.Network/expressRouteCircuits"
26-
$location = Get-ProviderLocation $resourceTypeParent
27-
$location = "brazilSouth"
26+
$location = Get-ProviderLocation $resourceTypeParent "Brazil South"
27+
2828
try
2929
{
3030
# Create the resource group

src/ResourceManager/Network/Commands.Network.Test/ScenarioTests/LoadBalancerTests.ps1

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,9 +1396,8 @@ function Test-LoadBalancerInboundNatPoolConfigCRUD-InternalLB
13961396
$domainNameLabel = Get-ResourceName
13971397
$lbName = Get-ResourceName
13981398
$frontendName = Get-ResourceName
1399-
$rglocation = "West US"
1400-
$resourceTypeParent = "Microsoft.Network/loadBalancers"
1401-
$location = "West US"
1399+
$rglocation = Get-ProviderLocation ResourceManagement "West US"
1400+
$location = Get-ProviderLocation "Microsoft.Network/loadBalancers" "West US"
14021401

14031402
try
14041403
{
@@ -1488,9 +1487,8 @@ function Test-LoadBalancerInboundNatPoolConfigCRUD-PublicLB
14881487
$lbName = Get-ResourceName
14891488
$frontendName = Get-ResourceName
14901489
$inboundNatPoolName = Get-ResourceName
1491-
$rglocation = "West US"
1492-
$resourceTypeParent = "Microsoft.Network/loadBalancers"
1493-
$location = "West US"
1490+
$rglocation = Get-ProviderLocation ResourceManagement "West US"
1491+
$location = Get-ProviderLocation "Microsoft.Network/loadBalancers" "West US"
14941492

14951493
try
14961494
{
@@ -2345,12 +2343,9 @@ function Test-LoadBalancerZones
23452343
$subnetName = Get-ResourceName
23462344
$vnetName = Get-ResourceName
23472345
$frontendName = Get-ResourceName
2348-
23492346
$zones = "1";
23502347
$rglocation = Get-ProviderLocation ResourceManagement
2351-
# TODO: replace hardcoded location
2352-
$resourceTypeParent = "Microsoft.Network/loadBalancers"
2353-
$location = "centralus";
2348+
$location = Get-ProviderLocation "Microsoft.Network/loadBalancers" "Central US"
23542349

23552350
try
23562351
{

src/ResourceManager/Network/Commands.Network.Test/ScenarioTests/NetworkInterfaceTests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -823,9 +823,9 @@ function Test-NetworkInterfaceWithAcceleratedNetworking
823823
$publicIpName = Get-ResourceName
824824
$nicName = Get-ResourceName
825825
$domainNameLabel = Get-ResourceName
826-
$rglocation = "westcentralus"
826+
$rglocation = Get-ProviderLocation ResourceManagement "West Central US"
827827
$resourceTypeParent = "Microsoft.Network/networkInterfaces"
828-
$location = "westcentralus"
828+
$location = Get-ProviderLocation $resourceTypeParent "West Central US"
829829

830830
try
831831
{

0 commit comments

Comments
 (0)