From df3371990529ae64f481760f1edb7ccdbb89d9d7 Mon Sep 17 00:00:00 2001 From: stknohg Date: Fri, 26 Jan 2018 11:10:22 +0900 Subject: [PATCH 1/3] Use 'RequireAdminOnWindows' tag instead of 'Test-IsElevated' function. --- .../Set-Date.Tests.ps1 | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 index 8a7f664e854..c8e0981f417 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 @@ -1,22 +1,18 @@ -# 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') { + It "Set-Date should be able to set the date in an elevated context" { { 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" { $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' { + # Currently CI tests on Linux/macOS are always run as sudo, so we need to skip this test on non-Windows platform. + It "Set-Date should produce an error in a non-elevated context" -Skip:(!$IsWindows) { { Get-Date | Set-Date } | ShouldBeErrorId "System.ComponentModel.Win32Exception,Microsoft.PowerShell.Commands.SetDateCommand" } } From ff9a0dde9d655efbe1460e0fab8e3f5dcf7ddee2 Mon Sep 17 00:00:00 2001 From: stknohg Date: Sat, 27 Jan 2018 08:30:13 +0900 Subject: [PATCH 2/3] Fix incorrect condition of user privilege in Linux/macOS CI --- .../Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 index c8e0981f417..9ff222e52da 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 @@ -1,9 +1,10 @@ Describe "Set-Date for admin" -Tag @('CI', 'RequireAdminOnWindows') { - It "Set-Date should be able to set the date in an elevated context" { + # Currently, CI tests on Linux/macOS are always run as normal user. So we need to skip these tests on non-Windows platform. + 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" { + 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 @@ -11,8 +12,7 @@ Describe "Set-Date for admin" -Tag @('CI', 'RequireAdminOnWindows') { } Describe "Set-Date" -Tag 'CI' { - # Currently CI tests on Linux/macOS are always run as sudo, so we need to skip this test on non-Windows platform. - It "Set-Date should produce an error in a non-elevated context" -Skip:(!$IsWindows) { + It "Set-Date should produce an error in a non-elevated context" { { Get-Date | Set-Date } | ShouldBeErrorId "System.ComponentModel.Win32Exception,Microsoft.PowerShell.Commands.SetDateCommand" } } From 9d328a296aea505f4515d04b77c349a861ad6423 Mon Sep 17 00:00:00 2001 From: stknohg Date: Mon, 29 Jan 2018 15:35:54 +0900 Subject: [PATCH 3/3] Add link to #5645 --- .../Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 index 9ff222e52da..c5950aa7160 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 @@ -1,5 +1,7 @@ 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 }