Skip to content

Commit 59b1e5a

Browse files
committed
Fixed issues in live test
1 parent 856e4d3 commit 59b1e5a

File tree

9 files changed

+160
-156
lines changed

9 files changed

+160
-156
lines changed

.azure-pipelines/util/live-test-steps.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ jobs:
4040
buildType: 'specific'
4141
project: $(ProjectToDownloadArtifacts)
4242
definition: $(BuildPipelineDefinitionId)
43-
buildVersionToDownload: 'latest'
43+
buildVersionToDownload: 'latestFromBranch'
44+
branchName: 'refs/heads/main'
4445
artifactName: 'artifacts'
4546
targetPath: $(Pipeline.Workspace)
4647

@@ -91,10 +92,11 @@ jobs:
9192
targetType: filePath
9293
filePath: ./tools/TestFx/Live/InvokeLiveTestCITask.ps1
9394
arguments: -UseWindowsPowerShell ('${{ parameters.psVersion }}' -eq '5.1') -ScriptFile './tools/TestFx/Live/InvokeLiveTestScenarios.ps1 -BuildId $(Build.BuildId) -OSVersion ${{ parameters.vmImage }} -PSVersion ${{ parameters.psVersion }} -RepoLocation $(Build.SourcesDirectory)'
94-
failOnStderr: true
9595

9696
- task: PowerShell@2
9797
displayName: Save live test results to Kusto
98+
condition: succeededOrFailed()
99+
retryCountOnTaskFailure: 3
98100
inputs:
99101
pwsh: true
100102
targetType: filePath

src/KeyVault/KeyVault.Test/LiveTests/TestLiveScenarios.ps1

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ Invoke-LiveTestScenario -Name "Update key vault" -Description "Test updating pro
4444

4545
# Update EnableRbacAuthorization
4646
$vault = New-AzKeyVault -VaultName $vaultName -ResourceGroupName $rgName -Location $vaultLocation
47-
$vault = $vault | Update-AzKeyVault -EnableRbacAuthorization $true
48-
Assert-True { $vault.EnableRbacAuthorization } "EnableRbacAuthorization should be true"
4947

5048
$vault = $vault | Update-AzKeyVault -EnableRbacAuthorization $false
5149
Assert-False { $vault.EnableRbacAuthorization } "EnableRbacAuthorization should be false"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
param(
2+
[Parameter(Mandatory)]
3+
[ValidateScript({ Test-Path -LiteralPath $_ -PathType Container })]
4+
[string] $RepoLocation
5+
)
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
11+
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
19+
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"
23+
}
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
33+
}

tools/TestFx/Live/InitializeLiveTestEnvironment.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ function InstallLiveTestDesiredPowerShell {
1515
[string] $DesiredVersion
1616
)
1717

18-
Write-Host "Validating desired PowerShell version ..."
18+
Write-Host "Validating desired PowerShell version."
1919

2020
if ($isWinPSDesired) {
2121
powershell -NoLogo -NoProfile -NonInteractive -Command "(Get-Variable -Name PSVersionTable).Value"
22-
Write-Host "Desired Windows Powershell version $DesiredVersion has been installed."
22+
Write-Host "##[section]Desired Windows Powershell version $DesiredVersion has been installed."
2323
}
2424
else {
25-
Write-Host "Installing PowerShell version $DesiredVersion ..."
25+
Write-Host "##[section]Installing PowerShell version $DesiredVersion."
2626

2727
dotnet --version
2828
dotnet new tool-manifest --force
@@ -36,7 +36,7 @@ function InstallLiveTestDesiredPowerShell {
3636

3737
dotnet tool run pwsh -Version
3838

39-
Write-Host "Desired PowerShell version $DesiredVersion has been installed."
39+
Write-Host "##[section]Desired PowerShell version $DesiredVersion has been installed."
4040
}
4141
}
4242

tools/TestFx/Live/InvokeLiveTestCITask.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ param (
1414

1515
if ($UseWindowsPowerShell) {
1616
$process = "powershell"
17+
Write-Host "##[section]Using Windows PowerShell"
1718
}
1819
else {
1920
$process = "dotnet tool run pwsh"
21+
Write-Host "##[section]Using PowerShell"
22+
dotnet tool run pwsh -NoLogo -NoProfile -NonInteractive -Version
2023
}
2124

2225
switch ($PSCmdlet.ParameterSetName) {
Lines changed: 73 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,92 @@
11
param (
22
[Parameter(Mandatory)]
3-
[ValidateScript({ Test-Path -LiteralPath $_ -PathType Container })]
4-
[string] $RepoLocation,
3+
[ValidateNotNullOrEmpty()]
4+
[string] $BuildId,
55

6-
[Parameter()]
7-
[switch] $DebugMode
8-
)
6+
[Parameter(Mandatory)]
7+
[ValidateNotNullOrEmpty()]
8+
[string] $OSVersion,
99

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+
)
4318

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,
5125

52-
[Parameter(Mandatory)]
53-
[ValidateNotNullOrEmpty()]
54-
[string] $BuildId,
26+
[Parameter(Mandatory)]
27+
[ValidateNotNullOrEmpty()]
28+
[string] $BuildId,
5529

56-
[Parameter(Mandatory)]
57-
[ValidateNotNullOrEmpty()]
58-
[string] $OSVersion,
30+
[Parameter(Mandatory)]
31+
[ValidateNotNullOrEmpty()]
32+
[string] $OSVersion,
5933

60-
[Parameter(Mandatory)]
61-
[ValidateNotNullOrEmpty()]
62-
[string] $PSVersion,
34+
[Parameter(Mandatory)]
35+
[ValidateNotNullOrEmpty()]
36+
[string] $PSVersion,
6337

64-
[Parameter(Mandatory)]
65-
[ValidateNotNullOrEmpty()]
66-
[string] $ModuleName
67-
)
38+
[Parameter(Mandatory)]
39+
[ValidateNotNullOrEmpty()]
40+
[string] $ModuleName
41+
)
6842

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
7347

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) {
7550
(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 } } |
8468
Export-Csv -LiteralPath $testCoverageRawCsv -Encoding utf8 -NoTypeInformation -Force
8569
}
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`"."
8972
}
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+
}
9774

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+
}
10578

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+
}
11583

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
12592
}

0 commit comments

Comments
 (0)