|
1 | 1 | param (
|
2 | 2 | [Parameter(Mandatory)]
|
3 |
| - [ValidateScript({ Test-Path -LiteralPath $_ -PathType Container })] |
4 |
| - [string] $RepoLocation, |
| 3 | + [ValidateNotNullOrEmpty()] |
| 4 | + [string] $BuildId, |
5 | 5 |
|
6 |
| - [Parameter()] |
7 |
| - [switch] $DebugMode |
8 |
| -) |
| 6 | + [Parameter(Mandatory)] |
| 7 | + [ValidateNotNullOrEmpty()] |
| 8 | + [string] $OSVersion, |
9 | 9 |
|
10 |
| -dynamicparam { |
11 |
| - if (!$DebugMode.IsPresent) { |
12 |
| - $dynParams = [Management.Automation.RuntimeDefinedParameterDictionary]::new() |
13 |
| - $paramBuildId = [Management.Automation.RuntimeDefinedParameter]::new( |
14 |
| - "BuildId", |
15 |
| - [string], |
16 |
| - [Attribute[]]@( |
17 |
| - [Parameter]@{ Mandatory = $true } |
18 |
| - [ValidateNotNullOrEmpty]::new() |
19 |
| - ) |
20 |
| - ) |
21 |
| - $paramOSVersion = [Management.Automation.RuntimeDefinedParameter]::new( |
22 |
| - "OSVersion", |
23 |
| - [string], |
24 |
| - [Attribute[]]@( |
25 |
| - [Parameter]@{ Mandatory = $true } |
26 |
| - [ValidateNotNullOrEmpty]::new() |
27 |
| - ) |
28 |
| - ) |
29 |
| - $paramPSVersion = [Management.Automation.RuntimeDefinedParameter]::new( |
30 |
| - "PSVersion", |
31 |
| - [string], |
32 |
| - [Attribute[]]@( |
33 |
| - [Parameter]@{ Mandatory = $true } |
34 |
| - [ValidateNotNullOrEmpty]::new() |
35 |
| - ) |
36 |
| - ) |
37 |
| - $dynParams.Add($paramBuildId.Name, $paramBuildId) |
38 |
| - $dynParams.Add($paramOSVersion.Name, $paramOSVersion) |
39 |
| - $dynParams.Add($paramPSVersion.Name, $paramPSVersion) |
40 |
| - $dynParams |
41 |
| - } |
42 |
| -} |
| 10 | + [Parameter(Mandatory)] |
| 11 | + [ValidateNotNullOrEmpty()] |
| 12 | + [string] $PSVersion, |
| 13 | + |
| 14 | + [Parameter(Mandatory)] |
| 15 | + [ValidateScript({ Test-Path -LiteralPath $_ -PathType Container })] |
| 16 | + [string] $RepoLocation |
| 17 | +) |
43 | 18 |
|
44 |
| -process { |
45 |
| - function FillLiveTestCoverageAdditionalInfo { |
46 |
| - [CmdletBinding()] |
47 |
| - param ( |
48 |
| - [Parameter(Mandatory)] |
49 |
| - [ValidateScript({ Test-Path -LiteralPath $_ -PathType Container })] |
50 |
| - [string] $TestCoverageDataLocation, |
| 19 | +function FillLiveTestCoverageAdditionalInfo { |
| 20 | + [CmdletBinding()] |
| 21 | + param ( |
| 22 | + [Parameter(Mandatory)] |
| 23 | + [ValidateScript({ Test-Path -LiteralPath $_ -PathType Container })] |
| 24 | + [string] $TestCoverageDataLocation, |
51 | 25 |
|
52 |
| - [Parameter(Mandatory)] |
53 |
| - [ValidateNotNullOrEmpty()] |
54 |
| - [string] $BuildId, |
| 26 | + [Parameter(Mandatory)] |
| 27 | + [ValidateNotNullOrEmpty()] |
| 28 | + [string] $BuildId, |
55 | 29 |
|
56 |
| - [Parameter(Mandatory)] |
57 |
| - [ValidateNotNullOrEmpty()] |
58 |
| - [string] $OSVersion, |
| 30 | + [Parameter(Mandatory)] |
| 31 | + [ValidateNotNullOrEmpty()] |
| 32 | + [string] $OSVersion, |
59 | 33 |
|
60 |
| - [Parameter(Mandatory)] |
61 |
| - [ValidateNotNullOrEmpty()] |
62 |
| - [string] $PSVersion, |
| 34 | + [Parameter(Mandatory)] |
| 35 | + [ValidateNotNullOrEmpty()] |
| 36 | + [string] $PSVersion, |
63 | 37 |
|
64 |
| - [Parameter(Mandatory)] |
65 |
| - [ValidateNotNullOrEmpty()] |
66 |
| - [string] $ModuleName |
67 |
| - ) |
| 38 | + [Parameter(Mandatory)] |
| 39 | + [ValidateNotNullOrEmpty()] |
| 40 | + [string] $ModuleName |
| 41 | + ) |
68 | 42 |
|
69 |
| - $testCoverageUtility = $PSScriptRoot | Split-Path | Join-Path -ChildPath "Coverage" | Join-Path -ChildPath "TestCoverageUtility.psd1" |
70 |
| - Import-Module $testCoverageUtility |
71 |
| - $module = Get-Module -Name "Az.$ModuleName" -ListAvailable |
72 |
| - $moduleDetails = Get-TestCoverageModuleDetails -Module $module |
| 43 | + $testCoverageUtility = $PSScriptRoot | Split-Path | Join-Path -ChildPath "Coverage" | Join-Path -ChildPath "TestCoverageUtility.psd1" |
| 44 | + Import-Module $testCoverageUtility -Force |
| 45 | + $module = Get-Module -Name "Az.$ModuleName" -ListAvailable |
| 46 | + $moduleDetails = Get-TestCoverageModuleDetails -Module $module |
73 | 47 |
|
74 |
| - $testCoverageRawCsv = Join-Path -Path $TestCoverageDataLocation -ChildPath "TestCoverageAnalysis" | Join-Path -ChildPath "Raw" | Join-Path -ChildPath "Az.$ModuleName.csv" |
| 48 | + $testCoverageRawCsv = Join-Path -Path $TestCoverageDataLocation -ChildPath "TestCoverageAnalysis" | Join-Path -ChildPath "Raw" | Join-Path -ChildPath "Az.$ModuleName.csv" |
| 49 | + if (Test-Path -LiteralPath $testCoverageRawCsv -PathType Leaf) { |
75 | 50 | (Import-Csv -LiteralPath $testCoverageRawCsv) |
|
76 |
| - Select-Object @{ Name = "BuildId"; Expression = { "$BuildId" } }, ` |
77 |
| - @{ Name = "OSVersion"; Expression = { "$OSVersion" } }, ` |
78 |
| - @{ Name = "PSVersion"; Expression = { "$PSVersion" } }, ` |
79 |
| - @{ Name = "Module"; Expression = { "$ModuleName" } }, ` |
80 |
| - "CommandName", @{ Name = "TotalCommands"; Expression = { "$($moduleDetails['TotalCommands'])" } }, ` |
81 |
| - "ParameterSetName", @{ Name = "TotalParameterSets"; Expression = { "$($moduleDetails['TotalParameterSets'])" } }, ` |
82 |
| - "Parameters", @{ Name = "TotalParameters"; Expression = { "$($moduleDetails['TotalParameters'])" } }, ` |
83 |
| - "SourceScript", "LineNumber", "StartDateTime", "EndDateTime", "IsSuccess" | |
| 51 | + Select-Object ` |
| 52 | + @{ Name = "Source"; Expression = { "LiveTest" } }, ` |
| 53 | + @{ Name = "BuildId"; Expression = { "$BuildId" } }, ` |
| 54 | + @{ Name = "OSVersion"; Expression = { "$OSVersion" } }, ` |
| 55 | + @{ Name = "PSVersion"; Expression = { "$PSVersion" } }, ` |
| 56 | + @{ Name = "Module"; Expression = { "$ModuleName" } }, ` |
| 57 | + @{ Name = "CommandName"; Expression = { $_.CommandName } }, ` |
| 58 | + @{ Name = "TotalCommands"; Expression = { "$($moduleDetails['TotalCommands'])" } }, ` |
| 59 | + @{ Name = "ParameterSetName"; Expression = { $_.ParameterSetName } }, ` |
| 60 | + @{ Name = "TotalParameterSets"; Expression = { "$($moduleDetails['TotalParameterSets'])" } }, ` |
| 61 | + @{ Name = "Parameters"; Expression = { $_.Parameters } }, ` |
| 62 | + @{ Name = "TotalParameters"; Expression = { "$($moduleDetails['TotalParameters'])" } }, ` |
| 63 | + @{ Name = "SourceScript"; Expression = { $_.SourceScript } }, ` |
| 64 | + @{ Name = "LineNumber"; Expression = { $_.LineNumber } }, ` |
| 65 | + @{ Name = "StartDateTime"; Expression = { $_.StartDateTime } }, ` |
| 66 | + @{ Name = "EndDateTime"; Expression = { $_.EndDateTime } }, ` |
| 67 | + @{ Name = "IsSuccess"; Expression = { $_.IsSuccess } } | |
84 | 68 | Export-Csv -LiteralPath $testCoverageRawCsv -Encoding utf8 -NoTypeInformation -Force
|
85 | 69 | }
|
86 |
| - |
87 |
| - if ($PSVersion -eq "latest") { |
88 |
| - $PSVersion = (Get-Variable -Name PSVersionTable).Value.PSVersion.ToString() |
| 70 | + else { |
| 71 | + Write-Host "##[warning]No test coverage data was found. Either the test coverage is not enabled or all live test commands were failed for the module `"$ModuleName`"." |
89 | 72 | }
|
90 |
| - $DataLocation = (Get-AzConfig -TestCoverageLocation).Value |
91 |
| - |
92 |
| - if ($DebugMode.IsPresent) { |
93 |
| - $debugDirectory = Join-Path -Path $RepoLocation -ChildPath "artifacts" | Join-Path -ChildPath "Debug" |
94 |
| - $accountsModuleDirectory = Join-Path -Path $debugDirectory -ChildPath "Az.Accounts" |
95 |
| - Write-Host "Start to import Azure PowerShell modules from artifacts/Debug." -ForegroundColor Green |
96 |
| - Write-Host "If you see module import issue, please restart the PowerShell host." -ForegroundColor Magenta |
| 73 | +} |
97 | 74 |
|
98 |
| - Write-Host "Importing Az.Accounts." -ForegroundColor Green |
99 |
| - Import-Module (Join-Path -Path $accountsModuleDirectory -ChildPath "Az.Accounts.psd1") |
100 |
| - Get-ChildItem -LiteralPath $debugDirectory -Directory -Exclude "Az.Accounts" | Get-ChildItem -File -Include "*.psd1" | ForEach-Object { |
101 |
| - Write-Host "Importing $_.FullName." -ForegroundColor Green |
102 |
| - Import-Module $_.FullName -Force |
103 |
| - } |
104 |
| - Write-Host "Successfully imported Azure PowerShell modules from artifacts/Debug" -ForegroundColor Green |
| 75 | +if ($PSVersion -eq "latest") { |
| 76 | + $PSVersion = (Get-Variable -Name PSVersionTable).Value.PSVersion.ToString() |
| 77 | +} |
105 | 78 |
|
106 |
| - $BuildId = "LocalDebug" |
107 |
| - $OSVersion = "LocalDebug" |
108 |
| - $PSVersion = "LocalDebug" |
109 |
| - } |
110 |
| - else { |
111 |
| - $BuildId = $PSBoundParameters["BuildId"] |
112 |
| - $OSVersion = $PSBoundParameters["OSVersion"] |
113 |
| - $PSVersion = $PSBoundParameters["PSVersion"] |
114 |
| - } |
| 79 | +$dataLocation = (Get-AzConfig -TestCoverageLocation).Value |
| 80 | +if ([string]::IsNullOrWhiteSpace($dataLocation) -or !(Test-Path -LiteralPath $dataLocation -PathType Container)) { |
| 81 | + $dataLocation = Join-Path -Path $env:USERPROFILE -ChildPath ".Azure" |
| 82 | +} |
115 | 83 |
|
116 |
| - $srcDir = Join-Path -Path $RepoLocation -ChildPath "src" |
117 |
| - $liveScenarios = Get-ChildItem -LiteralPath $srcDir -Recurse -Directory -Filter "LiveTests" | Get-ChildItem -Filter "TestLiveScenarios.ps1" -File |
118 |
| - $liveScenarios | ForEach-Object { |
119 |
| - $moduleName = [regex]::match($_.FullName, "[\\|\/]src[\\|\/](?<ModuleName>[a-zA-Z]+)[\\|\/]").Groups["ModuleName"].Value |
120 |
| - Import-Module "./tools/TestFx/Assert.ps1" -Force |
121 |
| - Import-Module "./tools/TestFx/Live/LiveTestUtility.psd1" -ArgumentList $moduleName, $BuildId, $OSVersion, $PSVersion, $DataLocation -Force |
122 |
| - . $_ |
123 |
| - FillLiveTestCoverageAdditionalInfo -TestCoverageDataLocation $DataLocation -BuildId $BuildId -OSVersion $OSVersion -PSVersion $PSVersion -ModuleName $moduleName |
124 |
| - } |
| 84 | +$srcDir = Join-Path -Path $RepoLocation -ChildPath "src" |
| 85 | +$liveScenarios = Get-ChildItem -Path $srcDir -Recurse -Directory -Filter "LiveTests" | Get-ChildItem -Filter "TestLiveScenarios.ps1" -File |
| 86 | +$liveScenarios | ForEach-Object { |
| 87 | + $moduleName = [regex]::match($_.FullName, "[\\|\/]src[\\|\/](?<ModuleName>[a-zA-Z]+)[\\|\/]").Groups["ModuleName"].Value |
| 88 | + Import-Module "./tools/TestFx/Assert.ps1" -Force |
| 89 | + Import-Module "./tools/TestFx/Live/LiveTestUtility.psd1" -ArgumentList $moduleName, $BuildId, $OSVersion, $PSVersion, $dataLocation -Force |
| 90 | + . $_.FullName |
| 91 | + FillLiveTestCoverageAdditionalInfo -TestCoverageDataLocation $dataLocation -BuildId $BuildId -OSVersion $OSVersion -PSVersion $PSVersion -ModuleName $moduleName |
125 | 92 | }
|
0 commit comments