Skip to content

Commit ccb7258

Browse files
author
shicwu
committed
add get-providerlocation to only choose available locations
1 parent 2823089 commit ccb7258

File tree

8 files changed

+1857
-1278
lines changed

8 files changed

+1857
-1278
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,35 @@ function Get-ElasticPoolName
182182
return getAssetName
183183
}
184184

185+
<#
186+
.SYNOPSIS
187+
Gets the location for a provider, if not found return East US
188+
#>
189+
function Get-ProviderLocation($provider)
190+
{
191+
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
192+
{
193+
$namespace = $provider.Split("/")[0]
194+
if($provider.Contains("/"))
195+
{
196+
$type = $provider.Substring($namespace.Length + 1)
197+
$location = Get-AzureRmResourceProvider -ProviderNamespace $namespace | where {$_.ResourceTypes[0].ResourceTypeName -eq $type}
198+
199+
if ($location -eq $null)
200+
{
201+
return "East US"
202+
} else
203+
{
204+
return $location.Locations[0]
205+
}
206+
}
207+
208+
return "East US"
209+
}
210+
211+
return "East US"
212+
}
213+
185214
<#
186215
.SYNOPSIS
187216
Creates a resource group for tests

src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/DatabaseBackupStretchTests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
function Test-ListStretchDatabaseRestorePoints
2020
{
2121
# Setup
22-
$location = "Japan East"
22+
$location = Get-ProviderLocation "Microsoft.Sql/servers"
2323
$serverVersion = "12.0";
24-
$rg = Create-ResourceGroupForTest
24+
$rg = Create-ResourceGroupForTest $location
2525

2626
try
2727
{

src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/DatabaseCrudStretchTests.ps1

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
#>
1919
function Test-CreateStretchDatabase
2020
{
21-
Test-CreateDatabaseInternal "12.0" "Southeast Asia"
21+
$rplocation = Get-ProviderLocation "Microsoft.Sql/servers"
22+
Test-CreateDatabaseInternal "12.0" $rplocation
2223
}
2324

2425
<#
@@ -28,7 +29,7 @@ function Test-CreateStretchDatabase
2829
function Test-CreateDatabaseInternal ($serverVersion, $location = "Japan East")
2930
{
3031
# Setup
31-
$rg = Create-ResourceGroupForTest
32+
$rg = Create-ResourceGroupForTest $location
3233
$server = Create-ServerForTest $rg $serverVersion $location
3334

3435
try
@@ -57,7 +58,8 @@ function Test-CreateDatabaseInternal ($serverVersion, $location = "Japan East")
5758
#>
5859
function Test-UpdateStretchDatabase
5960
{
60-
Test-UpdateDatabaseInternal "12.0" "Southeast Asia"
61+
$rplocation = Get-ProviderLocation "Microsoft.Sql/servers"
62+
Test-UpdateDatabaseInternal "12.0" $rplocation
6163
}
6264

6365
<#
@@ -67,7 +69,7 @@ function Test-UpdateStretchDatabase
6769
function Test-UpdateDatabaseInternal ($serverVersion, $location = "Japan East")
6870
{
6971
# Setup
70-
$rg = Create-ResourceGroupForTest
72+
$rg = Create-ResourceGroupForTest $location
7173
$server = Create-ServerForTest $rg $serverVersion $location
7274
try {
7375
# Create stretch database
@@ -99,7 +101,8 @@ function Test-UpdateDatabaseInternal ($serverVersion, $location = "Japan East")
99101
#>
100102
function Test-GetStretchDatabase
101103
{
102-
Test-GetDatabaseInternal "12.0" "Southeast Asia"
104+
$rplocation = Get-ProviderLocation "Microsoft.Sql/servers"
105+
Test-GetDatabaseInternal "12.0" $rplocation
103106
}
104107

105108
<#
@@ -109,7 +112,7 @@ function Test-GetStretchDatabase
109112
function Test-GetDatabaseInternal ($serverVersion, $location = "Japan East")
110113
{
111114
# Setup
112-
$rg = Create-ResourceGroupForTest
115+
$rg = Create-ResourceGroupForTest $location
113116
$server = Create-ServerForTest $rg $serverVersion $location
114117

115118
try
@@ -142,7 +145,8 @@ function Test-GetDatabaseInternal ($serverVersion, $location = "Japan East")
142145
#>
143146
function Test-RemoveStretchDatabase
144147
{
145-
Test-RemoveDatabaseInternal "12.0" "Southeast Asia"
148+
$rplocation = Get-ProviderLocation "Microsoft.Sql/servers"
149+
Test-RemoveDatabaseInternal "12.0" $rplocation
146150
}
147151

148152
<#
@@ -152,7 +156,7 @@ function Test-RemoveStretchDatabase
152156
function Test-RemoveDatabaseInternal ($serverVersion, $location = "Japan East")
153157
{
154158
# Setup
155-
$rg = Create-ResourceGroupForTest
159+
$rg = Create-ResourceGroupForTest $location
156160
$server = Create-ServerForTest $rg $serverVersion $location
157161

158162
try

src/ResourceManager/Sql/Commands.Sql.Test/SessionRecords/Microsoft.Azure.Commands.Sql.Test.ScenarioTests.DatabaseBackupStretchTests/TestStretchDatabaseListRestorePoints.json

Lines changed: 281 additions & 287 deletions
Large diffs are not rendered by default.

src/ResourceManager/Sql/Commands.Sql.Test/SessionRecords/Microsoft.Azure.Commands.Sql.Test.ScenarioTests.DatabaseCrudStretchTests/TestStretchDatabaseCreate.json

Lines changed: 318 additions & 216 deletions
Large diffs are not rendered by default.

src/ResourceManager/Sql/Commands.Sql.Test/SessionRecords/Microsoft.Azure.Commands.Sql.Test.ScenarioTests.DatabaseCrudStretchTests/TestStretchDatabaseGet.json

Lines changed: 452 additions & 215 deletions
Large diffs are not rendered by default.

src/ResourceManager/Sql/Commands.Sql.Test/SessionRecords/Microsoft.Azure.Commands.Sql.Test.ScenarioTests.DatabaseCrudStretchTests/TestStretchDatabaseRemove.json

Lines changed: 390 additions & 225 deletions
Large diffs are not rendered by default.

src/ResourceManager/Sql/Commands.Sql.Test/SessionRecords/Microsoft.Azure.Commands.Sql.Test.ScenarioTests.DatabaseCrudStretchTests/TestStretchDatabaseUpdate.json

Lines changed: 373 additions & 325 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)