Skip to content

Commit 49459fb

Browse files
authored
Shared/livetest (#21052)
* Added live test cases for Network and DNS * Added live test cases for modules Automation, Databricks and Functions Added more detailed error info and enabled Debug preference during the last retry * Updated live test to make it support no built-in resource group
1 parent 8a45596 commit 49459fb

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

tools/TestFx/Live/LiveTestUtility.psm1

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ function Invoke-LiveTestCommand {
215215
}
216216

217217
function Invoke-LiveTestScenario {
218-
[CmdletBinding()]
218+
[CmdletBinding(DefaultParameterSetName = "HasDefaultResourceGroup")]
219219
[OutputType([bool])]
220220
param (
221221
[Parameter(Mandatory, Position = 0)]
@@ -226,10 +226,13 @@ function Invoke-LiveTestScenario {
226226
[ValidateNotNullOrEmpty()]
227227
[string] $Description,
228228

229-
[Parameter()]
229+
[Parameter(ParameterSetName = "HasDefaulResourceGroup")]
230230
[ValidateNotNullOrEmpty()]
231231
[string] $ResourceGroupLocation,
232232

233+
[Parameter(ParameterSetName = "HasNoDefaultResourceGroup")]
234+
[switch] $NoResourceGroup,
235+
233236
[Parameter(Mandatory)]
234237
[ValidateNotNullOrEmpty()]
235238
[scriptblock] $ScenarioScript
@@ -256,32 +259,34 @@ function Invoke-LiveTestScenario {
256259
Errors = ""
257260
}
258261

259-
$snrResourceGroupName = New-LiveTestResourceGroupName
260-
$snrResourceGroupLocation = "westus"
261-
if ($PSBoundParameters.ContainsKey("ResourceGroupLocation")) {
262-
$snrResourceGroupLocation = $ResourceGroupLocation
263-
}
262+
if (!$NoResourceGroup.IsPresent) {
263+
$snrResourceGroupName = New-LiveTestResourceGroupName
264+
$snrResourceGroupLocation = "westus"
265+
if ($PSBoundParameters.ContainsKey("ResourceGroupLocation")) {
266+
$snrResourceGroupLocation = $ResourceGroupLocation
267+
}
264268

265-
Write-Host "##[section]Start to create a resource group." -ForegroundColor Green
266-
Write-Host "##[section]Resource group name: $snrResourceGroupName" -ForegroundColor Green
267-
Write-Host "##[section]Resource group location: $snrResourceGroupLocation" -ForegroundColor Green
269+
Write-Host "##[section]Start to create a resource group." -ForegroundColor Green
270+
Write-Host "##[section]Resource group name: $snrResourceGroupName" -ForegroundColor Green
271+
Write-Host "##[section]Resource group location: $snrResourceGroupLocation" -ForegroundColor Green
268272

269-
$snrResourceGroup = New-LiveTestResourceGroup -Name $snrResourceGroupName -Location $snrResourceGroupLocation
273+
$snrResourceGroup = New-LiveTestResourceGroup -Name $snrResourceGroupName -Location $snrResourceGroupLocation
270274

271-
Write-Host "##[section]Successfully created the resource group." -ForegroundColor Green
275+
Write-Host "##[section]Successfully created the resource group." -ForegroundColor Green
276+
}
272277

273278
$snrRetryCount = 0
274279
$snrRetryErrors = @()
275280

276281
do {
277282
try {
283+
$sPrefs = @([psvariable]::new("ErrorActionPreference", "Stop"), [psvariable]::new("ConfirmPreference", "None"))
278284
if ($snrRetryCount -eq $script:ScenarioMaxRetryCount) {
279-
$ScenarioScript.InvokeWithContext($null, @([psvariable]::new("ErrorActionPreference", "Stop"), [psvariable]::new("ConfirmPreference", "None"), [psvariable]::new("DebugPreference", "Continue")), $snrResourceGroup)
280-
}
281-
else {
282-
$ScenarioScript.InvokeWithContext($null, @([psvariable]::new("ErrorActionPreference", "Stop"), [psvariable]::new("ConfirmPreference", "None")), $snrResourceGroup)
285+
$prefs += [psvariable]::new("DebugPreference", "Continue")
283286
}
284287

288+
$ScenarioScript.InvokeWithContext($null, $prefs, $snrResourceGroup)
289+
285290
Write-Host "##[section]Successfully executed the live scenario `"$Name`"." -ForegroundColor Green
286291
break
287292
}
@@ -346,7 +351,10 @@ function Invoke-LiveTestScenario {
346351
$snrCsvData.Errors = ConvertToLiveTestJsonErrors -Errors $snrErrorMessage
347352
}
348353
finally {
349-
if ($null -ne $snrResourceGroup) {
354+
$snrCsvData.EndDateTime = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss")
355+
$snrCsvData | Export-Csv -LiteralPath $script:LiveTestRawCsvFile -Encoding utf8 -NoTypeInformation -Append
356+
357+
if (!$NoResourceGroup.IsPresent -and $null -ne $snrResourceGroup) {
350358
try {
351359
Write-Host "##[section]Start to clean up the resource group `"$snrResourceGroupName`"." -ForegroundColor Green
352360
Clear-LiveTestResources -Name $snrResourceGroupName
@@ -355,8 +363,6 @@ function Invoke-LiveTestScenario {
355363
# Ignore exception for clean up
356364
}
357365
}
358-
$snrCsvData.EndDateTime = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss")
359-
$snrCsvData | Export-Csv -LiteralPath $script:LiveTestRawCsvFile -Encoding utf8 -NoTypeInformation -Append
360366

361367
Write-Host "##[endgroup]"
362368
}

0 commit comments

Comments
 (0)