feature: initial commit for all new image changes

This commit is contained in:
Subir Ghosh
2024-11-13 17:16:01 -07:00
parent de6aa9e70e
commit fcf3d0ac96
1042 changed files with 45086 additions and 1 deletions
@@ -0,0 +1,18 @@
Describe "ActionArchiveCache" {
BeforeDiscovery {
$actionArchiveCachePath = "/opt/actionarchivecache"
$tarballTestCases = Get-ChildItem -Path "$actionArchiveCachePath/*.tar.gz" -Recurse | ForEach-Object { @{ ActionTarball = $_.FullName } }
}
Context "Action archive cache directory not empty" {
It "<ActionArchiveCachepath> not empty" -TestCases @{ ActionArchiveCachepath = $actionArchiveCachePath } {
(Get-ChildItem -Path "$ActionArchiveCachepath/*.tar.gz" -Recurse).Count | Should -BeGreaterThan 0
}
}
Context "Action tarball not empty" {
It "<ActionTarball>" -TestCases $tarballTestCases {
(Get-Item "$ActionTarball").Length | Should -BeGreaterThan 0
}
}
}
@@ -0,0 +1,105 @@
Describe "Android" {
function Get-AndroidPackages {
<#
.SYNOPSIS
This function returns a list of available Android packages.
.DESCRIPTION
The Get-AndroidPackages function checks if a list of packages is already available in a file.
If not, it uses the sdkmanager to generate a list of available packages and saves it to a file.
It then returns the content of this file.
.PARAMETER SDKRootPath
The root path of the Android SDK installation.
If not specified, the function uses the ANDROID_HOME environment variable.
.EXAMPLE
Get-AndroidPackages -SDKRootPath "/usr/local/lib/android/sdk"
This command returns a list of available Android packages for the specified SDK root path.
.NOTES
This function requires the Android SDK to be installed.
#>
param (
[Parameter(Mandatory=$false)]
[string] $SDKRootPath
)
if (-not $SDKRootPath) {
$SDKRootPath = $env:ANDROID_HOME
}
$packagesListFile = "$SDKRootPath/packages-list.txt"
if (-not (Test-Path -Path $packagesListFile -PathType Leaf)) {
(/usr/local/lib/android/sdk/cmdline-tools/latest/bin/sdkmanager --list --verbose 2>&1) |
Where-Object { $_ -Match "^[^\s]" } |
Where-Object { $_ -NotMatch "^(Loading |Info: Parsing |---|\[=+|Installed |Available )" } |
Where-Object { $_ -NotMatch "^[^;]*$" } |
Out-File -FilePath $packagesListFile
Write-Host "Android packages list:"
Get-Content $packagesListFile
}
return Get-Content $packagesListFile
}
$androidSdkManagerPackages = Get-AndroidPackages
[int]$platformMinVersion = (Get-ToolsetContent).android.platform_min_version
[version]$buildToolsMinVersion = (Get-ToolsetContent).android.build_tools_min_version
[array]$ndkVersions = (Get-ToolsetContent).android.ndk.versions
$ndkFullVersions = $ndkVersions |
ForEach-Object { (Get-ChildItem "/usr/local/lib/android/sdk/ndk/${_}.*" |
Select-Object -Last 1).Name } | ForEach-Object { "ndk/${_}" }
# Platforms starting with a letter are the preview versions, which is not installed on the image
$platformVersionsList = ($androidSdkManagerPackages |
Where-Object { "$_".StartsWith("platforms;") }) -replace 'platforms;android-', '' |
Where-Object { $_ -match "^\d" } | Sort-Object -Unique
$platformsInstalled = $platformVersionsList |
Where-Object { [int]($_.Split("-")[0]) -ge $platformMinVersion } |
ForEach-Object { "platforms/android-${_}" }
$buildToolsList = ($androidSdkManagerPackages | Where-Object { "$_".StartsWith("build-tools;") }) -replace 'build-tools;', ''
$buildTools = $buildToolsList |
Where-Object { $_ -match "\d+(\.\d+){2,}$"} |
Where-Object { [version]$_ -ge $buildToolsMinVersion } |
Sort-Object -Unique |
ForEach-Object { "build-tools/${_}" }
$androidPackages = @(
$platformsInstalled,
$buildTools,
$ndkFullVersions,
((Get-ToolsetContent).android.extra_list | ForEach-Object { "extras/${_}" }),
((Get-ToolsetContent).android.addon_list | ForEach-Object { "add-ons/${_}" }),
((Get-ToolsetContent).android.additional_tools | ForEach-Object { "${_}" })
)
$androidPackages = $androidPackages | ForEach-Object { $_ }
Context "SDKManagers" {
$testCases = @(
@{
PackageName = "Command-line tools"
Sdkmanager = "$env:ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager"
}
)
It "Sdkmanager from <PackageName> is available" -TestCases $testCases {
"$Sdkmanager --version" | Should -ReturnZeroExitCode
}
}
Context "Packages" {
$testCases = $androidPackages | ForEach-Object { @{ PackageName = $_ } }
It "<PackageName>" -TestCases $testCases {
# Convert 'cmake;3.6.4111459' -> 'cmake/3.6.4111459'
$PackageName = $PackageName.Replace(";", "/")
$targetPath = Join-Path $env:ANDROID_HOME $PackageName
$targetPath | Should -Exist
}
}
}
+23
View File
@@ -0,0 +1,23 @@
Import-Module "$PSScriptRoot/../helpers/Common.Helpers.psm1"
Describe "Apt" {
$packages = (Get-ToolsetContent).apt.cmd_packages + (Get-ToolsetContent).apt.vital_packages
$testCases = $packages | ForEach-Object { @{ toolName = $_ } }
It "<toolName> is available" -TestCases $testCases {
switch ($toolName) {
"acl" { $toolName = "getfacl"; break }
"aria2" { $toolName = "aria2c"; break }
"p7zip-full" { $toolName = "p7zip"; break }
"subversion" { $toolName = "svn"; break }
"sphinxsearch" { $toolName = "searchd"; break }
"binutils" { $toolName = "strings"; break }
"coreutils" { $toolName = "tr"; break }
"net-tools" { $toolName = "netstat"; break }
"mercurial" { $toolName = "hg"; break }
"findutils" { $toolName = "find"; break }
}
(Get-Command -Name $toolName).CommandType | Should -BeExactly "Application"
}
}
@@ -0,0 +1,41 @@
Describe "Firefox" {
It "Firefox" {
"firefox --version" | Should -ReturnZeroExitCode
}
It "Geckodriver" {
"geckodriver --version" | Should -ReturnZeroExitCode
}
}
Describe "Chrome" {
It "Chrome" {
"google-chrome --version" | Should -ReturnZeroExitCode
}
It "Chrome Driver" {
"chromedriver --version" | Should -ReturnZeroExitCode
}
It "Chrome and Chrome Driver major versions are the same" {
$chromeMajor = (google-chrome --version).Trim("Google Chrome ").Split(".")[0]
$chromeDriverMajor = (chromedriver --version).Trim("ChromeDriver ").Split(".")[0]
$chromeMajor | Should -BeExactly $chromeDriverMajor
}
}
Describe "Edge" {
It "Edge" {
"microsoft-edge --version" | Should -ReturnZeroExitCode
}
It "Edge Driver" {
"msedgedriver --version" | Should -ReturnZeroExitCode
}
}
Describe "Chromium" {
It "Chromium" {
"chromium-browser --version" | Should -ReturnZeroExitCode
}
}
@@ -0,0 +1,55 @@
Describe "Azure CLI" {
It "Azure CLI" {
"az --version" | Should -ReturnZeroExitCode
}
}
Describe "Azure DevOps CLI" {
It "az devops" {
"az devops -h" | Should -ReturnZeroExitCode
}
}
Describe "Aliyun CLI" -Skip:((-not (Test-IsUbuntu20)) -and (-not (Test-IsUbuntu22))) {
It "Aliyun CLI" {
"aliyun version" | Should -ReturnZeroExitCode
}
}
Describe "AWS" {
It "AWS CLI" {
"aws --version" | Should -ReturnZeroExitCode
}
It "Session Manager Plugin for the AWS CLI" {
session-manager-plugin 2>&1 | Out-String | Should -Match "plugin was installed successfully"
}
It "AWS SAM CLI" {
"sam --version" | Should -ReturnZeroExitCode
}
}
Describe "GitHub CLI" {
It "gh cli" {
"gh --version" | Should -ReturnZeroExitCode
}
}
Describe "Google Cloud CLI" -Skip:((-not (Test-IsUbuntu20)) -and (-not (Test-IsUbuntu22))) {
It "Google Cloud CLI" {
"gcloud --version" | Should -ReturnZeroExitCode
}
}
Describe "OC CLI" -Skip:((-not (Test-IsUbuntu20)) -and (-not (Test-IsUbuntu22))) {
It "OC CLI" {
"oc version" | Should -ReturnZeroExitCode
}
}
Describe "Oras CLI" -Skip:((-not (Test-IsUbuntu20)) -and (-not (Test-IsUbuntu22))) {
It "Oras CLI" {
"oras version" | Should -ReturnZeroExitCode
}
}
@@ -0,0 +1,47 @@
Describe "PHP" {
$testCases = (Get-ToolsetContent).php.versions | ForEach-Object { @{PhpVersion = $_} }
It "php <phpVersion>" -TestCases $testCases {
"php${PhpVersion} --version" | Should -ReturnZeroExitCode
"php-config${PhpVersion} --version" | Should -ReturnZeroExitCode
"phpize${PhpVersion} --version" | Should -ReturnZeroExitCode
}
It "PHPUnit" {
"phpunit --version" | Should -ReturnZeroExitCode
}
It "Composer" {
"composer --version" | Should -ReturnZeroExitCode
}
It "Pear" {
"pear" | Should -ReturnZeroExitCode
}
It "Pecl" {
"pecl" | Should -ReturnZeroExitCode
}
}
Describe "Swift" {
It "swift" {
"swift --version" | Should -ReturnZeroExitCode
}
It "swiftc" {
"swiftc --version" | Should -ReturnZeroExitCode
}
It "libsourcekitd" {
"/usr/local/lib/libsourcekitdInProc.so" | Should -Exist
}
}
Describe "PipxPackages" {
$testCases = (Get-ToolsetContent).pipx | ForEach-Object { @{package=$_.package; cmd = $_.cmd} }
It "<package>" -TestCases $testCases {
"$cmd --version" | Should -ReturnZeroExitCode
}
}
@@ -0,0 +1,39 @@
Describe "MongoDB" -Skip:(-not (Test-IsUbuntu20)) {
It "<ToolName>" -TestCases @(
@{ ToolName = "mongo" }
@{ ToolName = "mongod" }
) {
$toolsetVersion = (Get-ToolsetContent).mongodb.version
(& $ToolName --version)[2].Split('"')[-2] | Should -BeLike "$toolsetVersion*"
}
}
Describe "PostgreSQL" {
It "PostgreSQL Service" {
"sudo systemctl start postgresql" | Should -ReturnZeroExitCode
"pg_isready" | Should -OutputTextMatchingRegex "/var/run/postgresql:5432 - accepting connections"
"sudo systemctl stop postgresql" | Should -ReturnZeroExitCode
}
It "PostgreSQL version should correspond to the version in the toolset" {
$toolsetVersion = (Get-ToolsetContent).postgresql.version
# Client version
(psql --version).split()[-1] | Should -BeLike "$toolsetVersion*"
# Server version
(pg_config --version).split()[-1] | Should -BeLike "$toolsetVersion*"
}
}
Describe "MySQL" {
It "MySQL CLI" {
"mysql -V" | Should -ReturnZeroExitCode
}
It "MySQL Service" {
"sudo systemctl start mysql" | Should -ReturnZeroExitCode
mysql -s -N -h localhost -uroot -proot -e "select count(*) from mysql.user where user='root' and authentication_string is null;" | Should -BeExactly 0
"sudo mysql -vvv -e 'CREATE DATABASE smoke_test' -uroot -proot" | Should -ReturnZeroExitCode
"sudo mysql -vvv -e 'DROP DATABASE smoke_test' -uroot -proot" | Should -ReturnZeroExitCode
"sudo systemctl stop mysql" | Should -ReturnZeroExitCode
}
}
@@ -0,0 +1,40 @@
Import-Module "$PSScriptRoot/../helpers/Common.Helpers.psm1"
Describe "Dotnet and tools" {
BeforeAll {
$env:PATH = "/etc/skel/.dotnet/tools:$($env:PATH)"
$dotnetSDKs = dotnet --list-sdks | ConvertTo-Json
$dotnetRuntimes = dotnet --list-runtimes | ConvertTo-Json
}
$dotnetVersions = (Get-ToolsetContent).dotnet.versions
Context "Default" {
It "Default Dotnet SDK is available" {
"dotnet --version" | Should -ReturnZeroExitCode
}
}
foreach ($version in $dotnetVersions) {
Context "Dotnet $version" {
$dotnet = @{ dotnetVersion = $version }
It "SDK <dotnetVersion> is available" -TestCases $dotnet {
$dotnetSDKs | Should -Match "$dotnetVersion.[1-9]*"
}
It "Runtime <dotnetVersion> is available" -TestCases $dotnet {
$dotnetRuntimes | Should -Match "$dotnetVersion.[1-9]*"
}
}
}
Context "Dotnet tools" {
$dotnetTools = (Get-ToolsetContent).dotnet.tools
$testCases = $dotnetTools | ForEach-Object { @{ ToolName = $_.name; TestInstance = $_.test }}
It "<ToolName> is available" -TestCases $testCases {
"$TestInstance" | Should -ReturnZeroExitCode
}
}
}
@@ -0,0 +1,36 @@
Describe "Haskell" {
$GHCCommonPath = "/usr/local/.ghcup/ghc"
$GHCVersions = Get-ChildItem -Path $GHCCommonPath | Where-Object { $_.Name -match "\d+\.\d+" }
$testCase = @{ GHCVersions = $GHCVersions }
It "GHC directory contains two version of GHC" -TestCases $testCase {
$GHCVersions.Count | Should -Be 2
}
$testCases = $GHCVersions | ForEach-Object { @{ GHCPath = "${_}/bin/ghc"} }
It "GHC version <GHCPath>" -TestCases $testCases {
"$GHCPath --version" | Should -ReturnZeroExitCode
}
It "GHCup" {
"ghcup --version" | Should -ReturnZeroExitCode
}
It "Default GHC" {
"ghc --version" | Should -ReturnZeroExitCode
}
It "Cabal" {
"cabal --version" | Should -ReturnZeroExitCode
}
It "Stack" {
"stack --version" | Should -ReturnZeroExitCode
}
It "Stack hook is not installed" {
"$HOME/.stack/hooks/ghc-install.sh" | Should -Not -Exist
}
}
+165
View File
@@ -0,0 +1,165 @@
Import-Module "$PSScriptRoot/../helpers/Common.Helpers.psm1" -DisableNameChecking
function Invoke-PesterTests {
<#
.SYNOPSIS
Runs Pester tests based on the provided test file and test name.
.DESCRIPTION
The Invoke-PesterTests function runs Pester tests based on the provided test file and test name.
.PARAMETER TestFile
The name of the test file to run. This should be the base name of the test file without the extension.
Using "*" will run all tests from all test files.
.PARAMETER TestName
The name of the specific test to run. If provided, only the test with the matching name will be executed.
.EXAMPLE
Invoke-PesterTests -TestFile "MyTests" -TestName "Test1"
Runs the test named "Test1" from the test file "MyTests.Tests.ps1".
.EXAMPLE
Invoke-PesterTests -TestFile "*"
Runs all tests from all test files
#>
Param(
[Parameter(Mandatory = $true)]
[string] $TestFile,
[string] $TestName
)
$testPath = "/imagegeneration/tests/${TestFile}.Tests.ps1"
if (-not (Test-Path $testPath)) {
throw "Unable to find test file '$TestFile' on '$testPath'."
}
# Check that Pester module is imported
if (-not (Get-Module "Pester")) {
Import-Module Pester
}
$configuration = [PesterConfiguration] @{
Run = @{ Path = $testPath; PassThru = $true }
Output = @{ Verbosity = "Detailed"; RenderMode = "Plaintext" }
}
if ($TestName) {
$configuration.Filter.FullName = $TestName
}
# Switch ErrorActionPreference to Stop temporary to make sure that tests will fail on silent errors too
$backupErrorActionPreference = $ErrorActionPreference
$ErrorActionPreference = "Stop"
$results = Invoke-Pester -Configuration $configuration
$ErrorActionPreference = $backupErrorActionPreference
# Fail in case if no tests are run
if (-not ($results -and ($results.FailedCount -eq 0) -and (($results.PassedCount + $results.SkippedCount) -gt 0))) {
$results
throw "Test run has failed"
}
}
function ShouldReturnZeroExitCode {
<#
.SYNOPSIS
Implements a custom Should-operator for the Pester framework.
.DESCRIPTION
This function is used to check if a command has returned a zero exit code.
It can be used by registering it using the Add-ShouldOperator function in Pester.
.PARAMETER ActualValue
The actual value to be checked.
.PARAMETER Negate
A switch parameter that, when specified, negates the result of the check.
.PARAMETER Because
An optional string that provides additional context or explanation for the check.
.NOTES
This function is designed to be used with the Pester framework.
.LINK
https://pester.dev/docs/assertions/custom-assertions
#>
Param(
[string] $ActualValue,
[switch] $Negate,
[string] $Because # This parameter is unused but we need it to match Pester asserts signature
)
$result = Get-CommandResult $ActualValue -ValidateExitCode $false
[bool] $succeeded = $result.ExitCode -eq 0
if ($Negate) { $succeeded = -not $succeeded }
if (-not $succeeded) {
$commandOutputIndent = " " * 4
$commandOutput = ($result.Output | ForEach-Object { "${commandOutputIndent}${_}" }) -join "`n"
$failureMessage = "Command '${ActualValue}' has finished with exit code`n${commandOutput}"
}
return [PSCustomObject] @{
Succeeded = $succeeded
FailureMessage = $failureMessage
}
}
function ShouldOutputTextMatchingRegex {
<#
.SYNOPSIS
Implements a custom Should-operator for the Pester framework.
.DESCRIPTION
This function is used to check if a command outputs text that matches a regular expression.
It can be used by registering it using the Add-ShouldOperator function in Pester.
.PARAMETER ActualValue
The actual value to be checked.
.PARAMETER RegularExpression
The regular expression to be used for the check.
.PARAMETER Negate
A switch parameter that, when specified, negates the result of the check.
.NOTES
This function is designed to be used with the Pester framework.
.LINK
https://pester.dev/docs/assertions/custom-assertions
#>
Param(
[string] $ActualValue,
[string] $RegularExpression,
[switch] $Negate
)
$output = (Get-CommandResult $ActualValue -ValidateExitCode $false).Output | Out-String
[bool] $succeeded = $output -cmatch $RegularExpression
if ($Negate) { $succeeded = -not $succeeded }
$failureMessage = ''
if (-not $succeeded) {
if ($Negate) {
$failureMessage = "Expected regular expression '$RegularExpression' for '$ActualValue' command to not match '$output', but it did match."
} else {
$failureMessage = "Expected regular expression '$RegularExpression' for '$ActualValue' command to match '$output', but it did not match."
}
}
return [PSCustomObject] @{
Succeeded = $succeeded
FailureMessage = $failureMessage
}
}
If (Get-Command -Name Add-ShouldOperator -ErrorAction SilentlyContinue) {
Add-ShouldOperator -Name ReturnZeroExitCode -InternalName ShouldReturnZeroExitCode -Test ${function:ShouldReturnZeroExitCode}
Add-ShouldOperator -Name OutputTextMatchingRegex -InternalName ShouldOutputTextMatchingRegex -Test ${function:ShouldOutputTextMatchingRegex}
}
@@ -0,0 +1,56 @@
Import-Module "$PSScriptRoot/../helpers/Common.Helpers.psm1" -DisableNameChecking
Describe "Java" {
$toolsetJava = (Get-ToolsetContent).java
$defaultVersion = $toolsetJava.default
$jdkVersions = $toolsetJava.versions
It "Java <DefaultJavaVersion> is default" -TestCases @{ DefaultJavaVersion = $defaultVersion } {
$actualJavaPath = [System.Environment]::GetEnvironmentVariable("JAVA_HOME")
$expectedJavaPath = [System.Environment]::GetEnvironmentVariable("JAVA_HOME_${DefaultJavaVersion}_X64")
$actualJavaPath | Should -Not -BeNullOrEmpty
$expectedJavaPath | Should -Not -BeNullOrEmpty
$actualJavaPath | Should -Be $expectedJavaPath
}
It "<ToolName>" -TestCases @(
@{ ToolName = "java" }
@{ ToolName = "javac" }
) {
"$ToolName -version" | Should -ReturnZeroExitCode
}
$testCases = $jdkVersions | ForEach-Object { @{Version = $_ } }
It "Java <Version>" -TestCases $testCases {
$javaVariableValue = [System.Environment]::GetEnvironmentVariable("JAVA_HOME_${Version}_X64")
$javaVariableValue | Should -Not -BeNullOrEmpty
$javaPath = Join-Path $javaVariableValue "bin/java"
"`"$javaPath`" -version" | Should -ReturnZeroExitCode
if ($Version -eq 8) {
$Version = "1.${Version}"
}
"`"$javaPath`" -version" | Should -OutputTextMatchingRegex "openjdk\ version\ `"${Version}(\.[0-9_\.]+)?`""
}
}
Describe "Java-Tools" {
It "Gradle" {
"gradle -version" | Should -ReturnZeroExitCode
$gradleVariableValue = [System.Environment]::GetEnvironmentVariable("GRADLE_HOME")
$gradleVariableValue | Should -BeLike "/usr/share/gradle-*"
$gradlePath = Join-Path $env:GRADLE_HOME "bin/gradle"
"`"$GradlePath`" -version" | Should -ReturnZeroExitCode
}
It "<ToolName>" -TestCases @(
@{ ToolName = "mvn" }
@{ ToolName = "ant" }
) {
"$ToolName -version" | Should -ReturnZeroExitCode
}
}
@@ -0,0 +1,13 @@
Describe "Node.js" {
$binaries = @("node")
$module_commands = (Get-ToolsetContent).node_modules | ForEach-Object { $_.command }
$testCases = $binaries + $module_commands | ForEach-Object { @{NodeCommand = $_} }
It "<NodeCommand>" -TestCases $testCases {
"$NodeCommand --version" | Should -ReturnZeroExitCode
}
It "Node.js version should correspond to the version in the toolset" {
node --version | Should -BeLike "v$((Get-ToolsetContent).node.default).*"
}
}
@@ -0,0 +1,64 @@
Describe "PowerShellModules" {
$modules = (Get-ToolsetContent).powershellModules
$modulesWithoutVersions = $modules | Where-Object { -not $_.versions } | ForEach-Object {
@{moduleName = $_.name}
}
$modulesWithVersions = $modules | Where-Object { $_.versions } | ForEach-Object {
$moduleName = $_.name
$_.versions | ForEach-Object {
@{moduleName = $moduleName; expectedVersion = $_}
}
}
It "<moduleName> is installed" -TestCases $modulesWithoutVersions {
Get-Module -Name $moduleName -ListAvailable | Should -BeTrue
}
if ($modulesWithVersions) {
It "<moduleName> with <expectedVersion> is installed" -TestCases $modulesWithVersions {
(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}"
(Get-Module -ListAvailable -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
}
}
}
}
}
@@ -0,0 +1,3 @@
Import-Module "$PSScriptRoot/Helpers.psm1" -DisableNameChecking
Invoke-PesterTests "*"
@@ -0,0 +1,7 @@
Describe "RunnerCache" {
Context "runner cache directory not empty" {
It "<RunnerCachePath> not empty" -TestCases @{ RunnerCachePath = "/opt/runner-cache" } {
(Get-ChildItem -Path "$RunnerCachePath/*.tar.gz" -Recurse).Count | Should -BeGreaterThan 0
}
}
}
@@ -0,0 +1,8 @@
# The $env:AGENT_NAME and $env:RUNNER_NAME are predefined variables for the ADO pipelines and for the GitHub actions respectively.
# If the test is running on the ADO pipeline or on the GitHub actions, the test will be skipped
Describe "Disk free space" -Skip:(-not [String]::IsNullOrEmpty($env:AGENT_NAME) -or -not [String]::IsNullOrEmpty($env:RUNNER_NAME)) {
It "Image has enough free space" {
$freeSpace = (Get-PSDrive "/").Free
$freeSpace | Should -BeGreaterOrEqual 17GB
}
}
+413
View File
@@ -0,0 +1,413 @@
Import-Module "$PSScriptRoot/../helpers/Common.Helpers.psm1"
Describe "azcopy" {
It "azcopy" {
"azcopy --version" | Should -ReturnZeroExitCode
}
It "azcopy10 link exists" {
"azcopy10 --version" | Should -ReturnZeroExitCode
}
}
Describe "Bicep" {
It "Bicep" {
"bicep --version" | Should -ReturnZeroExitCode
}
}
Describe "Rust" {
BeforeAll {
$env:PATH = "/etc/skel/.cargo/bin:/etc/skel/.rustup/bin:$($env:PATH)"
$env:RUSTUP_HOME = "/etc/skel/.rustup"
$env:CARGO_HOME = "/etc/skel/.cargo"
}
It "Rustup is installed" {
"rustup --version" | Should -ReturnZeroExitCode
}
It "Rustc is installed" {
"rustc --version" | Should -ReturnZeroExitCode
}
It "Rustdoc is installed" {
"rustdoc --version" | Should -ReturnZeroExitCode
}
It "Rustfmt is installed" {
"rustfmt --version" | Should -ReturnZeroExitCode
}
It "cargo" {
"cargo --version" | Should -ReturnZeroExitCode
}
Context "Cargo dependencies" -Skip:((-not (Test-IsUbuntu20)) -and (-not (Test-IsUbuntu22))) {
It "bindgen" {
"bindgen --version" | Should -ReturnZeroExitCode
}
It "cbindgen" {
"cbindgen --version" | Should -ReturnZeroExitCode
}
It "cargo-clippy" {
"cargo-clippy --version" | Should -ReturnZeroExitCode
}
It "Cargo audit" {
"cargo audit --version" | Should -ReturnZeroExitCode
}
It "Cargo outdated" {
"cargo outdated --version" | Should -ReturnZeroExitCode
}
}
}
Describe "Docker" {
It "docker client" {
$version=(Get-ToolsetContent).docker.components | Where-Object { $_.package -eq 'docker-ce-cli' } | Select-Object -ExpandProperty version
If ($version -ne "latest") {
$(sudo docker version --format '{{.Client.Version}}') | Should -BeLike "*$version*"
}else{
"sudo docker version --format '{{.Client.Version}}'" | Should -ReturnZeroExitCode
}
}
It "docker server" {
$version=(Get-ToolsetContent).docker.components | Where-Object { $_.package -eq 'docker-ce' } | Select-Object -ExpandProperty version
If ($version -ne "latest") {
$(sudo docker version --format '{{.Server.Version}}') | Should -BeLike "*$version*"
}else{
"sudo docker version --format '{{.Server.Version}}'" | Should -ReturnZeroExitCode
}
}
It "docker client/server versions match" {
$clientVersion = $(sudo docker version --format '{{.Client.Version}}')
$serverVersion = $(sudo docker version --format '{{.Server.Version}}')
$clientVersion | Should -Be $serverVersion
}
It "docker buildx" {
$version=(Get-ToolsetContent).docker.plugins | Where-Object { $_.plugin -eq 'buildx' } | Select-Object -ExpandProperty version
If ($version -ne "latest") {
$(docker buildx version) | Should -BeLike "*$version*"
}else{
"docker buildx" | Should -ReturnZeroExitCode
}
}
It "docker compose v2" {
$version=(Get-ToolsetContent).docker.plugins | Where-Object { $_.plugin -eq 'compose' } | Select-Object -ExpandProperty version
If ($version -ne "latest") {
$(docker compose version --short) | Should -BeLike "*$version*"
}else{
"docker compose version --short" | Should -ReturnZeroExitCode
}
}
It "docker-credential-ecr-login" {
"docker-credential-ecr-login -v" | Should -ReturnZeroExitCode
}
}
Describe "Docker images" {
$testCases = (Get-ToolsetContent).docker.images | ForEach-Object { @{ ImageName = $_ } }
It "<ImageName>" -TestCases $testCases {
sudo docker images "$ImageName" --format "{{.Repository}}" | Should -Not -BeNullOrEmpty
}
}
Describe "Ansible" {
It "Ansible" {
"ansible --version" | Should -ReturnZeroExitCode
}
}
Describe "Bazel" {
It "<ToolName>" -TestCases @(
@{ ToolName = "bazel" }
@{ ToolName = "bazelisk" }
) {
"$ToolName --version"| Should -ReturnZeroExitCode
}
}
Describe "clang" {
$testCases = (Get-ToolsetContent).clang.Versions | ForEach-Object { @{ClangVersion = $_} }
It "clang <ClangVersion>" -TestCases $testCases {
"clang-$ClangVersion --version" | Should -ReturnZeroExitCode
"clang++-$ClangVersion --version" | Should -ReturnZeroExitCode
"clang-format-$ClangVersion --version" | Should -ReturnZeroExitCode
"clang-tidy-$ClangVersion --version" | Should -ReturnZeroExitCode
"run-clang-tidy-$ClangVersion --help" | Should -ReturnZeroExitCode
}
}
Describe "Cmake" {
It "cmake" {
"cmake --version" | Should -ReturnZeroExitCode
}
}
Describe "erlang" -Skip:(-not (Test-IsUbuntu20)) {
$testCases = @("erl -version", "erlc -v", "rebar3 -v") | ForEach-Object { @{ErlangCommand = $_} }
It "erlang <ErlangCommand>" -TestCases $testCases {
"$ErlangCommand" | Should -ReturnZeroExitCode
}
}
Describe "gcc" {
$testCases = (Get-ToolsetContent).gcc.Versions | ForEach-Object { @{GccVersion = $_} }
It "gcc <GccVersion>" -TestCases $testCases {
"$GccVersion --version" | Should -ReturnZeroExitCode
}
}
Describe "gfortran" {
$testCases = (Get-ToolsetContent).gfortran.Versions | ForEach-Object { @{GfortranVersion = $_} }
It "gfortran <GfortranVersion>" -TestCases $testCases {
"$GfortranVersion --version" | Should -ReturnZeroExitCode
}
}
Describe "Mono" -Skip:(Test-IsUbuntu24) {
It "mono" {
"mono --version" | Should -ReturnZeroExitCode
}
It "msbuild" {
"msbuild -version" | Should -ReturnZeroExitCode
}
It "nuget" {
"nuget" | Should -ReturnZeroExitCode
}
}
Describe "MSSQLCommandLineTools" -Skip:((-not (Test-IsUbuntu20)) -and (-not (Test-IsUbuntu22))) {
It "sqlcmd" {
"sqlcmd -?" | Should -ReturnZeroExitCode
}
}
Describe "SqlPackage" -Skip:((-not (Test-IsUbuntu20)) -and (-not (Test-IsUbuntu22))) {
It "sqlpackage" {
"sqlpackage /version" | Should -ReturnZeroExitCode
}
}
Describe "R" -Skip:((-not (Test-IsUbuntu20)) -and (-not (Test-IsUbuntu22))) {
It "r" {
"R --version" | Should -ReturnZeroExitCode
}
}
Describe "Sbt" -Skip:((-not (Test-IsUbuntu20)) -and (-not (Test-IsUbuntu22))) {
It "sbt" {
"sbt --version" | Should -ReturnZeroExitCode
}
}
Describe "Selenium" {
It "Selenium is installed" {
$seleniumPath = Join-Path "/usr/share/java" "selenium-server.jar"
$seleniumPath | Should -Exist
}
}
Describe "Terraform" -Skip:((-not (Test-IsUbuntu20)) -and (-not (Test-IsUbuntu22))) {
It "terraform" {
"terraform --version" | Should -ReturnZeroExitCode
}
}
Describe "Zstd" {
It "zstd" {
"zstd --version" | Should -ReturnZeroExitCode
}
It "pzstd" {
"pzstd --version" | Should -ReturnZeroExitCode
}
}
Describe "Vcpkg" {
It "vcpkg" {
"vcpkg version" | Should -ReturnZeroExitCode
}
}
Describe "Git" {
It "git" {
"git --version" | Should -ReturnZeroExitCode
}
It "git-ftp" {
"git-ftp --version" | Should -ReturnZeroExitCode
}
}
Describe "Git-lfs" {
It "git-lfs" {
"git-lfs --version" | Should -ReturnZeroExitCode
}
}
Describe "Heroku" -Skip:((-not (Test-IsUbuntu20)) -and (-not (Test-IsUbuntu22))) {
It "heroku" {
"heroku --version" | Should -ReturnZeroExitCode
}
}
Describe "HHVM" -Skip:(-not (Test-IsUbuntu20)) {
It "hhvm" {
"hhvm --version" | Should -ReturnZeroExitCode
}
}
Describe "Homebrew" {
It "homebrew" {
"/home/linuxbrew/.linuxbrew/bin/brew --version" | Should -ReturnZeroExitCode
}
}
Describe "Julia" {
It "julia" {
"julia --version" | Should -ReturnZeroExitCode
}
}
Describe "Kubernetes tools" {
It "kind" {
"kind version" | Should -ReturnZeroExitCode
}
It "kubectl" {
"kubectl version --client=true" | Should -OutputTextMatchingRegex "Client Version: v"
}
It "helm" {
"helm version --short" | Should -ReturnZeroExitCode
}
It "minikube" {
"minikube version --short" | Should -ReturnZeroExitCode
}
It "kustomize" {
"kustomize version" | Should -ReturnZeroExitCode
}
}
Describe "Leiningen" -Skip:((-not (Test-IsUbuntu20)) -and (-not (Test-IsUbuntu22))) {
It "leiningen" {
"lein --version" | Should -ReturnZeroExitCode
}
}
Describe "Conda" {
It "conda" {
"conda --version" | Should -ReturnZeroExitCode
}
}
Describe "Packer" {
It "packer" {
"packer --version" | Should -ReturnZeroExitCode
}
}
Describe "Pulumi" {
It "pulumi" {
"pulumi version" | Should -ReturnZeroExitCode
}
}
Describe "Phantomjs" -Skip:(-not (Test-IsUbuntu20)) {
It "phantomjs" {
$env:OPENSSL_CONF="/etc/ssl"
"phantomjs --version" | Should -ReturnZeroExitCode
}
}
Describe "Containers" {
$testCases = @("podman", "buildah", "skopeo") | ForEach-Object { @{ContainerCommand = $_} }
It "<ContainerCommand>" -TestCases $testCases {
"$ContainerCommand -v" | Should -ReturnZeroExitCode
}
# https://github.com/actions/runner-images/issues/7753
It "podman networking" -TestCases "podman CNI plugins" {
"podman network create -d bridge test-net" | Should -ReturnZeroExitCode
"podman network ls" | Should -Not -OutputTextMatchingRegex "Error"
"podman network rm test-net" | Should -ReturnZeroExitCode
}
}
Describe "nvm" -Skip:((-not (Test-IsUbuntu20)) -and (-not (Test-IsUbuntu22))) {
It "nvm" {
"source /etc/skel/.nvm/nvm.sh && nvm --version" | Should -ReturnZeroExitCode
}
}
Describe "Python" {
$testCases = @("python", "pip", "python3", "pip3") | ForEach-Object { @{PythonCommand = $_} }
It "<PythonCommand>" -TestCases $testCases {
"$PythonCommand --version" | Should -ReturnZeroExitCode
}
}
Describe "Ruby" {
$testCases = @("ruby", "gem") | ForEach-Object { @{RubyCommand = $_} }
It "<RubyCommand>" -TestCases $testCases {
"$RubyCommand --version" | Should -ReturnZeroExitCode
}
$gemTestCases = (Get-ToolsetContent).rubygems | ForEach-Object { @{gemName = $_.name} }
if ($gemTestCases) {
It "Gem <gemName> is installed" -TestCases $gemTestCases {
"gem list -i '^$gemName$'" | Should -OutputTextMatchingRegex "true"
}
}
}
Describe "yq" {
It "yq" {
"yq -V" | Should -ReturnZeroExitCode
}
}
Describe "Kotlin" {
It "kapt" {
"kapt -version" | Should -ReturnZeroExitCode
}
It "kotlin" {
"kotlin -version" | Should -ReturnZeroExitCode
}
It "kotlinc" {
"kotlinc -version" | Should -ReturnZeroExitCode
}
It "kotlinc-jvm" {
"kotlinc-jvm -version" | Should -ReturnZeroExitCode
}
It "kotlin-dce-js" {
"kotlin-dce-js -version" | Should -ReturnZeroExitCode
}
}
@@ -0,0 +1,65 @@
Describe "Toolset" {
$tools = (Get-ToolsetContent).toolcache
$toolsExecutables = @{
Python = @{
tools = @("python", "bin/pip")
command = "--version"
}
node = @{
tools = @("bin/node", "bin/npm")
command = "--version"
}
PyPy = @{
tools = @("bin/python", "bin/pip")
command = "--version"
}
go = @{
tools = @("bin/go")
command = "version"
}
Ruby = @{
tools = @("bin/ruby")
command = "--version"
}
CodeQL = @{
tools = @("codeql/codeql")
command = "version"
}
}
foreach ($tool in $tools) {
$toolName = $tool.Name
Context "$toolName" {
$toolExecs = $toolsExecutables[$toolName]
foreach ($version in $tool.versions) {
# Add wildcard if missing
if ($version.Split(".").Length -lt 3) {
$version += ".*"
}
$expectedVersionPath = Join-Path $env:AGENT_TOOLSDIRECTORY $toolName $version
It "$version version folder exists" -TestCases @{ ExpectedVersionPath = $expectedVersionPath} {
$ExpectedVersionPath | Should -Exist
}
$foundVersion = Get-Item $expectedVersionPath `
| Sort-Object -Property {[SemVer]$_.name} -Descending `
| Select-Object -First 1
$foundVersionPath = Join-Path $foundVersion $tool.arch
if ($toolExecs) {
foreach ($executable in $toolExecs["tools"]) {
$executablePath = Join-Path $foundVersionPath $executable
It "Validate $executable" -TestCases @{ExecutablePath = $executablePath} {
$ExecutablePath | Should -Exist
}
}
}
}
}
}
}
@@ -0,0 +1,23 @@
Describe "Apache" {
It "Apache CLI" {
"apache2 -v" | Should -ReturnZeroExitCode
}
It "Apache Service" {
"sudo systemctl start apache2" | Should -ReturnZeroExitCode
"apachectl configtest" | Should -ReturnZeroExitCode
"sudo systemctl stop apache2" | Should -ReturnZeroExitCode
}
}
Describe "Nginx" {
It "Nginx CLI" {
"nginx -v" | Should -ReturnZeroExitCode
}
It "Nginx Service" {
"sudo systemctl start nginx" | Should -ReturnZeroExitCode
"sudo nginx -t" | Should -ReturnZeroExitCode
"sudo systemctl stop nginx" | Should -ReturnZeroExitCode
}
}