mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 20:56:02 +00:00
1. Added parameterbinding test 2. Added ShouldBeErrorID function in helper file 3. Removed ShouldBeErrorID function from other test modules 4. Update New-TestHost to be able to run on full CLR 5. updated file map.json
71 lines
1.9 KiB
PowerShell
71 lines
1.9 KiB
PowerShell
function Wait-CompleteExecution
|
|
{
|
|
[CmdletBinding()]
|
|
param (
|
|
[ScriptBlock]$sb,
|
|
[int]$TimeoutInMilliseconds = 10000,
|
|
[int]$IntervalInMilliseconds = 1000
|
|
)
|
|
# Get the current time
|
|
$startTime = [DateTime]::Now
|
|
|
|
# Loop until the script block evaluates to true
|
|
while (-not ($sb.Invoke())) {
|
|
# Sleep for the specified interval
|
|
start-sleep -mil $intervalInMilliseconds
|
|
|
|
# If the timeout period has passed, throw an exception
|
|
if (([DateTime]::Now - $startTime).TotalMilliseconds -gt $timeoutInMilliseconds)
|
|
{
|
|
return $false
|
|
}
|
|
}
|
|
return $true
|
|
}
|
|
|
|
function Test-IsElevated
|
|
{
|
|
$IsElevated = $False
|
|
if ( $IsWindows ) {
|
|
# on Windows we can determine whether we're executing in an
|
|
# elevated context
|
|
$identity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
|
|
$windowsPrincipal = new-object 'Security.Principal.WindowsPrincipal' $identity
|
|
if ($windowsPrincipal.IsInRole("Administrators") -eq 1)
|
|
{
|
|
$IsElevated = $true
|
|
}
|
|
}
|
|
else {
|
|
# on Linux, tests run via sudo will generally report "root" for whoami
|
|
if ( (whoami) -match "root" ) {
|
|
$IsElevated = $true
|
|
}
|
|
}
|
|
return $IsElevated
|
|
}
|
|
#This function follows the pester naming convention
|
|
function ShouldBeErrorId
|
|
{
|
|
param([Parameter(ValueFromPipeline, Mandatory)]
|
|
[ScriptBlock]
|
|
$sb,
|
|
|
|
[Parameter(Mandatory, Position=0)]
|
|
[string]
|
|
$FullyQualifiedErrorId)
|
|
|
|
try
|
|
{
|
|
& $sb
|
|
Throw "Exception expected, execution should not have reached here"
|
|
}
|
|
catch
|
|
{
|
|
$_.FullyQualifiedErrorId | Should Be $FullyQualifiedErrorId
|
|
}
|
|
}
|
|
|
|
export-modulemember -function Wait-CompleteExecution,Test-IsElevated, ShouldBeErrorId
|
|
|