Skip to content

Commit 65ddc9e

Browse files
authored
Updated the script for local test and added a new parameter to specify the desired test modules. (#20708)
1 parent fa02282 commit 65ddc9e

File tree

2 files changed

+44
-24
lines changed

2 files changed

+44
-24
lines changed

.azure-pipelines/live-test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ schedules:
5252
branches:
5353
include:
5454
- shared/livetest
55+
always: true
5556

5657
pr: none
5758
trigger: none
Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,52 @@
1-
param(
1+
param (
22
[Parameter(Mandatory)]
33
[ValidateScript({ Test-Path -LiteralPath $_ -PathType Container })]
44
[string] $RepoLocation
55
)
66

7-
$debugDirectory = Join-Path -Path $RepoLocation -ChildPath "artifacts" | Join-Path -ChildPath "Debug"
8-
$accountsModuleDirectory = Join-Path -Path $debugDirectory -ChildPath "Az.Accounts"
9-
Write-Host "Start to import Azure PowerShell modules from artifacts/Debug." -ForegroundColor Green
10-
Write-Host "If you see module import issue, please restart the PowerShell host." -ForegroundColor Magenta
7+
New-Variable -Name LocalRepoLocation -Value $RepoLocation -Scope Script -Option ReadOnly
118

12-
Write-Host "Importing Az.Accounts." -ForegroundColor Green
13-
Import-Module (Join-Path -Path $accountsModuleDirectory -ChildPath "Az.Accounts.psd1")
14-
Get-ChildItem -Path $debugDirectory -Directory -Exclude "Az.Accounts" | Get-ChildItem -File -Filter "*.psd1" | ForEach-Object {
15-
Write-Host "Importing $($_.FullName)." -ForegroundColor Green
16-
Import-Module $_.FullName -Force
17-
}
18-
Write-Host "Successfully imported Azure PowerShell modules from artifacts/Debug" -ForegroundColor Green
9+
function ImportLocalAzModules {
10+
param ()
11+
12+
$debugDirectory = Join-Path -Path $script:LocalRepoLocation -ChildPath "artifacts" | Join-Path -ChildPath "Debug"
13+
$accountsModuleDirectory = Join-Path -Path $debugDirectory -ChildPath "Az.Accounts"
14+
Write-Host "Start to import Azure PowerShell modules from artifacts/Debug." -ForegroundColor Green
15+
Write-Host "If you see module import issue, please restart the PowerShell host." -ForegroundColor Magenta
1916

20-
$dataLocation = (Get-AzConfig -TestCoverageLocation).Value
21-
if ([string]::IsNullOrWhiteSpace($dataLocation) -or !(Test-Path -LiteralPath $dataLocation -PathType Container)) {
22-
$dataLocation = Join-Path -Path $env:USERPROFILE -ChildPath ".Azure"
17+
Write-Host "Importing Az.Accounts." -ForegroundColor Green
18+
Import-Module (Join-Path -Path $accountsModuleDirectory -ChildPath "Az.Accounts.psd1")
19+
Get-ChildItem -Path $debugDirectory -Directory -Exclude "Az.Accounts" | Get-ChildItem -File -Filter "*.psd1" | ForEach-Object {
20+
Write-Host "Importing $($_.FullName)." -ForegroundColor Green
21+
Import-Module $_.FullName -Force
22+
}
23+
Write-Host "Successfully imported Azure PowerShell modules from artifacts/Debug" -ForegroundColor Green
2324
}
24-
Write-Host "Data location is `"$dataLocation`"" -ForegroundColor Cyan
25-
26-
$srcDir = Join-Path -Path $RepoLocation -ChildPath "src"
27-
$liveScenarios = Get-ChildItem -Path $srcDir -Recurse -Directory -Filter "LiveTests" | Get-ChildItem -Filter "TestLiveScenarios.ps1" -File
28-
$liveScenarios | ForEach-Object {
29-
$moduleName = [regex]::match($_.FullName, "[\\|\/]src[\\|\/](?<ModuleName>[a-zA-Z]+)[\\|\/]").Groups["ModuleName"].Value
30-
Import-Module "./tools/TestFx/Assert.ps1" -Force
31-
Import-Module "./tools/TestFx/Live/LiveTestUtility.psd1" -ArgumentList $moduleName, "LocalDebug", "LocalDebug", "LocalDebug", $dataLocation -Force
32-
. $_.FullName
25+
26+
function InvokeLocalLiveTestScenarios {
27+
param (
28+
[Parameter()]
29+
[ValidateNotNullOrEmpty()]
30+
[string[]] $TargetModules
31+
)
32+
33+
$dataLocation = (Get-AzConfig -TestCoverageLocation).Value
34+
if ([string]::IsNullOrWhiteSpace($dataLocation) -or !(Test-Path -LiteralPath $dataLocation -PathType Container)) {
35+
$dataLocation = Join-Path -Path $env:USERPROFILE -ChildPath ".Azure"
36+
}
37+
Write-Host "Data location is `"$dataLocation`"" -ForegroundColor Cyan
38+
39+
$srcDir = Join-Path -Path $script:LocalRepoLocation -ChildPath "src"
40+
$liveScenarios = Get-ChildItem -Path $srcDir -Recurse -Directory -Filter "LiveTests" | Get-ChildItem -Filter "TestLiveScenarios.ps1" -File
41+
$liveScenarios | ForEach-Object {
42+
$moduleName = [regex]::match($_.FullName, "[\\|\/]src[\\|\/](?<ModuleName>[a-zA-Z]+)[\\|\/]").Groups["ModuleName"].Value
43+
if (!$PSBoundParameters.ContainsKey("TargetModules") -or $moduleName -in $TargetModules) {
44+
Write-Host "Executing live test scenarios for module $moduleName" -ForegroundColor Cyan
45+
Import-Module "./tools/TestFx/Assert.ps1" -Force
46+
Import-Module "./tools/TestFx/Live/LiveTestUtility.psd1" -ArgumentList $moduleName, "LocalDebug", "LocalDebug", "LocalDebug", $dataLocation -Force
47+
. $_.FullName
48+
}
49+
}
3350
}
51+
52+
ImportLocalAzModules

0 commit comments

Comments
 (0)