41 lines
1023 B
PowerShell
41 lines
1023 B
PowerShell
|
function Test-HaveContentThatMatches {
|
||
|
<#
|
||
|
.SYNOPSIS
|
||
|
Tests that the content in $result matches partially the value in $pattern
|
||
|
|
||
|
.DESCRIPTION
|
||
|
Intended to be used in conjunction with Test-Should function.
|
||
|
|
||
|
.PARAMETER result
|
||
|
Result of Invoke-WebRequest containing Html to test against.
|
||
|
|
||
|
.PARAMETER pattern
|
||
|
RegEx pattern to test the $result with. Performs $result.Content -match $pattern
|
||
|
|
||
|
.EXAMPLE
|
||
|
$passedTest = (Test-Should -Result $webResponse -Predicate ${function:Test-HaveContentThatMatches} "/DashboardV2")
|
||
|
|
||
|
.NOTES
|
||
|
Returns a bool of success and/or error message.
|
||
|
#>
|
||
|
[CmdletBinding()]
|
||
|
[OutputType([System.Boolean])]
|
||
|
[OutputType([System.String])]
|
||
|
param(
|
||
|
$result,
|
||
|
[regex]$pattern
|
||
|
)
|
||
|
|
||
|
try {
|
||
|
if (-not($result.Content -match $pattern)) {
|
||
|
$false
|
||
|
"returned content that did not match $pattern"
|
||
|
}
|
||
|
else {
|
||
|
$true
|
||
|
}
|
||
|
} catch {
|
||
|
$false
|
||
|
"Error occured inside test! Exception: $_"
|
||
|
}
|
||
|
}
|