mirror of
https://github.com/actions/runner-images.git
synced 2025-12-18 07:46:57 +00:00
[Windows] Update Az module pester test (#6902)
This commit is contained in:
@@ -54,4 +54,5 @@ Export-ModuleMember -Function @(
|
||||
'Get-VisualStudioComponents'
|
||||
'Get-WindowsUpdatesHistory'
|
||||
'New-ItemPath'
|
||||
'Get-ModuleVersionAsJob'
|
||||
)
|
||||
|
||||
@@ -615,3 +615,4 @@ function Get-GitHubPackageDownloadUrl {
|
||||
|
||||
return $downloadUrl
|
||||
}
|
||||
|
||||
|
||||
@@ -173,3 +173,28 @@ If (Get-Command -Name Add-ShouldOperator -ErrorAction SilentlyContinue) {
|
||||
Add-ShouldOperator -Name ReturnZeroExitCodeWithParam -InternalName ShouldReturnZeroExitCodeWithParam -Test ${function:ShouldReturnZeroExitCodeWithParam}
|
||||
Add-ShouldOperator -Name MatchCommandOutput -InternalName ShouldMatchCommandOutput -Test ${function:ShouldMatchCommandOutput}
|
||||
}
|
||||
|
||||
Function Get-ModuleVersionAsJob {
|
||||
Param (
|
||||
[Parameter(Mandatory)]
|
||||
[String] $modulePath,
|
||||
[Parameter(Mandatory)]
|
||||
[String] $moduleName
|
||||
)
|
||||
# Script block to run commands in separate PowerShell environment
|
||||
$testJob = Start-Job -ScriptBlock {
|
||||
param (
|
||||
$modulePath,
|
||||
$moduleName
|
||||
)
|
||||
# Disable warning messages to prevent additional warnings about Az and Azurerm modules in the same session
|
||||
$WarningPreference = "SilentlyContinue"
|
||||
$env:PsModulePath = "$modulePath;$env:PsModulePath"
|
||||
Import-Module -Name $moduleName
|
||||
(Get-Module -Name $moduleName).Version.ToString()
|
||||
|
||||
} -ArgumentList $modulePath, $moduleName
|
||||
|
||||
$testJob | Wait-Job | Receive-Job | Out-File -FilePath "${env:TEMP}\module-version.txt"
|
||||
Remove-Job $testJob
|
||||
}
|
||||
|
||||
@@ -90,4 +90,4 @@ foreach ($module in $modules)
|
||||
$psModuleMachinePath += $env:PSModulePath
|
||||
[Environment]::SetEnvironmentVariable("PSModulePath", $psModuleMachinePath, "Machine")
|
||||
|
||||
Invoke-PesterTests -TestFile "PowerShellModules" -TestName "AzureModules"
|
||||
Invoke-PesterTests -TestFile "PowerShellAzModules" -TestName "AzureModules"
|
||||
40
images/win/scripts/Tests/PowerShellAzModules.Tests.ps1
Normal file
40
images/win/scripts/Tests/PowerShellAzModules.Tests.ps1
Normal file
@@ -0,0 +1,40 @@
|
||||
Describe "AzureModules" {
|
||||
|
||||
$modules = (Get-ToolsetContent).azureModules
|
||||
$modulesRootPath = "C:\\Modules"
|
||||
|
||||
foreach ($module in $modules) {
|
||||
$moduleName = $module.name
|
||||
|
||||
Context "$moduleName" {
|
||||
|
||||
foreach ($version in $module.versions) {
|
||||
$modulePath = Join-Path -Path $modulesRootPath -ChildPath "${moduleName}_${version}"
|
||||
$moduleInfo = @{ moduleName = $moduleName; modulePath = $modulePath; expectedVersion = $version }
|
||||
It "<expectedVersion> exists in modules directory" -TestCases $moduleInfo {
|
||||
$ScriptBlock = {
|
||||
param ($modulePath, $moduleName)
|
||||
Import-Module ImageHelpers
|
||||
Get-ModuleVersionAsJob -modulePath $modulePath -moduleName $moduleName
|
||||
}
|
||||
if ($moduleName -eq "Az"){
|
||||
Start-Process -FilePath pwsh.exe -ArgumentList "-Command (Invoke-Command -ScriptBlock {$ScriptBlock} -ArgumentList $modulePath, $moduleName)" -Wait -PassThru
|
||||
} else {
|
||||
Start-Process -FilePath powershell.exe -ArgumentList "-Command (Invoke-Command -ScriptBlock {$ScriptBlock} -ArgumentList $modulePath, $moduleName)" -Wait -PassThru
|
||||
}
|
||||
$moduleVersion = Get-Content -Path "$env:TEMP\module-version.txt"
|
||||
Remove-Item -Path "${env:TEMP}\module-version.txt" -Force
|
||||
$moduleVersion | Should -Match $expectedVersion
|
||||
}
|
||||
}
|
||||
|
||||
if ($module.default) {
|
||||
$moduleInfo = @{ moduleName = $moduleName; moduleDefault = $module.default }
|
||||
It "<moduleDefault> set as default" -TestCases $moduleInfo {
|
||||
$moduleVersions = Get-Module -ListAvailable -Name $moduleName | ForEach-Object { $_.Version.ToString() }
|
||||
$moduleVersions | Should -Contain $moduleDefault
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,48 +21,3 @@ Describe "PowerShellModules" {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Describe "AzureModules" {
|
||||
$modules = (Get-ToolsetContent).azureModules
|
||||
$modulesRootPath = "C:\\Modules"
|
||||
|
||||
foreach ($module in $modules) {
|
||||
$moduleName = $module.name
|
||||
|
||||
Context "$moduleName" {
|
||||
|
||||
foreach ($version in $module.versions) {
|
||||
$modulePath = Join-Path -Path $modulesRootPath -ChildPath "${moduleName}_${version}"
|
||||
$moduleInfo = @{ moduleName = $moduleName; modulePath = $modulePath; expectedVersion = $version }
|
||||
It "<expectedVersion> exists in modules directory" -TestCases $moduleInfo {
|
||||
$testJob = Start-Job -ScriptBlock {
|
||||
param (
|
||||
$modulePath,
|
||||
$moduleName
|
||||
)
|
||||
|
||||
# Disable warning messages to prevent additional warnings about Az and Azurerm modules in the same session
|
||||
$WarningPreference = "SilentlyContinue"
|
||||
|
||||
$env:PsModulePath = "$modulePath;$env:PsModulePath"
|
||||
Import-Module -Name $moduleName
|
||||
(Get-Module -Name $moduleName).Version.ToString()
|
||||
|
||||
} -ArgumentList $modulePath, $moduleName
|
||||
|
||||
$moduleVersion = $testJob | Wait-Job | Receive-Job
|
||||
Remove-Job $testJob
|
||||
$moduleVersion | Should -Match $expectedVersion
|
||||
}
|
||||
}
|
||||
|
||||
if ($module.default) {
|
||||
$moduleInfo = @{ moduleName = $moduleName; moduleDefault = $module.default }
|
||||
It "<moduleDefault> set as default" -TestCases $moduleInfo {
|
||||
$moduleVersions = Get-Module -ListAvailable -Name $moduleName | ForEach-Object { $_.Version.ToString() }
|
||||
$moduleVersions | Should -Contain $moduleDefault
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user