From acbdf90193a61b114d1be7b9955ce124fed7098e Mon Sep 17 00:00:00 2001 From: Anam Navied Date: Wed, 8 Dec 2021 17:30:30 -0500 Subject: [PATCH 1/3] for errors being written in Save write to a variable --- test/SavePSResource.Tests.ps1 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/SavePSResource.Tests.ps1 b/test/SavePSResource.Tests.ps1 index 66858ce6d..067baecbb 100644 --- a/test/SavePSResource.Tests.ps1 +++ b/test/SavePSResource.Tests.ps1 @@ -52,9 +52,11 @@ Describe 'Test Save-PSResource for PSResources' { } It "Should not save resource given nonexistant name" { - Save-PSResource -Name NonExistentModule -Repository $TestGalleryName -Path $SaveDir + Save-PSResource -Name NonExistentModule -Repository $TestGalleryName -Path $SaveDir -ErrorVariable err -ErrorAction SilentlyContinue $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq "NonExistentModule" $pkgDir.Name | Should -BeNullOrEmpty + $err.Count | Should -Not -Be 0 + $err[0].FullyQualifiedErrorId | Should -BeExactly "ResourceNotFoundError,Microsoft.PowerShell.PowerShellGet.Cmdlets.SavePSResource" } It "Not Save module with Name containing wildcard" { @@ -102,9 +104,11 @@ Describe 'Test Save-PSResource for PSResources' { ) { param($Version, $Description) - Save-PSResource -Name $testModuleName2 -Version $Version -Repository $TestGalleryName -Path $SaveDir + Save-PSResource -Name $testModuleName2 -Version $Version -Repository $TestGalleryName -Path $SaveDir -ErrorVariable err -ErrorAction SilentlyContinue $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq $testModuleName2 $pkgDir | Should -BeNullOrEmpty + $err.Count | Should -Not -Be 0 + $err[0].FullyQualifiedErrorId | Should -BeExactly "ResourceNotFoundError,Microsoft.PowerShell.PowerShellGet.Cmdlets.SavePSResource" } It "Save resource when given Name, Version '*', should install the latest version" { From 4974b385c06bd5876e86a51053231f2231356825 Mon Sep 17 00:00:00 2001 From: Anam Navied Date: Wed, 8 Dec 2021 17:50:38 -0500 Subject: [PATCH 2/3] for Uninstall, fix errors being written --- test/UninstallPSResource.Tests.ps1 | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/test/UninstallPSResource.Tests.ps1 b/test/UninstallPSResource.Tests.ps1 index 3c4bcdc66..906c36037 100644 --- a/test/UninstallPSResource.Tests.ps1 +++ b/test/UninstallPSResource.Tests.ps1 @@ -43,15 +43,19 @@ Describe 'Test Uninstall-PSResource for Modules' { } It "Uninstall a specific script by name" { - $null = Install-PSResource Test-RPC -Repository $TestGalleryName -TrustRepository -WarningAction SilentlyContinue - - Uninstall-PSResource -name Test-RPC + $null = Install-PSResource "test_script" -Repository $TestGalleryName -TrustRepository -WarningAction SilentlyContinue + Uninstall-PSResource -name "test_script" + $res = Get-PSResource -Name "test_script" + $res | Should -BeNullOrEmpty } It "Uninstall a list of scripts by name" { - $null = Install-PSResource adsql, airoute -Repository $TestGalleryName -TrustRepository -WarningAction SilentlyContinue - - Uninstall-PSResource -Name adsql, airoute + $null = Install-PSResource "test_script", "TestTestScript" -Repository $TestGalleryName -TrustRepository -WarningAction SilentlyContinue + Uninstall-PSResource -Name "test_script", "TestTestScript" + $res = Get-PSResource -Name "test_script" + $res2 = Get-PSResource -Name "TestTestScript" + $res | Should -BeNullOrEmpty + $res2 | Should -BeNullOrEmpty } It "Uninstall a module when given name and specifying all versions" { From e4259626c368ea68fa78c9efd33f34b145005d00 Mon Sep 17 00:00:00 2001 From: Anam Navied Date: Wed, 8 Dec 2021 19:03:11 -0500 Subject: [PATCH 3/3] add more verification that Install step also worked --- test/UninstallPSResource.Tests.ps1 | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test/UninstallPSResource.Tests.ps1 b/test/UninstallPSResource.Tests.ps1 index 906c36037..eba8cfbc5 100644 --- a/test/UninstallPSResource.Tests.ps1 +++ b/test/UninstallPSResource.Tests.ps1 @@ -43,14 +43,22 @@ Describe 'Test Uninstall-PSResource for Modules' { } It "Uninstall a specific script by name" { - $null = Install-PSResource "test_script" -Repository $TestGalleryName -TrustRepository -WarningAction SilentlyContinue + $null = Install-PSResource "test_script" -Repository $TestGalleryName -TrustRepository + $res = Get-PSResource -Name "test_script" + $res.Name | Should -Be "test_script" + Uninstall-PSResource -name "test_script" $res = Get-PSResource -Name "test_script" $res | Should -BeNullOrEmpty } It "Uninstall a list of scripts by name" { - $null = Install-PSResource "test_script", "TestTestScript" -Repository $TestGalleryName -TrustRepository -WarningAction SilentlyContinue + $null = Install-PSResource "test_script", "TestTestScript" -Repository $TestGalleryName -TrustRepository + $res = Get-PSResource -Name "test_script" + $res2 = Get-PSResource -Name "TestTestScript" + $res.Name | Should -Be "test_script" + $res2.Name | Should -Be "TestTestScript" + Uninstall-PSResource -Name "test_script", "TestTestScript" $res = Get-PSResource -Name "test_script" $res2 = Get-PSResource -Name "TestTestScript"