Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit cfb6180

Browse files
authored
Fix 1815 - Get-InstalledPSResource -Path don't throw if no subdirectories were found (#1877)
1 parent 7f619c0 commit cfb6180

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

‎src/code/GetInstalledPSResource.cs‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,16 @@ protected override void BeginProcessing()
101101
var versionPaths = Utils.GetSubDirectories(resolvedPath);
102102
if (versionPaths.Length == 0)
103103
{
104-
ThrowTerminatingError(new ErrorRecord(
104+
WriteError(new ErrorRecord(
105105
new PSInvalidOperationException($"Error cannot find expected subdirectories in provided path: {Path}"),
106106
"PathMissingExpectedSubdirectories",
107107
ErrorCategory.InvalidOperation,
108108
this));
109109
}
110-
111-
_pathsToSearch.AddRange(versionPaths);
110+
else
111+
{
112+
_pathsToSearch.AddRange(versionPaths);
113+
}
112114
}
113115
else
114116
{

‎test/GetInstalledPSResource/GetInstalledPSResource.Tests.ps1‎

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,27 @@ Describe 'Test Get-InstalledPSResource for Module' -tags 'CI' {
1111
$PSGalleryName = Get-PSGalleryName
1212
$testModuleName = "test_module"
1313
$testScriptName = "test_script"
14+
$TestEmptyDirectoryPath = [System.IO.Path]::Combine($env:TEMP,'EmptyDir')
15+
1416
Get-NewPSResourceRepositoryFile
1517

1618
Install-PSResource -Name $testModuleName -Repository $PSGalleryName -TrustRepository
1719
Install-PSResource -Name $testModuleName -Repository $PSGalleryName -TrustRepository -Version "1.0"
1820
Install-PSResource -Name $testModuleName -Repository $PSGalleryName -TrustRepository -Version "3.0"
1921
Install-PSResource -Name $testModuleName -Repository $PSGalleryName -TrustRepository -Version "5.0"
2022
Install-PSResource -Name $testScriptName -Repository $PSGalleryName -TrustRepository
23+
24+
$null = New-Item -Path $TestEmptyDirectoryPath -ItemType 'Directory'
2125
}
2226

2327
AfterAll {
2428
Uninstall-PSResource -Name $testModuleName -Version "*" -ErrorAction SilentlyContinue
2529
Uninstall-PSResource -Name $testScriptName -Version "*" -ErrorAction SilentlyContinue
2630
Get-RevertPSResourceRepositoryFile
31+
32+
if (Test-Path -Path $TestEmptyDirectoryPath -PathType 'Container') {
33+
Remove-Item -Path $TestEmptyDirectoryPath -Recurse -Force
34+
}
2735
}
2836

2937
It "Get resources without any parameter values" {
@@ -54,16 +62,17 @@ Describe 'Test Get-InstalledPSResource for Module' -tags 'CI' {
5462
$pkgs.Name | Should -Contain $testModuleName
5563
}
5664

57-
$testCases =
58-
@{Version="[1.0.0.0]"; ExpectedVersion="1.0.0.0"; Reason="validate version, exact match"},
59-
@{Version="1.0.0.0"; ExpectedVersion="1.0.0.0"; Reason="validate version, exact match without bracket syntax"},
60-
@{Version="[1.0.0.0, 5.0.0.0]"; ExpectedVersion=@("5.0.0.0", "3.0.0.0", "1.0.0.0"); Reason="validate version, exact range inclusive"},
61-
@{Version="(1.0.0.0, 5.0.0.0)"; ExpectedVersion=@("3.0.0.0"); Reason="validate version, exact range exclusive"},
62-
@{Version="(1.0.0.0,)"; ExpectedVersion=@("5.0.0.0", "3.0.0.0"); Reason="validate version, minimum version exclusive"},
63-
@{Version="[1.0.0.0,)"; ExpectedVersion=@("5.0.0.0", "3.0.0.0", "1.0.0.0"); Reason="validate version, minimum version inclusive"},
64-
@{Version="(,5.0.0.0)"; ExpectedVersion=@("3.0.0.0", "1.0.0.0"); Reason="validate version, maximum version exclusive"},
65-
@{Version="(,5.0.0.0]"; ExpectedVersion=@("5.0.0.0", "3.0.0.0", "1.0.0.0"); Reason="validate version, maximum version inclusive"},
66-
@{Version="[1.0.0.0, 5.0.0.0)"; ExpectedVersion=@("3.0.0.0", "1.0.0.0"); Reason="validate version, mixed inclusive minimum and exclusive maximum version"}
65+
$testCases = [array](
66+
@{Version="[1.0.0.0]"; ExpectedVersion="1.0.0.0"; Reason="validate version, exact match"},
67+
@{Version="1.0.0.0"; ExpectedVersion="1.0.0.0"; Reason="validate version, exact match without bracket syntax"},
68+
@{Version="[1.0.0.0, 5.0.0.0]"; ExpectedVersion=@("5.0.0.0", "3.0.0.0", "1.0.0.0"); Reason="validate version, exact range inclusive"},
69+
@{Version="(1.0.0.0, 5.0.0.0)"; ExpectedVersion=@("3.0.0.0"); Reason="validate version, exact range exclusive"},
70+
@{Version="(1.0.0.0,)"; ExpectedVersion=@("5.0.0.0", "3.0.0.0"); Reason="validate version, minimum version exclusive"},
71+
@{Version="[1.0.0.0,)"; ExpectedVersion=@("5.0.0.0", "3.0.0.0", "1.0.0.0"); Reason="validate version, minimum version inclusive"},
72+
@{Version="(,5.0.0.0)"; ExpectedVersion=@("3.0.0.0", "1.0.0.0"); Reason="validate version, maximum version exclusive"},
73+
@{Version="(,5.0.0.0]"; ExpectedVersion=@("5.0.0.0", "3.0.0.0", "1.0.0.0"); Reason="validate version, maximum version inclusive"},
74+
@{Version="[1.0.0.0, 5.0.0.0)"; ExpectedVersion=@("3.0.0.0", "1.0.0.0"); Reason="validate version, mixed inclusive minimum and exclusive maximum version"}
75+
)
6776

6877
It "Get resource when given Name to <Reason> <Version>" -TestCases $testCases {
6978
param($Version, $ExpectedVersion)
@@ -144,8 +153,12 @@ $testCases =
144153
(Get-Alias Get-PSResource).Definition | Should -BeExactly 'Get-InstalledPSResource'
145154
}
146155

147-
# Windows only
148-
It "Get resource under CurrentUser scope - Windows only" -Skip:(!(Get-IsWindows)) {
156+
It "Should not throw on ErrorAction ignore when no subdirectories are found" {
157+
{ Get-InstalledPSResource -Path $TestEmptyDirectoryPath -ErrorAction 'Ignore' } | Should -Not -Throw
158+
}
159+
160+
# Windows only
161+
It "Get resource under CurrentUser scope - Windows only" -Skip:(!(Get-IsWindows)) {
149162
$pkg = Get-InstalledPSResource -Name $testModuleName -Scope CurrentUser
150163
$pkg[0].Name | Should -Be $testModuleName
151164
$pkg[0].InstalledLocation.ToString().Contains("Documents") | Should -Be $true

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /