Skip to content

Fixed failing tests on Windows when not an Administrator #502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/InstallPSResource.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Describe 'Test Install-PSResource for Module' {
}

# Windows only
It "Install resource under AllUsers scope - Windows only" -Skip:(!(Get-IsWindows)) {
It "Install resource under AllUsers scope - Windows only" -Skip:(!((Get-IsWindows) -and (Test-IsAdmin))) {
Install-PSResource -Name "TestModule" -Repository $TestGalleryName -Scope AllUsers
$pkg = Get-Module "TestModule" -ListAvailable
$pkg.Name | Should -Be "TestModule"
Expand Down
9 changes: 9 additions & 0 deletions test/PSGetTestUtils.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ $script:moduleSourcesFilePath = Microsoft.PowerShell.Management\Join-Path -Path
$script:CurrentPSGetFormatVersion = "1.0"
$script:PSGetFormatVersionPrefix = "PowerShellGetFormatVersion_"

function Test-IsAdmin {
[OutputType([bool])]
param()

[System.Security.Principal.WindowsPrincipal]::new(
[Security.Principal.WindowsIdentity]::GetCurrent()
).IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)
}

function Get-IsWindows {
return $script:IsWindows
}
Expand Down
2 changes: 1 addition & 1 deletion test/UpdatePSResource.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ Describe 'Test Update-PSResource' {
}

# Windows only
It "update resource under AllUsers scope" -skip:(!$IsWindows) {
It "update resource under AllUsers scope" -skip:(!($IsWindows -and (Test-IsAdmin))) {
Install-PSResource -Name "TestModule" -Version "1.1.0.0" -Repository $TestGalleryName -Scope AllUsers
Install-PSResource -Name "TestModule" -Version "1.1.0.0" -Repository $TestGalleryName -Scope CurrentUser

Expand Down