From 7ee22063c565541c2aa2e04f908567f1187f3f91 Mon Sep 17 00:00:00 2001 From: "James Truher [MSFT]" Date: Mon, 27 Mar 2023 14:54:53 -0700 Subject: [PATCH] Improve package management acceptance tests by not going to the gallery (#19412) --- .../PackageManagement.Tests.ps1 | 72 ++++++++++-------- .../assets/PowerShell.TestPackage.3.2.1.nupkg | Bin 0 -> 3225 bytes 2 files changed, 41 insertions(+), 31 deletions(-) create mode 100644 test/powershell/Modules/PackageManagement/assets/PowerShell.TestPackage.3.2.1.nupkg diff --git a/test/powershell/Modules/PackageManagement/PackageManagement.Tests.ps1 b/test/powershell/Modules/PackageManagement/PackageManagement.Tests.ps1 index 3fea57db36..bd4d0218f5 100644 --- a/test/powershell/Modules/PackageManagement/PackageManagement.Tests.ps1 +++ b/test/powershell/Modules/PackageManagement/PackageManagement.Tests.ps1 @@ -13,34 +13,36 @@ # # ------------------ PackageManagement Test ----------------------------------- -$gallery = "https://www.powershellgallery.com/api/v2" -$source = 'OneGetTestSource' - Describe "PackageManagement Acceptance Test" -Tags "Feature" { - BeforeAll{ - Register-PackageSource -Name Nugettest -provider NuGet -Location https://www.nuget.org/api/v2 -Force + BeforeAll { + # the package name for testing + $packageName = "PowerShell.TestPackage" - $packageSource = Get-PackageSource -Location $gallery -ErrorAction SilentlyContinue - if ($packageSource) { - $source = $packageSource.Name - Set-PackageSource -Name $source -Trusted - } else { - Register-PackageSource -Name $source -Location $gallery -ProviderName 'PowerShellGet' -Trusted -ErrorAction SilentlyContinue + # register the asset directory + $localSourceName = [Guid]::NewGuid().ToString("n") + $localSourceLocation = Join-Path $PSScriptRoot assets + Register-PackageSource -Name $localSourceName -provider NuGet -Location $localSourceLocation -Force -Trusted + + # register the gallery location + $galleryLocation = "https://www.powershellgallery.com/api/v2" + $gallerySourceName = [Guid]::newGuid().ToString("n") + Register-PackageSource -Name $gallerySourceName -Location $galleryLocation -ProviderName 'PowerShellGet' -Trusted -ErrorAction SilentlyContinue + + $SavedProgressPreference = $ProgressPreference + $ProgressPreference = "SilentlyContinue" + } + + AfterAll { + $ProgressPreference = $SavedProgressPreference + Unregister-PackageSource -Source $localSourceName -ErrorAction Ignore + Unregister-PackageSource -Name $gallerySourceName -ErrorAction Ignore + Uninstall-Module NanoServerPackage -ErrorAction Ignore -WarningAction SilentlyContinue } - $SavedProgressPreference = $ProgressPreference - $ProgressPreference = "SilentlyContinue" - } - AfterAll { - $ProgressPreference = $SavedProgressPreference - } It "get-packageprovider" { - $gpp = Get-PackageProvider - $gpp.Name | Should -Contain 'NuGet' - $gpp.Name | Should -Contain 'PowerShellGet' } @@ -50,32 +52,40 @@ Describe "PackageManagement Acceptance Test" -Tags "Feature" { } It "install-packageprovider, Expect succeed" { - $ipp = (Install-PackageProvider -Name NanoServerPackage -Force -Source $source -Scope CurrentUser).name + Set-ItResult -Pending -Because "local test package provider not installable" + $ippArgs = @{ + Name = "NanoServerPackage" + Force = $true + Source = $galleryLocation + Scope = "CurrentUser" + WarningAction = "SilentlyContinue" + } + $ipp = (Install-PackageProvider @ippArgs).name $ipp | Should -Contain "NanoServerPackage" } It "Find-package" { - $f = Find-Package -ProviderName NuGet -Name jquery -Source Nugettest - $f.Name | Should -Contain "jquery" + $f = Find-Package -ProviderName NuGet -Name $packageName -Source $localSourceName + $f.Name | Should -Contain "$packageName" } It "Install-package" { - $i = Install-Package -ProviderName NuGet -Name jquery -Force -Source Nugettest -Scope CurrentUser - $i.Name | Should -Contain "jquery" + $i = Install-Package -ProviderName NuGet -Name $packageName -Force -Source $localSourceName -Scope CurrentUser + $i.Name | Should -Contain "$packageName" } It "Get-package" { - $g = Get-Package -ProviderName NuGet -Name jquery - $g.Name | Should -Contain "jquery" + $g = Get-Package -ProviderName NuGet -Name $packageName + $g.Name | Should -Contain "$packageName" } It "save-package" { - $s = Save-Package -ProviderName NuGet -Name jquery -Path $TestDrive -Force -Source Nugettest - $s.Name | Should -Contain "jquery" + $s = Save-Package -ProviderName NuGet -Name $packageName -Path $TestDrive -Force -Source $localSourceName + $s.Name | Should -Contain "$packageName" } It "uninstall-package" { - $u = Uninstall-Package -ProviderName NuGet -Name jquery - $u.Name | Should -Contain "jquery" + $u = Uninstall-Package -ProviderName NuGet -Name $packageName + $u.Name | Should -Contain "$packageName" } } diff --git a/test/powershell/Modules/PackageManagement/assets/PowerShell.TestPackage.3.2.1.nupkg b/test/powershell/Modules/PackageManagement/assets/PowerShell.TestPackage.3.2.1.nupkg new file mode 100644 index 0000000000000000000000000000000000000000..bc3a6d9b094ff479b0acef2b1e54415e559c339d GIT binary patch literal 3225 zcmb_ecU03$8Vy}Rib(Y-hy|1qLMMWvB1ixUH7cTzgh&ku5K10B5I{sB5E1DmAWe9R zG=b1jKp@ha5D^fh3ZW=%;}OPy%i-QxuE{WeVYXO~9FDJpd^KrOxNN-$ey%!- zH3Sp7h?IU#-7+t?w=i&xG zlPCCL*gB$my5C|Hadqhsqa@*~u25Qp@S*PLDoD&Gmf(MT)2#f8r@9?E)VVO?EK5Z{8>^YVoiy zf-Gr%^FcdgD4Ihh(d#8?re&Q~Ys^7VA_RRVOT*%n$ROEiC2?5uHY=LChVI*888>G?N zV*DHQ%R99iO-q+5UQ{?waxMEUZ?938H)}T&V}?s5E#e}rLF(#}1Lr78-yN)*X26S5T^VRtg0&M73oM$Uf zEP`j7v|gIb2yspT@I+$L_zSy#eqtg)TR6TyxP(3NiFNktk)xGJsjkAbWpN=moBl0F z=R(OoWWgKs;DHz1@016Mw|81An%?n-t&zui4DqLHi8c#xXV)vAT8?~@A5rMB)h@c% zM|$^`mPdOPr|^YPwR}8_|EA{ms1OHmuA=tF=_bMLnFkD3XZQj}@eZVlC;REa8Lt1B3Mzb3nOLKSSQ$}Z1&UcK=^0)cTY5GNvBd!EJ=%Llf z;bE&9XX>QBdD1Ooq@B^vTy4_4^eh4$pb33Da;8>$KEXvjhe;9yGS-MW^v%mws2Elh*_8zF+K*6IQi=TC3aA(=b(CyRA+R@7HCm0onI-XfBOj zA_}E5kh*Yu<8w=e+p;`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