mirror of
https://github.com/actions/runner-images.git
synced 2025-12-15 22:26:56 +00:00
Implement tests for software-report-module (#6815)
* Minor improvements * fix typos * fix brew rendering * add temp test * Implement tests * Add arguments validation * ToMarkdown() * Use before-All and helpers * Get rid of arrays * Add validation, no new nodes after header * Fix naming * add workflow * Revisit comments + tiny improvements * Fix tables * Fix html table indent * remove comment * attemp to break test - testing CI * revert breaking test * fix nitpicks
This commit is contained in:
34
helpers/software-report-base/tests/TestHelpers.psm1
Normal file
34
helpers/software-report-base/tests/TestHelpers.psm1
Normal file
@@ -0,0 +1,34 @@
|
||||
function ShouldBeArray([Array] $ActualValue, [Array]$ExpectedValue, [Switch] $Negate, [String] $Because) {
|
||||
if ($Negate) {
|
||||
throw "Negation is not supported for Should-BeArray"
|
||||
}
|
||||
|
||||
if ($ExpectedValue.Count -eq 0) {
|
||||
throw "Expected array cannot be empty. Use Should-BeNullOrEmpty instead."
|
||||
}
|
||||
|
||||
$ExpectedValue | ForEach-Object {
|
||||
if ($_.GetType() -notin @([String], [Int32])) {
|
||||
throw "Only string or int arrays are supported in Should-BeArray"
|
||||
}
|
||||
}
|
||||
|
||||
$actualValueJson = $ActualValue | ConvertTo-Json
|
||||
$expectedValueJson = $ExpectedValue | ConvertTo-Json
|
||||
|
||||
$succeeded = ($ActualValue.Count -eq $ExpectedValue.Count) -and ($actualValueJson -eq $expectedValueJson)
|
||||
|
||||
if (-not $succeeded) {
|
||||
$failureMessage = "Expected array '$actualValueJson' to be equal to '$expectedValueJson'"
|
||||
}
|
||||
|
||||
return [PSCustomObject]@{
|
||||
Succeeded = $succeeded
|
||||
FailureMessage = $failureMessage
|
||||
}
|
||||
}
|
||||
|
||||
Add-ShouldOperator -Name BeArray `
|
||||
-InternalName 'ShouldBeArray' `
|
||||
-Test ${function:ShouldBeArray} `
|
||||
-SupportsArrayInput
|
||||
Reference in New Issue
Block a user