Update Microsoft.PowerShell.PSResourceGet to 1.1.0-preview2 (#24300)

This commit is contained in:
alerickson
2024-09-23 14:58:24 -07:00
committed by GitHub
parent 389f9dba88
commit 669d9e384e
2 changed files with 110 additions and 1 deletions
+1 -1
View File
@@ -13,7 +13,7 @@
<ItemGroup>
<PackageReference Include="PowerShellGet" Version="2.2.5" />
<PackageReference Include="PackageManagement" Version="1.4.8.1" />
<PackageReference Include="Microsoft.PowerShell.PSResourceGet" Version="1.1.0-preview1" />
<PackageReference Include="Microsoft.PowerShell.PSResourceGet" Version="1.1.0-preview2" />
<PackageReference Include="Microsoft.PowerShell.Archive" Version="1.2.5" />
<PackageReference Include="PSReadLine" Version="2.3.5" />
<PackageReference Include="ThreadJob" Version="2.0.3" />
@@ -7,10 +7,20 @@ $ProgressPreference = "SilentlyContinue"
$RepositoryName = 'PSGallery'
$ACRRepositoryName = "ACRRepo"
$ACRRepoUri = "https://psresourcegettest.azurecr.io/"
$LocalRepoName = 'LocalRepo'
$TempDir = 'TempDir'
$LocalRepoUri = Microsoft.PowerShell.Management\Join-Path -Path $TempDir -ChildPath 'TempLocalRepoUri'
$TestModule = 'newTestModule'
$TestScript = 'TestTestScript'
$ACRTestModule = 'newTestMod'
$PublishedNupkgs = Microsoft.PowerShell.Management\Join-Path -Path $TempDir -ChildPath 'PublishedNupkgs'
$TestModuleNupkgName = "$TestModule.0.0.1.nupkg"
$TestModuleNupkgPath = Microsoft.PowerShell.Management\Join-Path -Path $PublishedNupkgs -ChildPath $TestModuleNupkgName
$TestScriptPath = "$TestScript.ps1"
$TestScriptNupkgName = "$TestScript.0.0.1.nupkg"
$TestScriptNupkgPath = Microsoft.PowerShell.Management\Join-Path -Path $PublishedNupkgs -ChildPath $TestScriptNupkgName
$Initialized = $false
#region Install locations for modules and scripts
@@ -72,6 +82,11 @@ if (!(Test-Path $script:MyDocumentsScriptsPath)) {
function Initialize
{
if(!(Test-Path $TempDir))
{
New-Item -Path $TempDir -ItemType Directory
}
$repo = Get-PSResourceRepository $RepositoryName -ErrorAction SilentlyContinue
if($repo)
{
@@ -97,6 +112,15 @@ function Initialize
}
}
function Register-LocalRepo
{
if (!(Test-Path $LocalRepoUri)) {
New-Item -Path $LocalRepoUri -ItemType Directory
}
Register-PSResourceRepository -Name $LocalRepoName -Uri $LocalRepoUri -Trusted -Force
}
#endregion
function Remove-InstalledModules
@@ -104,6 +128,28 @@ function Remove-InstalledModules
Get-InstalledPSResource -Name $TestModule -Version '*' -ErrorAction SilentlyContinue | Microsoft.PowerShell.PSResourceGet\Uninstall-PSResource
}
function New-TestPackages
{
if (!(Test-Path $PublishedNupkgs)) {
New-Item $PublishedNupkgs -ItemType Directory
}
if (!(Test-Path $TestModule)) {
New-Item $TestModule -ItemType Directory
}
$moduleManifestPath = Join-Path $TestModule -ChildPath "$TestModule.psd1"
if (!(Test-Path $moduleManifestPath))
{
New-ModuleManifest $moduleManifestPath -Description "Test module for PowerShell CI" -Author "PSGetAuthor"
}
if (!(Test-Path $TestScriptPath))
{
New-ScriptFileInfo -Path $TestScriptPath -Description "Test script for PowerShell CI" -Author "PSGetAuthor"
}
}
Describe "PSResourceGet - Module tests" -tags "Feature" {
BeforeAll {
@@ -111,6 +157,9 @@ Describe "PSResourceGet - Module tests" -tags "Feature" {
Initialize
$script:Initialized = $true
}
Register-LocalRepo
New-TestPackages
}
BeforeEach {
@@ -138,6 +187,39 @@ Describe "PSResourceGet - Module tests" -tags "Feature" {
}
}
It "Should publish a module" {
Publish-PSResource -Path $TestModule -Repository $LocalRepoName
$foundModuleInfo = Find-PSResource $TestModule -Repository $LocalRepoName
$foundModuleInfo | Should -Not -BeNullOrEmpty
$foundModuleInfo.Count | Should -Be 1
$foundModuleInfo.Name | Should -Be $TestModule
}
It "Should compress a module into a .nupkg" {
Compress-PSResource -Path $TestModule -DestinationPath $PublishedNupkgs
$modulePublished = Get-ChildItem $TestModuleNupkgPath
$modulePublished | Should -Not -BeNullOrEmpty
$modulePublished.Name | Should -Be $TestModuleNupkgName
}
It "Should publish compressed .nupkg" {
Compress-PSResource -Path $TestModule -DestinationPath $PublishedNupkgs
Publish-PSResource -NupkgPath $TestModuleNupkgPath -Repository $LocalRepoName
$foundModuleInfo = Find-PSResource $TestModule -Repository $LocalRepoName
$foundModuleInfo | Should -Not -BeNullOrEmpty
$foundModuleInfo.Count | Should -Be 1
$foundModuleInfo.Name | Should -Be $TestModule
}
AfterEach {
Get-ChildItem $PublishedNupkgs | Remove-Item -Recurse -Force
Get-ChildItem $LocalRepoUri | Remove-Item -Recurse -Force
}
AfterAll {
Remove-InstalledModules
}
@@ -181,6 +263,9 @@ Describe "PSResourceGet - Script tests" -tags "Feature" {
Initialize
$script:Initialized = $true
}
Register-LocalRepo
New-TestPackages
}
BeforeEach {
@@ -205,6 +290,20 @@ Describe "PSResourceGet - Script tests" -tags "Feature" {
}
}
It "Should publish a script" {
Publish-PSResource -Path $TestScriptPath -Repository $LocalRepoName
$foundScriptInfo = Find-PSResource $TestScript -Repository $LocalRepoName
$foundScriptInfo | Should -Not -BeNullOrEmpty
$foundScriptInfo.Count | Should -Be 1
$foundScriptInfo.Name | Should -Be $TestScript
}
AfterEach {
Get-ChildItem $PublishedNupkgs | Remove-Item -Recurse -Force
Get-ChildItem $LocalRepoUri | Remove-Item -Recurse -Force
}
AfterAll {
Remove-InstalledScripts
}
@@ -294,5 +393,15 @@ Describe "PSResourceGet - ACR tests" -tags "Feature" {
}
Remove-InstalledModules
FinalCleanUp
}
}
function FinalCleanUp
{
if(Test-Path $TempDir)
{
Remove-Item -Path $TempDir -Recurse -Force
}
}