mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Tests for Get-Process Cmdlet for Module and FileVersion parameters (#6272)
* Tests for Get-Process cmdlet. * Tests for Get-Process run as admin. * Skipping some Get-Process tests on Linux * Skip test for -FileVersionInfo parameter for Linux because of the bug that cause the command to hang. * Add checks for ErrorId in Get-Process tests * Change one Get-Process test status to pending for MacOs
This commit is contained in:
committed by
Aditya Patwardhan
parent
0e276c4e63
commit
20b0e9cc61
@@ -4,12 +4,26 @@ Describe "Get-Process for admin" -Tags @('CI', 'RequireAdminOnWindows') {
|
||||
It "Should support -IncludeUserName" {
|
||||
(Get-Process -Id $pid -IncludeUserName).UserName | Should Match $env:USERNAME
|
||||
}
|
||||
|
||||
It "Should support -Module" -Pending:$IsMacOS {
|
||||
$modules = Get-Process -Id $pid -Module
|
||||
$modules.GetType() | Should -BeExactly "System.Object[]"
|
||||
foreach ($module in $modules) {
|
||||
$module.GetType() | Should -BeExactly "System.Diagnostics.ProcessModule"
|
||||
}
|
||||
}
|
||||
|
||||
It "Should support -FileVersionInfo" -Skip:(!$IsWindows) {
|
||||
$pwshVersion = Get-Process -Id $pid -FileVersionInfo
|
||||
$PSVersionTable.PSVersion | Should -Match $pwshVersion.FileVersion
|
||||
}
|
||||
}
|
||||
|
||||
Describe "Get-Process" -Tags "CI" {
|
||||
# These tests are no good, please replace!
|
||||
BeforeAll {
|
||||
$ps = Get-Process
|
||||
$idleProcessPid = 0
|
||||
}
|
||||
It "Should return a type of Object[] for Get-Process cmdlet" -Pending:$IsMacOS {
|
||||
,$ps | Should BeOfType "System.Object[]"
|
||||
@@ -18,6 +32,43 @@ Describe "Get-Process" -Tags "CI" {
|
||||
It "Should have not empty Name flags set for Get-Process object" -Pending:$IsMacOS {
|
||||
$ps | foreach-object { $_.Name | Should Not BeNullOrEmpty }
|
||||
}
|
||||
|
||||
It "Should throw an error for non existing process id." {
|
||||
$randomId = 123456789
|
||||
{ Get-Process -Id $randomId -ErrorAction Stop } | Should -Throw -ErrorId "NoProcessFoundForGivenId,Microsoft.PowerShell.Commands.GetProcessCommand"
|
||||
}
|
||||
|
||||
It "Should throw an exception when process id is null." {
|
||||
{ Get-Process -id $null } | Should -Throw -ErrorId "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.GetProcessCommand"
|
||||
}
|
||||
|
||||
It "Should throw an exception when -InputObject parameter is null." {
|
||||
{ Get-Process -InputObject $null } | Should -Throw -ErrorId "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.GetProcessCommand"
|
||||
}
|
||||
|
||||
It "Should not fail to get process name even if it is unavailable." {
|
||||
{ (Get-Process -Id $idleProcessPid).Name } | Should -Not -Throw
|
||||
}
|
||||
|
||||
It "Test for process property = Name" {
|
||||
(Get-Process -Id $pid).Name | Should -BeExactly "pwsh"
|
||||
}
|
||||
|
||||
It "Test for process property = Id" {
|
||||
(Get-Process -Id $pid).Id | Should -BeExactly $pid
|
||||
}
|
||||
|
||||
It "Should fail to run Get-Process with -IncludeUserName without admin" -Skip:(!$IsWindows) {
|
||||
{ Get-Process -IncludeUserName } | Should -Throw -ErrorId "IncludeUserNameRequiresElevation,Microsoft.PowerShell.Commands.GetProcessCommand"
|
||||
}
|
||||
|
||||
It "Should fail to run Get-Process with -Module without admin" -Skip:(!$IsWindows) {
|
||||
{ Get-Process -Module -ErrorAction Stop } | Should -Throw -ErrorId "CouldNotEnumerateModules,Microsoft.PowerShell.Commands.GetProcessCommand"
|
||||
}
|
||||
|
||||
It "Should fail to run Get-Process with -FileVersionInfo without admin" -Skip:(!$IsWindows) {
|
||||
{ Get-Process -FileVersionInfo -ErrorAction Stop } | Should -Throw -ErrorId "CouldNotEnumerateFileVer,Microsoft.PowerShell.Commands.GetProcessCommand"
|
||||
}
|
||||
}
|
||||
|
||||
Describe "Get-Process Formatting" -Tags "Feature" {
|
||||
|
||||
Reference in New Issue
Block a user