-
Notifications
You must be signed in to change notification settings - Fork 113
Add PSContentPath Standard Platform Paths #1912
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
+198
−8
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5f00798
Add experimental feature check and add PSContentPath to standard plat…
jshigetomi 7d03376
Use Json.net to parse instead
jshigetomi bbb7148
Add support in Linux, MacOS and refactor
jshigetomi d53dd08
Use PowerShell GetPSModulePath API instead
jshigetomi a454cb3
Use runspace instead of reflection
jshigetomi 94a1563
Use current runspace and only get PSVersion once
jshigetomi 26c5bf8
Add tests and test hooks
jshigetomi 536b1ed
Use pwsh variable PSContentPath instead of cmdlet Get-PSContentPath
jshigetomi eafe88b
remove try catch for auomatic variable
jshigetomi af96e1a
Merge branch 'master' into PSContentPath
jshigetomi 06c3d4c
Address PSContentPath review feedback
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '')] | ||
| Param() | ||
|
|
||
| $ProgressPreference = "SilentlyContinue" | ||
| $modPath = "$psscriptroot/PSGetTestUtils.psm1" | ||
| Import-Module $modPath -Force | ||
|
|
||
| Describe 'PSUserContentPath/PSContentPath - End-to-End Install Location' -Tags 'CI' { | ||
| BeforeAll { | ||
| $script:originalPSModulePath = $env:PSModulePath | ||
| $psUserContentPathVariable = Get-Variable -Name PSUserContentPath -ErrorAction SilentlyContinue | ||
| $script:psUserContentPathAvailable = $null -ne $psUserContentPathVariable ` | ||
| -and $psUserContentPathVariable.Value -is [string] ` | ||
| -and -not [string]::IsNullOrWhiteSpace($psUserContentPathVariable.Value) | ||
| $script:sessionContentPath = if ($script:psUserContentPathAvailable) { | ||
| $psUserContentPathVariable.Value | ||
| } else { | ||
| $null | ||
| } | ||
| $script:legacyContentPath = if (Get-IsWindows) { | ||
| Split-Path -Path (Get-CurrentUserModulesPath) -Parent | ||
| } else { | ||
| Join-Path -Path $env:HOME -ChildPath '.local/share/powershell' | ||
| } | ||
| $script:isCustomContentPath = $script:psUserContentPathAvailable ` | ||
| -and $script:sessionContentPath -ne $script:legacyContentPath | ||
|
|
||
| $localRepo = "psgettestlocal" | ||
| $testModuleName = "PSContentPathTestModule" | ||
| Get-NewPSResourceRepositoryFile | ||
| Register-LocalRepos | ||
|
|
||
| # Create a test module | ||
| New-TestModule -moduleName $testModuleName -repoName $localRepo -packageVersion "1.0.0" -prereleaseLabel "" -tags @() | ||
| } | ||
|
|
||
| AfterEach { | ||
| # Restore PSModulePath | ||
| $env:PSModulePath = $script:originalPSModulePath | ||
| # Clean up installed test modules from every scope exercised by the tests | ||
| Uninstall-PSResource $testModuleName -Version "*" -Scope CurrentUser -SkipDependencyCheck -ErrorAction SilentlyContinue | ||
| if ((Get-IsWindows) -and (Test-IsAdmin)) { | ||
| Uninstall-PSResource $testModuleName -Version "*" -Scope AllUsers -SkipDependencyCheck -ErrorAction SilentlyContinue | ||
| } | ||
| # Clear testing hooks | ||
| [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::ClearPSContentPathHooks() | ||
| } | ||
|
|
||
| AfterAll { | ||
| Get-RevertPSResourceRepositoryFile | ||
| } | ||
|
|
||
| Context 'PSResourceGet user content path selection' { | ||
| It 'Should use $PSUserContentPath when available, Legacy when not' { | ||
| Install-PSResource -Name $testModuleName -Repository $localRepo -Scope CurrentUser -TrustRepository | ||
|
|
||
| $pathSource = [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::GetTestHook("LastUserContentPathSource") | ||
| $pathUsed = [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::GetTestHook("LastUserContentPath") | ||
|
|
||
| if ($script:psUserContentPathAvailable) { | ||
| $pathSource | Should -Be '$PSUserContentPath' | ||
| $pathUsed | Should -Be $script:sessionContentPath | ||
| } else { | ||
| $pathSource | Should -Be "Legacy" | ||
| $pathUsed | Should -Be $script:legacyContentPath | ||
| } | ||
|
|
||
| # Module should be installed | ||
| $res = Get-InstalledPSResource -Name $testModuleName -Scope CurrentUser | ||
| $res.Name | Should -Be $testModuleName | ||
| } | ||
| } | ||
|
|
||
| Context 'When a custom $PSUserContentPath is configured' { | ||
| It "Should install to the custom user content path" { | ||
| if (-not $script:isCustomContentPath) { | ||
| Set-ItResult -Skipped -Because "A custom PSUserContentPath is not configured in this session" | ||
| return | ||
| } | ||
|
|
||
| Install-PSResource -Name $testModuleName -Repository $localRepo -Scope CurrentUser -TrustRepository | ||
|
|
||
| $pathSource = [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::GetTestHook("LastUserContentPathSource") | ||
| $pathUsed = [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::GetTestHook("LastUserContentPath") | ||
|
|
||
| $pathSource | Should -Be '$PSUserContentPath' | ||
| $pathUsed | Should -Be $script:sessionContentPath | ||
|
|
||
| # Module should be installed in custom path | ||
| $res = Get-InstalledPSResource -Name $testModuleName -Scope CurrentUser | ||
| $expectedModulesPath = Join-Path $script:sessionContentPath 'Modules' | ||
| $expectedModulePath = Join-Path $expectedModulesPath $testModuleName | ||
| Test-Path $expectedModulePath | Should -BeTrue | ||
| $res.Name | Should -Be $testModuleName | ||
| $res.InstalledLocation | Should -Be $expectedModulesPath | ||
| } | ||
| } | ||
|
|
||
| Context 'PSResourceGet delegates user content path resolution' { | ||
| It 'Should use $PSUserContentPath when the variable is available' { | ||
| if (-not $script:psUserContentPathAvailable) { | ||
| Set-ItResult -Skipped -Because "PSUserContentPath is not available" | ||
| return | ||
| } | ||
|
|
||
| $beforePath = $PSUserContentPath | ||
|
|
||
| Install-PSResource -Name $testModuleName -Repository $localRepo -Scope CurrentUser -TrustRepository | ||
|
|
||
| $pathSource = [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::GetTestHook("LastUserContentPathSource") | ||
| $pathUsed = [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::GetTestHook("LastUserContentPath") | ||
|
|
||
| $pathSource | Should -Be '$PSUserContentPath' | ||
|
|
||
| # Path should match the engine-provided session value | ||
| $pathUsed | Should -Be $beforePath | ||
|
|
||
| # Module should be installed | ||
| $res = Get-InstalledPSResource -Name $testModuleName -Scope CurrentUser | ||
| $res.Name | Should -Be $testModuleName | ||
| } | ||
| } | ||
|
|
||
| Context "AllUsers scope should not be affected by PSContentPath/PSUserContentPath" { | ||
| It "Should install to the shared PowerShell modules path" -Skip:(!((Get-IsWindows) -and (Test-IsAdmin))) { | ||
| Install-PSResource -Name $testModuleName -Repository $localRepo -Scope AllUsers -TrustRepository | ||
| $expectedModulesPath = Get-AllUsersModulesPath | ||
| $expectedModulePath = Join-Path $expectedModulesPath $testModuleName | ||
| Test-Path $expectedModulePath | Should -BeTrue | ||
| $res = Get-InstalledPSResource -Name $testModuleName -Scope AllUsers | ||
| $res.Name | Should -Be $testModuleName | ||
| $res.InstalledLocation | Should -Be $expectedModulesPath | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.