Files
runner-images/helpers/software-report-base/tests/TestHelpers.psm1
Maxim Lobanov 4aeccc7b5b 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
2022-12-21 10:58:27 +01:00

34 lines
1.1 KiB
PowerShell

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