mirror of
https://github.com/actions/runner-images-sangeeth.git
synced 2025-12-20 06:29:50 +00:00
[Ubuntu] Migrate PowerShell and Docker tests to Pester (#2317)
* PowerShell and Docker Pester tests * no pester module * import pester * invoke docker with sudo * remove native test * add fix for az 1.0.0 module * revert powershellget installation * revert flag Force * add $ProgressPreference = "SilentlyContinue"
This commit is contained in:
committed by
GitHub
parent
ec4b0fa89c
commit
ac87b63b13
65
images/linux/scripts/tests/PowerShellModules.Tests.ps1
Normal file
65
images/linux/scripts/tests/PowerShellModules.Tests.ps1
Normal file
@@ -0,0 +1,65 @@
|
||||
Describe "PowerShellModules" {
|
||||
$modules = (Get-ToolsetContent).powershellModules
|
||||
$withoutVersionsModules = $modules | Where-Object {-not $_.versions} | ForEach-Object {
|
||||
@{moduleName = $_.name}
|
||||
}
|
||||
|
||||
$withVersionsModules = $modules | Where-Object {$_.versions} | ForEach-Object {
|
||||
$moduleName = $_.name
|
||||
$_.versions | ForEach-Object {
|
||||
@{moduleName = $moduleName; expectedVersion = $_}
|
||||
}
|
||||
}
|
||||
|
||||
It "<moduleName> is installed" -TestCases $withoutVersionsModules {
|
||||
Get-Module -Name $moduleName -ListAvailable | Should -BeTrue
|
||||
}
|
||||
|
||||
if ($withVersionsModules) {
|
||||
It "<moduleName> with <expectedVersion> is installed" -TestCases $withVersionsModules {
|
||||
(Get-Module -Name $moduleName -ListAvailable).Version -contains $expectedVersion | Should -BeTrue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Describe "AzureModules" {
|
||||
$modules = (Get-ToolsetContent).azureModules
|
||||
$modulesRootPath = "/usr/share"
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
$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 {
|
||||
$moduleVersion = (Get-Module -ListAvailable -Name $moduleName).Version.ToString()
|
||||
$moduleVersion | Should -Match $moduleDefault
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,40 @@ Describe "azcopy" {
|
||||
}
|
||||
}
|
||||
|
||||
Describe "Docker" {
|
||||
It "docker" {
|
||||
"docker --version" | Should -ReturnZeroExitCode
|
||||
}
|
||||
|
||||
It "docker buildx" {
|
||||
"docker buildx" | Should -ReturnZeroExitCode
|
||||
}
|
||||
|
||||
Context "docker images" {
|
||||
$testCases = (Get-ToolsetContent).docker.images | ForEach-Object { @{ ImageName = $_ } }
|
||||
|
||||
It "<ImageName>" -TestCases $testCases {
|
||||
sudo docker images "$ImageName" --format "{{.Repository}}" | Should -Not -BeNullOrEmpty
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Describe "Docker-compose" {
|
||||
It "docker-compose" {
|
||||
"docker-compose --version"| Should -ReturnZeroExitCode
|
||||
}
|
||||
}
|
||||
|
||||
Describe "PowerShell Core" {
|
||||
It "pwsh" {
|
||||
"pwsh --version" | Should -ReturnZeroExitCode
|
||||
}
|
||||
|
||||
It "Execute 2+2 command" {
|
||||
pwsh -Command "2+2" | Should -BeExactly 4
|
||||
}
|
||||
}
|
||||
|
||||
Describe "Ansible" {
|
||||
It "Ansible" {
|
||||
"ansible --version" | Should -ReturnZeroExitCode
|
||||
@@ -84,4 +118,4 @@ Describe "gfortran" {
|
||||
|
||||
"$GfortranVersion --version" | Should -ReturnZeroExitCode
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user