|
1 |
| -param( |
| 1 | +param ( |
2 | 2 | [Parameter(Mandatory)]
|
3 | 3 | [ValidateScript({ Test-Path -LiteralPath $_ -PathType Container })]
|
4 | 4 | [string] $RepoLocation
|
5 | 5 | )
|
6 | 6 |
|
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 |
11 | 8 |
|
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 |
19 | 16 |
|
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 |
23 | 24 | }
|
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 | + } |
33 | 50 | }
|
| 51 | + |
| 52 | +ImportLocalAzModules |
0 commit comments