Skip to content

Commit f31c167

Browse files
author
Maddie Clayton
authored
Merge branch 'dev' into CRT
2 parents a4c44d1 + 960afe5 commit f31c167

File tree

1 file changed

+62
-55
lines changed

1 file changed

+62
-55
lines changed

src/ScenarioTest.ResourceManager/Common.ps1

Lines changed: 62 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ function Run-Test
7979
Write-Log "[run-test]: Running test without file comparison"
8080
}
8181

82-
$oldPref = $ErrorActionPreference
82+
$oldPref = $ErrorActionPreference
8383
$ErrorActionPreference = "SilentlyContinue"
84-
#Start-Transcript -Path $transFile
84+
#Start-Transcript -Path $transFile
8585
$success = $false;
8686
$ErrorActionPreference = $oldPref
8787
try
@@ -92,7 +92,7 @@ function Run-Test
9292
finally
9393
{
9494
Test-Cleanup
95-
$oldPref = $ErrorActionPreference
95+
$oldPref = $ErrorActionPreference
9696
$ErrorActionPreference = "SilentlyContinue"
9797
#Stop-Transcript
9898
$ErrorActionPreference = $oldPref
@@ -406,7 +406,7 @@ function getTestName
406406
}
407407
}
408408

409-
return $testName
409+
return $testName
410410
}
411411

412412
<#
@@ -479,7 +479,7 @@ function getTestCredentialFromString
479479
if (-not ($parsedString.ContainsKey([Microsoft.Azure.Test.TestEnvironment]::UserIdKey) -or ((-not ($parsedString.ContainsKey([Microsoft.Azure.Test.TestEnvironment]::AADPasswordKey))))))
480480
{
481481
throw "The connection string '$connectionString' must have a valid value, including username and password " +`
482-
"in the following format: SubscriptionId=<subscription>;UserName=<username>;Password=<password>"
482+
"in the following format: SubscriptionId=<subscription>;UserName=<username>;Password=<password>"
483483
}
484484
return $(createTestCredential $parsedString[[Microsoft.Azure.Test.TestEnvironment]::UserIdKey] $parsedString[[Microsoft.Azure.Test.TestEnvironment]::AADPasswordKey])
485485
}
@@ -498,7 +498,7 @@ function getSubscriptionFromString
498498
if (-not ($parsedString.ContainsKey([Microsoft.Azure.Test.TestEnvironment]::SubscriptionIdKey)))
499499
{
500500
throw "The connection string '$connectionString' must have a valid value, including subscription " +`
501-
"in the following format: SubscriptionId=<subscription>;UserName=<username>;Password=<password>"
501+
"in the following format: SubscriptionId=<subscription>;UserName=<username>;Password=<password>"
502502
}
503503
return $($parsedString[[Microsoft.Azure.Test.TestEnvironment]::SubscriptionIdKey])
504504
}
@@ -518,22 +518,22 @@ function getCredentialFromEnvironment
518518
{
519519
$environmentVariable = $null;
520520
if ([System.string]::Equals($testEnvironment, "rdfe", [System.StringComparison]::OrdinalIgnoreCase))
521-
{
522-
$environmentVariable = [Microsoft.Azure.Test.RDFETestEnvironmentFactory]::TestOrgIdAuthenticationKey
523-
}
524-
else
525-
{
526-
$environmentVariable = [Microsoft.Azure.Test.CSMTestEnvironmentFactory]::TestCSMOrgIdConnectionStringKey
527-
}
528-
529-
$environmentValue = [System.Environment]::GetEnvironmentVariable($environmentVariable)
530-
if ([System.string]::IsNullOrEmpty($environmentValue))
531-
{
532-
throw "The environment variable '$environmentVariable' must have a valid value, including username and password " +`
533-
"in the following format: $environmentVariable=SubscriptionId=<subscription>;UserName=<username>;Password=<password>"
534-
}
535-
536-
$credential = $(getTestCredentialFromString $environmentValue)
521+
{
522+
$environmentVariable = [Microsoft.Azure.Test.RDFETestEnvironmentFactory]::TestOrgIdAuthenticationKey
523+
}
524+
else
525+
{
526+
$environmentVariable = [Microsoft.Azure.Test.CSMTestEnvironmentFactory]::TestCSMOrgIdConnectionStringKey
527+
}
528+
529+
$environmentValue = [System.Environment]::GetEnvironmentVariable($environmentVariable)
530+
if ([System.string]::IsNullOrEmpty($environmentValue))
531+
{
532+
throw "The environment variable '$environmentVariable' must have a valid value, including username and password " +`
533+
"in the following format: $environmentVariable=SubscriptionId=<subscription>;UserName=<username>;Password=<password>"
534+
}
535+
536+
$credential = $(getTestCredentialFromString $environmentValue)
537537
}
538538

539539
return $credential
@@ -555,22 +555,22 @@ function getSubscriptionFromEnvironment
555555
{
556556
$environmentVariable = $null;
557557
if ([System.string]::Equals($testEnvironment, "rdfe", [System.StringComparison]::OrdinalIgnoreCase))
558-
{
559-
$environmentVariable = [Microsoft.Azure.Test.RDFETestEnvironmentFactory]::TestOrgIdAuthenticationKey
560-
}
561-
else
562-
{
563-
$environmentVariable = [Microsoft.Azure.Test.CSMTestEnvironmentFactory]::TestCSMOrgIdConnectionStringKey
564-
}
565-
566-
$environmentValue = [System.Environment]::GetEnvironmentVariable($environmentVariable)
567-
if ([System.string]::IsNullOrEmpty($environmentValue))
568-
{
569-
throw "The environment variable '$environmentVariable' must have a valid value, including subscription id" +`
570-
"in the following format: $environmentVariable=SubscriptionId=<subscription>;UserName=<username>;Password=<password>"
571-
}
572-
573-
$subscription = $(getSubscriptionFromString $environmentValue)
558+
{
559+
$environmentVariable = [Microsoft.Azure.Test.RDFETestEnvironmentFactory]::TestOrgIdAuthenticationKey
560+
}
561+
else
562+
{
563+
$environmentVariable = [Microsoft.Azure.Test.CSMTestEnvironmentFactory]::TestCSMOrgIdConnectionStringKey
564+
}
565+
566+
$environmentValue = [System.Environment]::GetEnvironmentVariable($environmentVariable)
567+
if ([System.string]::IsNullOrEmpty($environmentValue))
568+
{
569+
throw "The environment variable '$environmentVariable' must have a valid value, including subscription id" +`
570+
"in the following format: $environmentVariable=SubscriptionId=<subscription>;UserName=<username>;Password=<password>"
571+
}
572+
573+
$subscription = $(getSubscriptionFromString $environmentValue)
574574
}
575575
else
576576
{
@@ -582,49 +582,56 @@ function getSubscriptionFromEnvironment
582582

583583
function Get-Location
584584
{
585-
param([string]$providerNamespace, [string]$resourceType, [string]$preferredLocation)
585+
param([string]$providerNamespace, [string]$resourceType, [string]$preferredLocation, [switch]$UseCanonical)
586586
$provider = Get-AzureRmResourceProvider -ProviderNamespace $providerNamespace
587587
$resourceTypes = $null
588588
if ( ( $provider.ResourceTypes -ne $null ) -and ( $provider.ResourceTypes.Count -gt 0 ) )
589589
{
590590
$nameFound = $provider.ResourceTypes[0]| Get-Member | Where-Object { $_.Name -eq "Name" }
591591
$resourceTypeNameFound = $provider.ResourceTypes[0]| Get-Member | Where-Object { $_.Name -eq "ResourceTypeName" }
592592
if ( $nameFound -ne $null )
593-
{
594-
$resourceTypes = $provider.ResourceTypes | Where-Object { $_.Name -eq $resourceType }
593+
{
594+
$resourceTypes = $provider.ResourceTypes | Where-Object { $_.Name -eq $resourceType }
595595
}
596-
elseif ( $resourceTypeNameFound -ne $null )
596+
elseif ( $resourceTypeNameFound -ne $null )
597597
{
598598
$resourceTypes = $provider.ResourceTypes | Where-Object { $_.ResourceTypeName -eq $resourceType }
599599
}
600-
else
601-
{
600+
else
601+
{
602602
$resourceTypes = $provider.ResourceTypes | Where-Object { $_.ResourceType -eq $resourceType }
603603
}
604604
}
605-
$location = $resourceTypes.Locations | Where-Object { $_ -eq $preferredLocation }
605+
$locations = $resourceTypes.Locations
606+
if($UseCanonical)
607+
{
608+
$locations = $locations | ForEach-Object { Normalize-Location $_ }
609+
}
610+
$location = $locations | Where-Object { $_ -eq $preferredLocation }
606611
if ($location -eq $null)
607612
{
608-
if ($resourceTypes.Locations.Length -ne 0)
613+
if ($locations.Count -ne 0)
609614
{
610-
return $resourceTypes.Locations[0]
615+
return $locations[0]
611616
}
612-
else
617+
else
613618
{
614-
return "West US"
619+
$defaultLocation = "West US"
620+
if($UseCanonical)
621+
{
622+
$defaultLocation = "westus"
623+
}
624+
return $defaultLocation
615625
}
616626
}
617-
else
627+
else
618628
{
619629
return $location
620630
}
621631
}
622632

623633
function Normalize-Location
624634
{
625-
param([string]$location)
626-
$outputLocation = $location.ToLower()
627-
$outputLocation = $outputLocation -replace '\s', ''
628-
$outputLocation = $outputLocation -replace '-', ''
629-
$outputLocation = $outputLocation -replace '_', ''
635+
param([string]$location)
636+
return $location.ToLower() -replace '[^a-z0-9]'
630637
}

0 commit comments

Comments
 (0)