mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 12:45:47 +00:00
Add autoload for TestLanguage.psm1 TestHelpers.psm1 (#3456)
* Add autoload for TestHelpers.psm1 Test.Helpers.psm1 was renamed to TestHelpers.psm1 * Resolve conflit and rebase Add autoload for TestLanguage.psm1 * Remove unneeded comments from PSD1 files * Rename test modules Remove approved verbs (Get-Verb) from module names. * Enhance ShouldBeErrorId to output exception into pipeline for later analysis * Remove unneeded comments * Resolve merge conflict
This commit is contained in:
1 parent
599eae9b1b
commit
e00161a8af
25 files changed
+599
-620
No files matched your search
@@ -0,0 +1,21 @@
|
||||
#
|
||||
# Module manifest for module 'HelpersCommon'
|
||||
#
|
||||
|
||||
@{
|
||||
|
||||
RootModule = 'HelpersCommon.psm1'
|
||||
|
||||
ModuleVersion = '1.0'
|
||||
|
||||
GUID = 'cc1c8e94-51d1-4bc1-b508-62bc09f02f54'
|
||||
|
||||
CompanyName = 'Microsoft Corporation'
|
||||
|
||||
Copyright = 'Copyright (C) Microsoft Corporation, All rights reserved.'
|
||||
|
||||
Description = 'Temporary module contains functions for using in tests'
|
||||
|
||||
FunctionsToExport = 'Wait-UntilTrue', 'Test-IsElevated', 'ShouldBeErrorId'
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
function Wait-UntilTrue
|
||||
{
|
||||
[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 | Out-Null
|
||||
Throw "No Exception!"
|
||||
}
|
||||
catch
|
||||
{
|
||||
$_.FullyQualifiedErrorId | Should Be $FullyQualifiedErrorId | Out-Null
|
||||
# Write the exception to output that allow us to check later other properies of the exception
|
||||
Write-Output $_
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user