Skip to content

Updated the script for local test and added a new parameter to specif… #20708

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .azure-pipelines/live-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ schedules:
branches:
include:
- shared/livetest
always: true

pr: none
trigger: none
Expand Down
67 changes: 43 additions & 24 deletions tools/TestFx/Live/DebugLocalLiveTestScenarios.ps1
Original file line number Diff line number Diff line change
@@ -1,33 +1,52 @@
param(
param (
[Parameter(Mandatory)]
[ValidateScript({ Test-Path -LiteralPath $_ -PathType Container })]
[string] $RepoLocation
)

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

Write-Host "Importing Az.Accounts." -ForegroundColor Green
Import-Module (Join-Path -Path $accountsModuleDirectory -ChildPath "Az.Accounts.psd1")
Get-ChildItem -Path $debugDirectory -Directory -Exclude "Az.Accounts" | Get-ChildItem -File -Filter "*.psd1" | ForEach-Object {
Write-Host "Importing $($_.FullName)." -ForegroundColor Green
Import-Module $_.FullName -Force
}
Write-Host "Successfully imported Azure PowerShell modules from artifacts/Debug" -ForegroundColor Green
function ImportLocalAzModules {
param ()

$debugDirectory = Join-Path -Path $script:LocalRepoLocation -ChildPath "artifacts" | Join-Path -ChildPath "Debug"
$accountsModuleDirectory = Join-Path -Path $debugDirectory -ChildPath "Az.Accounts"
Write-Host "Start to import Azure PowerShell modules from artifacts/Debug." -ForegroundColor Green
Write-Host "If you see module import issue, please restart the PowerShell host." -ForegroundColor Magenta

$dataLocation = (Get-AzConfig -TestCoverageLocation).Value
if ([string]::IsNullOrWhiteSpace($dataLocation) -or !(Test-Path -LiteralPath $dataLocation -PathType Container)) {
$dataLocation = Join-Path -Path $env:USERPROFILE -ChildPath ".Azure"
Write-Host "Importing Az.Accounts." -ForegroundColor Green
Import-Module (Join-Path -Path $accountsModuleDirectory -ChildPath "Az.Accounts.psd1")
Get-ChildItem -Path $debugDirectory -Directory -Exclude "Az.Accounts" | Get-ChildItem -File -Filter "*.psd1" | ForEach-Object {
Write-Host "Importing $($_.FullName)." -ForegroundColor Green
Import-Module $_.FullName -Force
}
Write-Host "Successfully imported Azure PowerShell modules from artifacts/Debug" -ForegroundColor Green
}
Write-Host "Data location is `"$dataLocation`"" -ForegroundColor Cyan

$srcDir = Join-Path -Path $RepoLocation -ChildPath "src"
$liveScenarios = Get-ChildItem -Path $srcDir -Recurse -Directory -Filter "LiveTests" | Get-ChildItem -Filter "TestLiveScenarios.ps1" -File
$liveScenarios | ForEach-Object {
$moduleName = [regex]::match($_.FullName, "[\\|\/]src[\\|\/](?<ModuleName>[a-zA-Z]+)[\\|\/]").Groups["ModuleName"].Value
Import-Module "./tools/TestFx/Assert.ps1" -Force
Import-Module "./tools/TestFx/Live/LiveTestUtility.psd1" -ArgumentList $moduleName, "LocalDebug", "LocalDebug", "LocalDebug", $dataLocation -Force
. $_.FullName

function InvokeLocalLiveTestScenarios {
param (
[Parameter()]
[ValidateNotNullOrEmpty()]
[string[]] $TargetModules
)

$dataLocation = (Get-AzConfig -TestCoverageLocation).Value
if ([string]::IsNullOrWhiteSpace($dataLocation) -or !(Test-Path -LiteralPath $dataLocation -PathType Container)) {
$dataLocation = Join-Path -Path $env:USERPROFILE -ChildPath ".Azure"
}
Write-Host "Data location is `"$dataLocation`"" -ForegroundColor Cyan

$srcDir = Join-Path -Path $script:LocalRepoLocation -ChildPath "src"
$liveScenarios = Get-ChildItem -Path $srcDir -Recurse -Directory -Filter "LiveTests" | Get-ChildItem -Filter "TestLiveScenarios.ps1" -File
$liveScenarios | ForEach-Object {
$moduleName = [regex]::match($_.FullName, "[\\|\/]src[\\|\/](?<ModuleName>[a-zA-Z]+)[\\|\/]").Groups["ModuleName"].Value
if (!$PSBoundParameters.ContainsKey("TargetModules") -or $moduleName -in $TargetModules) {
Write-Host "Executing live test scenarios for module $moduleName" -ForegroundColor Cyan
Import-Module "./tools/TestFx/Assert.ps1" -Force
Import-Module "./tools/TestFx/Live/LiveTestUtility.psd1" -ArgumentList $moduleName, "LocalDebug", "LocalDebug", "LocalDebug", $dataLocation -Force
. $_.FullName
}
}
}

ImportLocalAzModules