Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use 'RequireAdminOnWindows' tag in Set-Date tests (#6034)
* Use 'RequireAdminOnWindows' tag instead of 'Test-IsElevated' function. * Fix incorrect condition of user privilege in Linux/macOS CI
- Loading branch information
1 parent
99a7d38
commit 22014a9
Showing
1 changed file
with
9 additions
and
11 deletions.
There are no files selected for viewing
20 changes: 9 additions & 11 deletions
20
test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,20 @@ | ||
# first check to see which platform we're on. If we're on windows we should be able | ||
# to be sure whether we're running elevated. If we're on Linux, we can use whoami to | ||
# determine whether we're elevated | ||
Describe "Set-Date" -Tag "CI" { | ||
BeforeAll { | ||
$IsElevated = Test-IsElevated | ||
} | ||
|
||
It "Set-Date should be able to set the date in an elevated context" -Skip:(! $IsElevated) { | ||
Describe "Set-Date for admin" -Tag @('CI', 'RequireAdminOnWindows') { | ||
# Currently, CI tests on Linux/macOS are always run as normal user. So we need to skip these tests on non-Windows platform. | ||
# CI tests in root privilege on Linux/macOS is not supported. | ||
# See : https://github.com/PowerShell/PowerShell/issues/5645 | ||
It "Set-Date should be able to set the date in an elevated context" -Skip:(!$IsWindows) { | ||
{ Get-Date | Set-Date } | Should Not Throw | ||
} | ||
|
||
It "Set-Date should be able to set the date with -Date parameter" -Skip:(! $IsElevated) { | ||
It "Set-Date should be able to set the date with -Date parameter" -Skip:(!$IsWindows) { | ||
$target = Get-Date | ||
$expected = $target | ||
Set-Date -Date $target | Should Be $expected | ||
} | ||
} | ||
|
||
It "Set-Date should produce an error in a non-elevated context" -Skip:($IsElevated) { | ||
Describe "Set-Date" -Tag 'CI' { | ||
It "Set-Date should produce an error in a non-elevated context" { | ||
{ Get-Date | Set-Date } | ShouldBeErrorId "System.ComponentModel.Win32Exception,Microsoft.PowerShell.Commands.SetDateCommand" | ||
} | ||
} |