@@ -79,9 +79,9 @@ function Run-Test
79
79
Write-Log " [run-test]: Running test without file comparison"
80
80
}
81
81
82
- $oldPref = $ErrorActionPreference
82
+ $oldPref = $ErrorActionPreference
83
83
$ErrorActionPreference = " SilentlyContinue"
84
- # Start-Transcript -Path $transFile
84
+ # Start-Transcript -Path $transFile
85
85
$success = $false ;
86
86
$ErrorActionPreference = $oldPref
87
87
try
@@ -92,7 +92,7 @@ function Run-Test
92
92
finally
93
93
{
94
94
Test-Cleanup
95
- $oldPref = $ErrorActionPreference
95
+ $oldPref = $ErrorActionPreference
96
96
$ErrorActionPreference = " SilentlyContinue"
97
97
# Stop-Transcript
98
98
$ErrorActionPreference = $oldPref
@@ -406,7 +406,7 @@ function getTestName
406
406
}
407
407
}
408
408
409
- return $testName
409
+ return $testName
410
410
}
411
411
412
412
<#
@@ -479,7 +479,7 @@ function getTestCredentialFromString
479
479
if (-not ($parsedString.ContainsKey ([Microsoft.Azure.Test.TestEnvironment ]::UserIdKey) -or ((-not ($parsedString.ContainsKey ([Microsoft.Azure.Test.TestEnvironment ]::AADPasswordKey))))))
480
480
{
481
481
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>"
483
483
}
484
484
return $ (createTestCredential $parsedString [[Microsoft.Azure.Test.TestEnvironment ]::UserIdKey ] $parsedString [[Microsoft.Azure.Test.TestEnvironment ]::AADPasswordKey ])
485
485
}
@@ -498,7 +498,7 @@ function getSubscriptionFromString
498
498
if (-not ($parsedString.ContainsKey ([Microsoft.Azure.Test.TestEnvironment ]::SubscriptionIdKey)))
499
499
{
500
500
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>"
502
502
}
503
503
return $ ($parsedString [[Microsoft.Azure.Test.TestEnvironment ]::SubscriptionIdKey ])
504
504
}
@@ -518,22 +518,22 @@ function getCredentialFromEnvironment
518
518
{
519
519
$environmentVariable = $null ;
520
520
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 )
537
537
}
538
538
539
539
return $credential
@@ -555,22 +555,22 @@ function getSubscriptionFromEnvironment
555
555
{
556
556
$environmentVariable = $null ;
557
557
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 )
574
574
}
575
575
else
576
576
{
@@ -582,49 +582,56 @@ function getSubscriptionFromEnvironment
582
582
583
583
function Get-Location
584
584
{
585
- param ([string ]$providerNamespace , [string ]$resourceType , [string ]$preferredLocation )
585
+ param ([string ]$providerNamespace , [string ]$resourceType , [string ]$preferredLocation , [ switch ] $UseCanonical )
586
586
$provider = Get-AzureRmResourceProvider - ProviderNamespace $providerNamespace
587
587
$resourceTypes = $null
588
588
if ( ( $provider.ResourceTypes -ne $null ) -and ( $provider.ResourceTypes.Count -gt 0 ) )
589
589
{
590
590
$nameFound = $provider.ResourceTypes [0 ]| Get-Member | Where-Object { $_.Name -eq " Name" }
591
591
$resourceTypeNameFound = $provider.ResourceTypes [0 ]| Get-Member | Where-Object { $_.Name -eq " ResourceTypeName" }
592
592
if ( $nameFound -ne $null )
593
- {
594
- $resourceTypes = $provider.ResourceTypes | Where-Object { $_.Name -eq $resourceType }
593
+ {
594
+ $resourceTypes = $provider.ResourceTypes | Where-Object { $_.Name -eq $resourceType }
595
595
}
596
- elseif ( $resourceTypeNameFound -ne $null )
596
+ elseif ( $resourceTypeNameFound -ne $null )
597
597
{
598
598
$resourceTypes = $provider.ResourceTypes | Where-Object { $_.ResourceTypeName -eq $resourceType }
599
599
}
600
- else
601
- {
600
+ else
601
+ {
602
602
$resourceTypes = $provider.ResourceTypes | Where-Object { $_.ResourceType -eq $resourceType }
603
603
}
604
604
}
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 }
606
611
if ($location -eq $null )
607
612
{
608
- if ($resourceTypes .Locations.Length -ne 0 )
613
+ if ($locations .Count -ne 0 )
609
614
{
610
- return $resourceTypes .Locations [0 ]
615
+ return $locations [0 ]
611
616
}
612
- else
617
+ else
613
618
{
614
- return " West US"
619
+ $defaultLocation = " West US"
620
+ if ($UseCanonical )
621
+ {
622
+ $defaultLocation = " westus"
623
+ }
624
+ return $defaultLocation
615
625
}
616
626
}
617
- else
627
+ else
618
628
{
619
629
return $location
620
630
}
621
631
}
622
632
623
633
function Normalize-Location
624
634
{
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]'
630
637
}
0 commit comments