From 00aacfca4b6f0aeedcc94740e09461238bf7dcb6 Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Thu, 1 Feb 2024 17:11:01 -0800 Subject: [PATCH 01/22] Enable testing against ACR --- .ci/test.yml | 27 ++++++++++++++++++- .../FindPSResourceACRServer.Tests.ps1 | 10 +++---- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/.ci/test.yml b/.ci/test.yml index 541d72542..d22673e80 100644 --- a/.ci/test.yml +++ b/.ci/test.yml @@ -11,6 +11,14 @@ jobs: vmImage: ${{ parameters.imageName }} displayName: ${{ parameters.displayName }} steps: + - ${{ parameters.powershellExecutable }}: | + Install-Module -Name 'Microsoft.PowerShell.SecretManagement' -force -SkipPublisherCheck -AllowClobber + Install-Module -Name 'Microsoft.PowerShell.SecretStore' -force -SkipPublisherCheck -AllowClobber + $vaultPassword = ConvertTo-SecureString $("a!!"+ (Get-Random -Maximum ([int]::MaxValue))) -AsPlainText -Force + Set-SecretStoreConfiguration -Authentication None -Interaction None -Confirm:$false -Password $vaultPassword + Register-SecretVault -Name SecretStore -ModuleName Microsoft.PowerShell.SecretStore -DefaultVault + displayName: Install Secret store + - task: DownloadBuildArtifacts@0 displayName: 'Download artifacts' inputs: @@ -53,6 +61,24 @@ jobs: displayName: Install module for test from downloaded artifact workingDirectory: ${{ parameters.buildDirectory }} + - task: AzurePowerShell@5 + inputs: + azureSubscription: PSResourceGetACR + azurePowerShellVersion: LatestVersion + ScriptType: InlineScript + pwsh: true + inline: | + Write-Verbose -Verbose "Getting Azure Container Registry" + Get-AzContainerRegistry -ResourceGroupName 'PSResourceGet' -Name 'psresourcegettest' | Select-Object -Property * + Write-Verbose -Verbose "Setting up secret for Azure Container Registry" + $azt = Get-AzAccessToken + $tenantId = $azt.TenantID + Set-Secret -Name $tenantId -Secret $azt.Token -Verbose + $vstsCommandString = "vso[task.setvariable variable=TenantId]$tenantId" + Write-Host "sending " + $vstsCommandString + Write-Host "##$vstsCommandString" + displayName: 'Setup Azure Container Registry secret' + - ${{ parameters.powershellExecutable }}: | $modulePath = Join-Path -Path $env:AGENT_TEMPDIRECTORY -ChildPath 'TempModules' $env:PSModulePath = $modulePath + [System.IO.Path]::PathSeparator + $env:PSModulePath @@ -68,4 +94,3 @@ jobs: workingDirectory: ${{ parameters.buildDirectory }} errorActionPreference: continue condition: succeededOrFailed() - diff --git a/test/FindPSResourceTests/FindPSResourceACRServer.Tests.ps1 b/test/FindPSResourceTests/FindPSResourceACRServer.Tests.ps1 index ed7e4bfc8..1b9c36d7e 100644 --- a/test/FindPSResourceTests/FindPSResourceACRServer.Tests.ps1 +++ b/test/FindPSResourceTests/FindPSResourceACRServer.Tests.ps1 @@ -1,9 +1,6 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -<# -# These tests are working with manual validation but there is currently no automated testing for ACR repositories. - $modPath = "$psscriptroot/../PSGetTestUtils.psm1" Import-Module $modPath -Force -Verbose @@ -12,9 +9,10 @@ Describe 'Test HTTP Find-PSResource for ACR Server Protocol' -tags 'CI' { BeforeAll{ $testModuleName = "hello-world" $ACRRepoName = "ACRRepo" - $ACRRepoUri = "https://psgetregistry.azurecr.io" + $ACRRepoUri = "https://psresourcegettest.azurecr.io" Get-NewPSResourceRepositoryFile - Register-PSResourceRepository -Name $ACRRepoName -Uri $ACRepoUri -ApiVersion "ACR" + $psCredInfo = New-Object Microsoft.PowerShell.PSResourceGet.UtilClasses.PSCredentialInfo ("SecretStore", "$env:TENANTID") + Register-PSResourceRepository -Name $ACRRepoName -ApiVersion 'acr' -Uri $ACRRepoUri -CredentialInfo $psCredInfo -Verbose } AfterAll { @@ -138,5 +136,3 @@ Describe 'Test HTTP Find-PSResource for ACR Server Protocol' -tags 'CI' { $err[0].FullyQualifiedErrorId | Should -BeExactly "FindAllFailure,Microsoft.PowerShell.PSResourceGet.Cmdlets.FindPSResource" } } - -#> \ No newline at end of file From 9929dfd1c935d2d846c144a7e0a2c3958cd0c5fd Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Thu, 1 Feb 2024 17:17:18 -0800 Subject: [PATCH 02/22] Fix yaml --- .ci/test.yml | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/.ci/test.yml b/.ci/test.yml index d22673e80..13be97783 100644 --- a/.ci/test.yml +++ b/.ci/test.yml @@ -62,22 +62,22 @@ jobs: workingDirectory: ${{ parameters.buildDirectory }} - task: AzurePowerShell@5 - inputs: - azureSubscription: PSResourceGetACR - azurePowerShellVersion: LatestVersion - ScriptType: InlineScript - pwsh: true - inline: | - Write-Verbose -Verbose "Getting Azure Container Registry" - Get-AzContainerRegistry -ResourceGroupName 'PSResourceGet' -Name 'psresourcegettest' | Select-Object -Property * - Write-Verbose -Verbose "Setting up secret for Azure Container Registry" - $azt = Get-AzAccessToken - $tenantId = $azt.TenantID - Set-Secret -Name $tenantId -Secret $azt.Token -Verbose - $vstsCommandString = "vso[task.setvariable variable=TenantId]$tenantId" - Write-Host "sending " + $vstsCommandString - Write-Host "##$vstsCommandString" - displayName: 'Setup Azure Container Registry secret' + inputs: + azureSubscription: PSResourceGetACR + azurePowerShellVersion: LatestVersion + ScriptType: InlineScript + pwsh: true + inline: | + Write-Verbose -Verbose "Getting Azure Container Registry" + Get-AzContainerRegistry -ResourceGroupName 'PSResourceGet' -Name 'psresourcegettest' | Select-Object -Property * + Write-Verbose -Verbose "Setting up secret for Azure Container Registry" + $azt = Get-AzAccessToken + $tenantId = $azt.TenantID + Set-Secret -Name $tenantId -Secret $azt.Token -Verbose + $vstsCommandString = "vso[task.setvariable variable=TenantId]$tenantId" + Write-Host "sending " + $vstsCommandString + Write-Host "##$vstsCommandString" + displayName: 'Setup Azure Container Registry secret' - ${{ parameters.powershellExecutable }}: | $modulePath = Join-Path -Path $env:AGENT_TEMPDIRECTORY -ChildPath 'TempModules' From b490e24bc5d88da988a1acbf0dfc11b4fcfec8ee Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Fri, 9 Feb 2024 16:43:44 -0800 Subject: [PATCH 03/22] Add ACR install tests --- .../InstallPSResourceACRServer.Tests.ps1 | 267 ++++++++++++++++++ 1 file changed, 267 insertions(+) create mode 100644 test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1 diff --git a/test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1 b/test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1 new file mode 100644 index 000000000..ba8d13d7b --- /dev/null +++ b/test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1 @@ -0,0 +1,267 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +$ProgressPreference = "SilentlyContinue" +$modPath = "$psscriptroot/../PSGetTestUtils.psm1" +Import-Module $modPath -Force -Verbose + +Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' { + + BeforeAll { + $testModuleName = "test_local_mod" + $testModuleName2 = "test_local_mod2" + $testScriptName = "test_ado_script" + $ACRRepoName = "ACRRepo" + $ACRRepoUri = "https://psresourcegettest.azurecr.io" + Get-NewPSResourceRepositoryFile + $psCredInfo = New-Object Microsoft.PowerShell.PSResourceGet.UtilClasses.PSCredentialInfo ("SecretStore", "$env:TENANTID") + Register-PSResourceRepository -Name $ACRRepoName -ApiVersion 'acr' -Uri $ACRRepoUri -CredentialInfo $psCredInfo -Verbose + } + + AfterEach { + Uninstall-PSResource $testModuleName, $testModuleName2, $testScriptName -Version "*" -SkipDependencyCheck -ErrorAction SilentlyContinue + } + + AfterAll { + Get-RevertPSResourceRepositoryFile + } + + $testCases = @{Name="*"; ErrorId="NameContainsWildcard"}, + @{Name="Test_local_m*"; ErrorId="NameContainsWildcard"}, + @{Name="Test?local","Test[local"; ErrorId="ErrorFilteringNamesForUnsupportedWildcards"} + + It "Should not install resource with wildcard in name" -TestCases $testCases { + param($Name, $ErrorId) + Install-PSResource -Name $Name -Repository $ADORepoName -ErrorVariable err -ErrorAction SilentlyContinue + $err.Count | Should -BeGreaterThan 0 + $err[0].FullyQualifiedErrorId | Should -BeExactly "$ErrorId,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource" + $res = Get-InstalledPSResource $testModuleName + $res | Should -BeNullOrEmpty + } + + It "Install specific module resource by name" { + Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository + $pkg = Get-InstalledPSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.Version | Should -Be "5.0.0" + } + + <# currently failing + It "Install specific script resource by name" { + Install-PSResource -Name $testScriptName -Repository $ADORepoName -TrustRepository + $pkg = Get-InstalledPSResource $testScriptName + $pkg.Name | Should -Be $testScriptName + $pkg.Version | Should -Be "1.0.0" + } + #> + + It "Install multiple resources by name" { + $pkgNames = @($testModuleName, $testModuleName2) + Install-PSResource -Name $pkgNames -Repository $ADORepoName -TrustRepository + $pkg = Get-InstalledPSResource $pkgNames + $pkg.Name | Should -Be $pkgNames + } + + It "Should not install resource given nonexistant name" { + Install-PSResource -Name "NonExistantModule" -Repository $ADORepoName -TrustRepository -ErrorVariable err -ErrorAction SilentlyContinue + $pkg = Get-InstalledPSResource "NonExistantModule" + $pkg | Should -BeNullOrEmpty + $err.Count | Should -BeGreaterThan 0 + $err[0].FullyQualifiedErrorId | Should -BeExactly "InstallPackageFailure,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource" + } + + # Do some version testing, but Find-PSResource should be doing thorough testing + It "Should install resource given name and exact version" { + Install-PSResource -Name $testModuleName -Version "1.0.0" -Repository $ADORepoName -TrustRepository + $pkg = Get-InstalledPSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.Version | Should -Be "1.0.0" + } + + It "Should install resource given name and exact version with bracket syntax" { + Install-PSResource -Name $testModuleName -Version "[1.0.0]" -Repository $ADORepoName -TrustRepository + $pkg = Get-InstalledPSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.Version | Should -Be "1.0.0" + } + + It "Should install resource given name and exact range inclusive [1.0.0, 5.0.0]" { + Install-PSResource -Name $testModuleName -Version "[1.0.0, 5.0.0]" -Repository $ADORepoName -TrustRepository + $pkg = Get-InstalledPSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.Version | Should -Be "5.0.0" + } + + It "Should install resource given name and exact range exclusive (1.0.0, 5.0.0)" { + Install-PSResource -Name $testModuleName -Version "(1.0.0, 5.0.0)" -Repository $ADORepoName -TrustRepository + $pkg = Get-InstalledPSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.Version | Should -Be "3.0.0" + } + + # TODO: Update this test and others like it that use try/catch blocks instead of Should -Throw + It "Should not install resource with incorrectly formatted version such as exclusive version (1.0.0.0)" { + $Version = "(1.0.0.0)" + try { + Install-PSResource -Name $testModuleName -Version $Version -Repository $ADORepoName -TrustRepository -ErrorAction SilentlyContinue + } + catch + {} + $Error[0].FullyQualifiedErrorId | Should -be "IncorrectVersionFormat,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource" + + $res = Get-InstalledPSResource $testModuleName + $res | Should -BeNullOrEmpty + } + + It "Install resource when given Name, Version '*', should install the latest version" { + Install-PSResource -Name $testModuleName -Version "*" -Repository $ADORepoName -TrustRepository + $pkg = Get-InstalledPSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.Version | Should -Be "5.0.0" + } + + It "Install resource with latest (including prerelease) version given Prerelease parameter" { + Install-PSResource -Name $testModuleName -Prerelease -Repository $ADORepoName -TrustRepository + $pkg = Get-InstalledPSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.Version | Should -Be "5.2.5" + $pkg.Prerelease | Should -Be "alpha001" + } + + It "Install resource via InputObject by piping from Find-PSresource" { + Find-PSResource -Name $testModuleName -Repository $ADORepoName | Install-PSResource -TrustRepository + $pkg = Get-InstalledPSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.Version | Should -Be "5.0.0" + } + + It "Install resource with companyname and repository source location and validate properties" { + Install-PSResource -Name $testModuleName -Version "5.2.5-alpha001" -Repository $ADORepoName -TrustRepository + $pkg = Get-InstalledPSResource $testModuleName + $pkg.Version | Should -Be "5.2.5" + $pkg.Prerelease | Should -Be "alpha001" + + $pkg.CompanyName | Should -Be "None" + $pkg.RepositorySourceLocation | Should -Be $ADORepoUri + } + + # Windows only + It "Install resource under CurrentUser scope - Windows only" -Skip:(!(Get-IsWindows)) { + Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository -Scope CurrentUser + $pkg = Get-InstalledPSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.InstalledLocation.ToString().Contains("Documents") | Should -Be $true + } + + # Windows only + It "Install resource under AllUsers scope - Windows only" -Skip:(!((Get-IsWindows) -and (Test-IsAdmin))) { + Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository -Scope AllUsers -Verbose + $pkg = Get-InstalledPSResource $testModuleName -Scope AllUsers + $pkg.Name | Should -Be $testModuleName + $pkg.InstalledLocation.ToString().Contains("Program Files") | Should -Be $true + } + + # Windows only + It "Install resource under no specified scope - Windows only" -Skip:(!(Get-IsWindows)) { + Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository + $pkg = Get-InstalledPSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.InstalledLocation.ToString().Contains("Documents") | Should -Be $true + } + + # Unix only + # Expected path should be similar to: '/home/janelane/.local/share/powershell/Modules' + It "Install resource under CurrentUser scope - Unix only" -Skip:(Get-IsWindows) { + Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository -Scope CurrentUser + $pkg = Get-InstalledPSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.InstalledLocation.ToString().Contains("$env:HOME/.local") | Should -Be $true + } + + # Unix only + # Expected path should be similar to: '/home/janelane/.local/share/powershell/Modules' + It "Install resource under no specified scope - Unix only" -Skip:(Get-IsWindows) { + Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository + $pkg = Get-InstalledPSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.InstalledLocation.ToString().Contains("$env:HOME/.local") | Should -Be $true + } + + It "Should not install resource that is already installed" { + Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository + $pkg = Get-InstalledPSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository -WarningVariable WarningVar -warningaction SilentlyContinue + $WarningVar | Should -Not -BeNullOrEmpty + } + + It "Reinstall resource that is already installed with -Reinstall parameter" { + Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository + $pkg = Get-InstalledPSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.Version | Should -Be "5.0.0" + Install-PSResource -Name $testModuleName -Repository $ADORepoName -Reinstall -TrustRepository + $pkg = Get-InstalledPSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.Version | Should -Be "5.0.0" + } + + It "Install PSResourceInfo object piped in" { + Find-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $ADORepoName | Install-PSResource -TrustRepository + $res = Get-InstalledPSResource -Name $testModuleName + $res.Name | Should -Be $testModuleName + $res.Version | Should -Be "1.0.0" + } + + It "Install module using -PassThru" { + $res = Install-PSResource -Name $testModuleName -Repository $ADORepoName -PassThru -TrustRepository + $res.Name | Should -Contain $testModuleName + } +} + +Describe 'Test Install-PSResource for V3Server scenarios' -tags 'ManualValidationOnly' { + + BeforeAll { + $testModuleName = "TestModule" + $testModuleName2 = "testModuleWithlicense" + Get-NewPSResourceRepositoryFile + Register-LocalRepos + } + + AfterEach { + Uninstall-PSResource $testModuleName, $testModuleName2 -SkipDependencyCheck -ErrorAction SilentlyContinue + } + + AfterAll { + Get-RevertPSResourceRepositoryFile + } + + # Unix only manual test + # Expected path should be similar to: '/usr/local/share/powershell/Modules' + It "Install resource under AllUsers scope - Unix only" -Skip:(Get-IsWindows) { + Install-PSResource -Name $testModuleName -Repository $TestGalleryName -Scope AllUsers + $pkg = Get-Module $testModuleName -ListAvailable + $pkg.Name | Should -Be $testModuleName + $pkg.Path.Contains("/usr/") | Should -Be $true + } + + # This needs to be manually tested due to prompt + It "Install resource that requires accept license without -AcceptLicense flag" { + Install-PSResource -Name $testModuleName2 -Repository $TestGalleryName + $pkg = Get-InstalledPSResource $testModuleName2 + $pkg.Name | Should -Be $testModuleName2 + $pkg.Version | Should -Be "0.0.1.0" + } + + # This needs to be manually tested due to prompt + It "Install resource should prompt 'trust repository' if repository is not trusted" { + Set-PSResourceRepository PoshTestGallery -Trusted:$false + + Install-PSResource -Name $testModuleName -Repository $TestGalleryName -confirm:$false + + $pkg = Get-Module $testModuleName -ListAvailable + $pkg.Name | Should -Be $testModuleName + + Set-PSResourceRepository PoshTestGallery -Trusted + } +} From 179d0967586357ddb56536c0f43bf89e5139b7f4 Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Sat, 10 Feb 2024 12:55:38 -0800 Subject: [PATCH 04/22] Update test/FindPSResourceTests/FindPSResourceACRServer.Tests.ps1 Co-authored-by: alerickson <25858831+alerickson@users.noreply.github.com> --- test/FindPSResourceTests/FindPSResourceACRServer.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/FindPSResourceTests/FindPSResourceACRServer.Tests.ps1 b/test/FindPSResourceTests/FindPSResourceACRServer.Tests.ps1 index 1b9c36d7e..624b56c1e 100644 --- a/test/FindPSResourceTests/FindPSResourceACRServer.Tests.ps1 +++ b/test/FindPSResourceTests/FindPSResourceACRServer.Tests.ps1 @@ -7,7 +7,7 @@ Import-Module $modPath -Force -Verbose Describe 'Test HTTP Find-PSResource for ACR Server Protocol' -tags 'CI' { BeforeAll{ - $testModuleName = "hello-world" + $testModuleName = "test_local_mod" $ACRRepoName = "ACRRepo" $ACRRepoUri = "https://psresourcegettest.azurecr.io" Get-NewPSResourceRepositoryFile From 2c81e023a8359ecad60f1f89d41edcff51e4c728 Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Thu, 1 Feb 2024 17:11:01 -0800 Subject: [PATCH 05/22] Enable testing against ACR --- .ci/test.yml | 27 ++++++++++++++++++- .../FindPSResourceACRServer.Tests.ps1 | 10 +++---- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/.ci/test.yml b/.ci/test.yml index 541d72542..d22673e80 100644 --- a/.ci/test.yml +++ b/.ci/test.yml @@ -11,6 +11,14 @@ jobs: vmImage: ${{ parameters.imageName }} displayName: ${{ parameters.displayName }} steps: + - ${{ parameters.powershellExecutable }}: | + Install-Module -Name 'Microsoft.PowerShell.SecretManagement' -force -SkipPublisherCheck -AllowClobber + Install-Module -Name 'Microsoft.PowerShell.SecretStore' -force -SkipPublisherCheck -AllowClobber + $vaultPassword = ConvertTo-SecureString $("a!!"+ (Get-Random -Maximum ([int]::MaxValue))) -AsPlainText -Force + Set-SecretStoreConfiguration -Authentication None -Interaction None -Confirm:$false -Password $vaultPassword + Register-SecretVault -Name SecretStore -ModuleName Microsoft.PowerShell.SecretStore -DefaultVault + displayName: Install Secret store + - task: DownloadBuildArtifacts@0 displayName: 'Download artifacts' inputs: @@ -53,6 +61,24 @@ jobs: displayName: Install module for test from downloaded artifact workingDirectory: ${{ parameters.buildDirectory }} + - task: AzurePowerShell@5 + inputs: + azureSubscription: PSResourceGetACR + azurePowerShellVersion: LatestVersion + ScriptType: InlineScript + pwsh: true + inline: | + Write-Verbose -Verbose "Getting Azure Container Registry" + Get-AzContainerRegistry -ResourceGroupName 'PSResourceGet' -Name 'psresourcegettest' | Select-Object -Property * + Write-Verbose -Verbose "Setting up secret for Azure Container Registry" + $azt = Get-AzAccessToken + $tenantId = $azt.TenantID + Set-Secret -Name $tenantId -Secret $azt.Token -Verbose + $vstsCommandString = "vso[task.setvariable variable=TenantId]$tenantId" + Write-Host "sending " + $vstsCommandString + Write-Host "##$vstsCommandString" + displayName: 'Setup Azure Container Registry secret' + - ${{ parameters.powershellExecutable }}: | $modulePath = Join-Path -Path $env:AGENT_TEMPDIRECTORY -ChildPath 'TempModules' $env:PSModulePath = $modulePath + [System.IO.Path]::PathSeparator + $env:PSModulePath @@ -68,4 +94,3 @@ jobs: workingDirectory: ${{ parameters.buildDirectory }} errorActionPreference: continue condition: succeededOrFailed() - diff --git a/test/FindPSResourceTests/FindPSResourceACRServer.Tests.ps1 b/test/FindPSResourceTests/FindPSResourceACRServer.Tests.ps1 index ed7e4bfc8..1b9c36d7e 100644 --- a/test/FindPSResourceTests/FindPSResourceACRServer.Tests.ps1 +++ b/test/FindPSResourceTests/FindPSResourceACRServer.Tests.ps1 @@ -1,9 +1,6 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -<# -# These tests are working with manual validation but there is currently no automated testing for ACR repositories. - $modPath = "$psscriptroot/../PSGetTestUtils.psm1" Import-Module $modPath -Force -Verbose @@ -12,9 +9,10 @@ Describe 'Test HTTP Find-PSResource for ACR Server Protocol' -tags 'CI' { BeforeAll{ $testModuleName = "hello-world" $ACRRepoName = "ACRRepo" - $ACRRepoUri = "https://psgetregistry.azurecr.io" + $ACRRepoUri = "https://psresourcegettest.azurecr.io" Get-NewPSResourceRepositoryFile - Register-PSResourceRepository -Name $ACRRepoName -Uri $ACRepoUri -ApiVersion "ACR" + $psCredInfo = New-Object Microsoft.PowerShell.PSResourceGet.UtilClasses.PSCredentialInfo ("SecretStore", "$env:TENANTID") + Register-PSResourceRepository -Name $ACRRepoName -ApiVersion 'acr' -Uri $ACRRepoUri -CredentialInfo $psCredInfo -Verbose } AfterAll { @@ -138,5 +136,3 @@ Describe 'Test HTTP Find-PSResource for ACR Server Protocol' -tags 'CI' { $err[0].FullyQualifiedErrorId | Should -BeExactly "FindAllFailure,Microsoft.PowerShell.PSResourceGet.Cmdlets.FindPSResource" } } - -#> \ No newline at end of file From f0a3f1c7f43121a39914f4b7c72f5af4e110280c Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Thu, 1 Feb 2024 17:17:18 -0800 Subject: [PATCH 06/22] Fix yaml --- .ci/test.yml | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/.ci/test.yml b/.ci/test.yml index d22673e80..13be97783 100644 --- a/.ci/test.yml +++ b/.ci/test.yml @@ -62,22 +62,22 @@ jobs: workingDirectory: ${{ parameters.buildDirectory }} - task: AzurePowerShell@5 - inputs: - azureSubscription: PSResourceGetACR - azurePowerShellVersion: LatestVersion - ScriptType: InlineScript - pwsh: true - inline: | - Write-Verbose -Verbose "Getting Azure Container Registry" - Get-AzContainerRegistry -ResourceGroupName 'PSResourceGet' -Name 'psresourcegettest' | Select-Object -Property * - Write-Verbose -Verbose "Setting up secret for Azure Container Registry" - $azt = Get-AzAccessToken - $tenantId = $azt.TenantID - Set-Secret -Name $tenantId -Secret $azt.Token -Verbose - $vstsCommandString = "vso[task.setvariable variable=TenantId]$tenantId" - Write-Host "sending " + $vstsCommandString - Write-Host "##$vstsCommandString" - displayName: 'Setup Azure Container Registry secret' + inputs: + azureSubscription: PSResourceGetACR + azurePowerShellVersion: LatestVersion + ScriptType: InlineScript + pwsh: true + inline: | + Write-Verbose -Verbose "Getting Azure Container Registry" + Get-AzContainerRegistry -ResourceGroupName 'PSResourceGet' -Name 'psresourcegettest' | Select-Object -Property * + Write-Verbose -Verbose "Setting up secret for Azure Container Registry" + $azt = Get-AzAccessToken + $tenantId = $azt.TenantID + Set-Secret -Name $tenantId -Secret $azt.Token -Verbose + $vstsCommandString = "vso[task.setvariable variable=TenantId]$tenantId" + Write-Host "sending " + $vstsCommandString + Write-Host "##$vstsCommandString" + displayName: 'Setup Azure Container Registry secret' - ${{ parameters.powershellExecutable }}: | $modulePath = Join-Path -Path $env:AGENT_TEMPDIRECTORY -ChildPath 'TempModules' From 5e97ee433787ab11f8afec55ff790f7d53cefe2a Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Sat, 10 Feb 2024 12:55:38 -0800 Subject: [PATCH 07/22] Update test/FindPSResourceTests/FindPSResourceACRServer.Tests.ps1 Co-authored-by: alerickson <25858831+alerickson@users.noreply.github.com> --- test/FindPSResourceTests/FindPSResourceACRServer.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/FindPSResourceTests/FindPSResourceACRServer.Tests.ps1 b/test/FindPSResourceTests/FindPSResourceACRServer.Tests.ps1 index 1b9c36d7e..624b56c1e 100644 --- a/test/FindPSResourceTests/FindPSResourceACRServer.Tests.ps1 +++ b/test/FindPSResourceTests/FindPSResourceACRServer.Tests.ps1 @@ -7,7 +7,7 @@ Import-Module $modPath -Force -Verbose Describe 'Test HTTP Find-PSResource for ACR Server Protocol' -tags 'CI' { BeforeAll{ - $testModuleName = "hello-world" + $testModuleName = "test_local_mod" $ACRRepoName = "ACRRepo" $ACRRepoUri = "https://psresourcegettest.azurecr.io" Get-NewPSResourceRepositoryFile From cf7b3851070ef68c6193ea6c9f7cc88095747437 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Fri, 9 Feb 2024 16:43:44 -0800 Subject: [PATCH 08/22] Add ACR install tests --- .../InstallPSResourceACRServer.Tests.ps1 | 267 ++++++++++++++++++ 1 file changed, 267 insertions(+) create mode 100644 test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1 diff --git a/test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1 b/test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1 new file mode 100644 index 000000000..ba8d13d7b --- /dev/null +++ b/test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1 @@ -0,0 +1,267 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +$ProgressPreference = "SilentlyContinue" +$modPath = "$psscriptroot/../PSGetTestUtils.psm1" +Import-Module $modPath -Force -Verbose + +Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' { + + BeforeAll { + $testModuleName = "test_local_mod" + $testModuleName2 = "test_local_mod2" + $testScriptName = "test_ado_script" + $ACRRepoName = "ACRRepo" + $ACRRepoUri = "https://psresourcegettest.azurecr.io" + Get-NewPSResourceRepositoryFile + $psCredInfo = New-Object Microsoft.PowerShell.PSResourceGet.UtilClasses.PSCredentialInfo ("SecretStore", "$env:TENANTID") + Register-PSResourceRepository -Name $ACRRepoName -ApiVersion 'acr' -Uri $ACRRepoUri -CredentialInfo $psCredInfo -Verbose + } + + AfterEach { + Uninstall-PSResource $testModuleName, $testModuleName2, $testScriptName -Version "*" -SkipDependencyCheck -ErrorAction SilentlyContinue + } + + AfterAll { + Get-RevertPSResourceRepositoryFile + } + + $testCases = @{Name="*"; ErrorId="NameContainsWildcard"}, + @{Name="Test_local_m*"; ErrorId="NameContainsWildcard"}, + @{Name="Test?local","Test[local"; ErrorId="ErrorFilteringNamesForUnsupportedWildcards"} + + It "Should not install resource with wildcard in name" -TestCases $testCases { + param($Name, $ErrorId) + Install-PSResource -Name $Name -Repository $ADORepoName -ErrorVariable err -ErrorAction SilentlyContinue + $err.Count | Should -BeGreaterThan 0 + $err[0].FullyQualifiedErrorId | Should -BeExactly "$ErrorId,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource" + $res = Get-InstalledPSResource $testModuleName + $res | Should -BeNullOrEmpty + } + + It "Install specific module resource by name" { + Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository + $pkg = Get-InstalledPSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.Version | Should -Be "5.0.0" + } + + <# currently failing + It "Install specific script resource by name" { + Install-PSResource -Name $testScriptName -Repository $ADORepoName -TrustRepository + $pkg = Get-InstalledPSResource $testScriptName + $pkg.Name | Should -Be $testScriptName + $pkg.Version | Should -Be "1.0.0" + } + #> + + It "Install multiple resources by name" { + $pkgNames = @($testModuleName, $testModuleName2) + Install-PSResource -Name $pkgNames -Repository $ADORepoName -TrustRepository + $pkg = Get-InstalledPSResource $pkgNames + $pkg.Name | Should -Be $pkgNames + } + + It "Should not install resource given nonexistant name" { + Install-PSResource -Name "NonExistantModule" -Repository $ADORepoName -TrustRepository -ErrorVariable err -ErrorAction SilentlyContinue + $pkg = Get-InstalledPSResource "NonExistantModule" + $pkg | Should -BeNullOrEmpty + $err.Count | Should -BeGreaterThan 0 + $err[0].FullyQualifiedErrorId | Should -BeExactly "InstallPackageFailure,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource" + } + + # Do some version testing, but Find-PSResource should be doing thorough testing + It "Should install resource given name and exact version" { + Install-PSResource -Name $testModuleName -Version "1.0.0" -Repository $ADORepoName -TrustRepository + $pkg = Get-InstalledPSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.Version | Should -Be "1.0.0" + } + + It "Should install resource given name and exact version with bracket syntax" { + Install-PSResource -Name $testModuleName -Version "[1.0.0]" -Repository $ADORepoName -TrustRepository + $pkg = Get-InstalledPSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.Version | Should -Be "1.0.0" + } + + It "Should install resource given name and exact range inclusive [1.0.0, 5.0.0]" { + Install-PSResource -Name $testModuleName -Version "[1.0.0, 5.0.0]" -Repository $ADORepoName -TrustRepository + $pkg = Get-InstalledPSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.Version | Should -Be "5.0.0" + } + + It "Should install resource given name and exact range exclusive (1.0.0, 5.0.0)" { + Install-PSResource -Name $testModuleName -Version "(1.0.0, 5.0.0)" -Repository $ADORepoName -TrustRepository + $pkg = Get-InstalledPSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.Version | Should -Be "3.0.0" + } + + # TODO: Update this test and others like it that use try/catch blocks instead of Should -Throw + It "Should not install resource with incorrectly formatted version such as exclusive version (1.0.0.0)" { + $Version = "(1.0.0.0)" + try { + Install-PSResource -Name $testModuleName -Version $Version -Repository $ADORepoName -TrustRepository -ErrorAction SilentlyContinue + } + catch + {} + $Error[0].FullyQualifiedErrorId | Should -be "IncorrectVersionFormat,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource" + + $res = Get-InstalledPSResource $testModuleName + $res | Should -BeNullOrEmpty + } + + It "Install resource when given Name, Version '*', should install the latest version" { + Install-PSResource -Name $testModuleName -Version "*" -Repository $ADORepoName -TrustRepository + $pkg = Get-InstalledPSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.Version | Should -Be "5.0.0" + } + + It "Install resource with latest (including prerelease) version given Prerelease parameter" { + Install-PSResource -Name $testModuleName -Prerelease -Repository $ADORepoName -TrustRepository + $pkg = Get-InstalledPSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.Version | Should -Be "5.2.5" + $pkg.Prerelease | Should -Be "alpha001" + } + + It "Install resource via InputObject by piping from Find-PSresource" { + Find-PSResource -Name $testModuleName -Repository $ADORepoName | Install-PSResource -TrustRepository + $pkg = Get-InstalledPSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.Version | Should -Be "5.0.0" + } + + It "Install resource with companyname and repository source location and validate properties" { + Install-PSResource -Name $testModuleName -Version "5.2.5-alpha001" -Repository $ADORepoName -TrustRepository + $pkg = Get-InstalledPSResource $testModuleName + $pkg.Version | Should -Be "5.2.5" + $pkg.Prerelease | Should -Be "alpha001" + + $pkg.CompanyName | Should -Be "None" + $pkg.RepositorySourceLocation | Should -Be $ADORepoUri + } + + # Windows only + It "Install resource under CurrentUser scope - Windows only" -Skip:(!(Get-IsWindows)) { + Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository -Scope CurrentUser + $pkg = Get-InstalledPSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.InstalledLocation.ToString().Contains("Documents") | Should -Be $true + } + + # Windows only + It "Install resource under AllUsers scope - Windows only" -Skip:(!((Get-IsWindows) -and (Test-IsAdmin))) { + Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository -Scope AllUsers -Verbose + $pkg = Get-InstalledPSResource $testModuleName -Scope AllUsers + $pkg.Name | Should -Be $testModuleName + $pkg.InstalledLocation.ToString().Contains("Program Files") | Should -Be $true + } + + # Windows only + It "Install resource under no specified scope - Windows only" -Skip:(!(Get-IsWindows)) { + Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository + $pkg = Get-InstalledPSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.InstalledLocation.ToString().Contains("Documents") | Should -Be $true + } + + # Unix only + # Expected path should be similar to: '/home/janelane/.local/share/powershell/Modules' + It "Install resource under CurrentUser scope - Unix only" -Skip:(Get-IsWindows) { + Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository -Scope CurrentUser + $pkg = Get-InstalledPSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.InstalledLocation.ToString().Contains("$env:HOME/.local") | Should -Be $true + } + + # Unix only + # Expected path should be similar to: '/home/janelane/.local/share/powershell/Modules' + It "Install resource under no specified scope - Unix only" -Skip:(Get-IsWindows) { + Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository + $pkg = Get-InstalledPSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.InstalledLocation.ToString().Contains("$env:HOME/.local") | Should -Be $true + } + + It "Should not install resource that is already installed" { + Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository + $pkg = Get-InstalledPSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository -WarningVariable WarningVar -warningaction SilentlyContinue + $WarningVar | Should -Not -BeNullOrEmpty + } + + It "Reinstall resource that is already installed with -Reinstall parameter" { + Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository + $pkg = Get-InstalledPSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.Version | Should -Be "5.0.0" + Install-PSResource -Name $testModuleName -Repository $ADORepoName -Reinstall -TrustRepository + $pkg = Get-InstalledPSResource $testModuleName + $pkg.Name | Should -Be $testModuleName + $pkg.Version | Should -Be "5.0.0" + } + + It "Install PSResourceInfo object piped in" { + Find-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $ADORepoName | Install-PSResource -TrustRepository + $res = Get-InstalledPSResource -Name $testModuleName + $res.Name | Should -Be $testModuleName + $res.Version | Should -Be "1.0.0" + } + + It "Install module using -PassThru" { + $res = Install-PSResource -Name $testModuleName -Repository $ADORepoName -PassThru -TrustRepository + $res.Name | Should -Contain $testModuleName + } +} + +Describe 'Test Install-PSResource for V3Server scenarios' -tags 'ManualValidationOnly' { + + BeforeAll { + $testModuleName = "TestModule" + $testModuleName2 = "testModuleWithlicense" + Get-NewPSResourceRepositoryFile + Register-LocalRepos + } + + AfterEach { + Uninstall-PSResource $testModuleName, $testModuleName2 -SkipDependencyCheck -ErrorAction SilentlyContinue + } + + AfterAll { + Get-RevertPSResourceRepositoryFile + } + + # Unix only manual test + # Expected path should be similar to: '/usr/local/share/powershell/Modules' + It "Install resource under AllUsers scope - Unix only" -Skip:(Get-IsWindows) { + Install-PSResource -Name $testModuleName -Repository $TestGalleryName -Scope AllUsers + $pkg = Get-Module $testModuleName -ListAvailable + $pkg.Name | Should -Be $testModuleName + $pkg.Path.Contains("/usr/") | Should -Be $true + } + + # This needs to be manually tested due to prompt + It "Install resource that requires accept license without -AcceptLicense flag" { + Install-PSResource -Name $testModuleName2 -Repository $TestGalleryName + $pkg = Get-InstalledPSResource $testModuleName2 + $pkg.Name | Should -Be $testModuleName2 + $pkg.Version | Should -Be "0.0.1.0" + } + + # This needs to be manually tested due to prompt + It "Install resource should prompt 'trust repository' if repository is not trusted" { + Set-PSResourceRepository PoshTestGallery -Trusted:$false + + Install-PSResource -Name $testModuleName -Repository $TestGalleryName -confirm:$false + + $pkg = Get-Module $testModuleName -ListAvailable + $pkg.Name | Should -Be $testModuleName + + Set-PSResourceRepository PoshTestGallery -Trusted + } +} From 0fad988be4df6bbe5c19cf92a584bcffa12464a1 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Tue, 13 Feb 2024 20:42:02 -0800 Subject: [PATCH 09/22] Update Install tests --- .../InstallPSResourceACRServer.Tests.ps1 | 52 +++++++++---------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1 b/test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1 index ba8d13d7b..24f2b9f1b 100644 --- a/test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1 +++ b/test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1 @@ -32,7 +32,7 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' { It "Should not install resource with wildcard in name" -TestCases $testCases { param($Name, $ErrorId) - Install-PSResource -Name $Name -Repository $ADORepoName -ErrorVariable err -ErrorAction SilentlyContinue + Install-PSResource -Name $Name -Repository $ACRRepoName -ErrorVariable err -ErrorAction SilentlyContinue $err.Count | Should -BeGreaterThan 0 $err[0].FullyQualifiedErrorId | Should -BeExactly "$ErrorId,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource" $res = Get-InstalledPSResource $testModuleName @@ -40,30 +40,28 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' { } It "Install specific module resource by name" { - Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository + Install-PSResource -Name $testModuleName -Repository $ACRRepoName -TrustRepository $pkg = Get-InstalledPSResource $testModuleName $pkg.Name | Should -Be $testModuleName $pkg.Version | Should -Be "5.0.0" } - <# currently failing It "Install specific script resource by name" { - Install-PSResource -Name $testScriptName -Repository $ADORepoName -TrustRepository + Install-PSResource -Name $testScriptName -Repository $ACRRepoName -TrustRepository $pkg = Get-InstalledPSResource $testScriptName $pkg.Name | Should -Be $testScriptName $pkg.Version | Should -Be "1.0.0" } - #> It "Install multiple resources by name" { $pkgNames = @($testModuleName, $testModuleName2) - Install-PSResource -Name $pkgNames -Repository $ADORepoName -TrustRepository + Install-PSResource -Name $pkgNames -Repository $ACRRepoName -TrustRepository $pkg = Get-InstalledPSResource $pkgNames $pkg.Name | Should -Be $pkgNames } It "Should not install resource given nonexistant name" { - Install-PSResource -Name "NonExistantModule" -Repository $ADORepoName -TrustRepository -ErrorVariable err -ErrorAction SilentlyContinue + Install-PSResource -Name "NonExistantModule" -Repository $ACRRepoName -TrustRepository -ErrorVariable err -ErrorAction SilentlyContinue $pkg = Get-InstalledPSResource "NonExistantModule" $pkg | Should -BeNullOrEmpty $err.Count | Should -BeGreaterThan 0 @@ -72,28 +70,28 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' { # Do some version testing, but Find-PSResource should be doing thorough testing It "Should install resource given name and exact version" { - Install-PSResource -Name $testModuleName -Version "1.0.0" -Repository $ADORepoName -TrustRepository + Install-PSResource -Name $testModuleName -Version "1.0.0" -Repository $ACRRepoName -TrustRepository $pkg = Get-InstalledPSResource $testModuleName $pkg.Name | Should -Be $testModuleName $pkg.Version | Should -Be "1.0.0" } It "Should install resource given name and exact version with bracket syntax" { - Install-PSResource -Name $testModuleName -Version "[1.0.0]" -Repository $ADORepoName -TrustRepository + Install-PSResource -Name $testModuleName -Version "[1.0.0]" -Repository $ACRRepoName -TrustRepository $pkg = Get-InstalledPSResource $testModuleName $pkg.Name | Should -Be $testModuleName $pkg.Version | Should -Be "1.0.0" } It "Should install resource given name and exact range inclusive [1.0.0, 5.0.0]" { - Install-PSResource -Name $testModuleName -Version "[1.0.0, 5.0.0]" -Repository $ADORepoName -TrustRepository + Install-PSResource -Name $testModuleName -Version "[1.0.0, 5.0.0]" -Repository $ACRRepoName -TrustRepository $pkg = Get-InstalledPSResource $testModuleName $pkg.Name | Should -Be $testModuleName $pkg.Version | Should -Be "5.0.0" } It "Should install resource given name and exact range exclusive (1.0.0, 5.0.0)" { - Install-PSResource -Name $testModuleName -Version "(1.0.0, 5.0.0)" -Repository $ADORepoName -TrustRepository + Install-PSResource -Name $testModuleName -Version "(1.0.0, 5.0.0)" -Repository $ACRRepoName -TrustRepository $pkg = Get-InstalledPSResource $testModuleName $pkg.Name | Should -Be $testModuleName $pkg.Version | Should -Be "3.0.0" @@ -103,7 +101,7 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' { It "Should not install resource with incorrectly formatted version such as exclusive version (1.0.0.0)" { $Version = "(1.0.0.0)" try { - Install-PSResource -Name $testModuleName -Version $Version -Repository $ADORepoName -TrustRepository -ErrorAction SilentlyContinue + Install-PSResource -Name $testModuleName -Version $Version -Repository $ACRRepoName -TrustRepository -ErrorAction SilentlyContinue } catch {} @@ -114,14 +112,14 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' { } It "Install resource when given Name, Version '*', should install the latest version" { - Install-PSResource -Name $testModuleName -Version "*" -Repository $ADORepoName -TrustRepository + Install-PSResource -Name $testModuleName -Version "*" -Repository $ACRRepoName -TrustRepository $pkg = Get-InstalledPSResource $testModuleName $pkg.Name | Should -Be $testModuleName $pkg.Version | Should -Be "5.0.0" } It "Install resource with latest (including prerelease) version given Prerelease parameter" { - Install-PSResource -Name $testModuleName -Prerelease -Repository $ADORepoName -TrustRepository + Install-PSResource -Name $testModuleName -Prerelease -Repository $ACRRepoName -TrustRepository $pkg = Get-InstalledPSResource $testModuleName $pkg.Name | Should -Be $testModuleName $pkg.Version | Should -Be "5.2.5" @@ -129,14 +127,14 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' { } It "Install resource via InputObject by piping from Find-PSresource" { - Find-PSResource -Name $testModuleName -Repository $ADORepoName | Install-PSResource -TrustRepository + Find-PSResource -Name $testModuleName -Repository $ACRRepoName | Install-PSResource -TrustRepository $pkg = Get-InstalledPSResource $testModuleName $pkg.Name | Should -Be $testModuleName $pkg.Version | Should -Be "5.0.0" } It "Install resource with companyname and repository source location and validate properties" { - Install-PSResource -Name $testModuleName -Version "5.2.5-alpha001" -Repository $ADORepoName -TrustRepository + Install-PSResource -Name $testModuleName -Version "5.2.5-alpha001" -Repository $ACRRepoName -TrustRepository $pkg = Get-InstalledPSResource $testModuleName $pkg.Version | Should -Be "5.2.5" $pkg.Prerelease | Should -Be "alpha001" @@ -147,7 +145,7 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' { # Windows only It "Install resource under CurrentUser scope - Windows only" -Skip:(!(Get-IsWindows)) { - Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository -Scope CurrentUser + Install-PSResource -Name $testModuleName -Repository $ACRRepoName -TrustRepository -Scope CurrentUser $pkg = Get-InstalledPSResource $testModuleName $pkg.Name | Should -Be $testModuleName $pkg.InstalledLocation.ToString().Contains("Documents") | Should -Be $true @@ -155,7 +153,7 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' { # Windows only It "Install resource under AllUsers scope - Windows only" -Skip:(!((Get-IsWindows) -and (Test-IsAdmin))) { - Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository -Scope AllUsers -Verbose + Install-PSResource -Name $testModuleName -Repository $ACRRepoName -TrustRepository -Scope AllUsers -Verbose $pkg = Get-InstalledPSResource $testModuleName -Scope AllUsers $pkg.Name | Should -Be $testModuleName $pkg.InstalledLocation.ToString().Contains("Program Files") | Should -Be $true @@ -163,7 +161,7 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' { # Windows only It "Install resource under no specified scope - Windows only" -Skip:(!(Get-IsWindows)) { - Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository + Install-PSResource -Name $testModuleName -Repository $ACRRepoName -TrustRepository $pkg = Get-InstalledPSResource $testModuleName $pkg.Name | Should -Be $testModuleName $pkg.InstalledLocation.ToString().Contains("Documents") | Should -Be $true @@ -172,7 +170,7 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' { # Unix only # Expected path should be similar to: '/home/janelane/.local/share/powershell/Modules' It "Install resource under CurrentUser scope - Unix only" -Skip:(Get-IsWindows) { - Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository -Scope CurrentUser + Install-PSResource -Name $testModuleName -Repository $ACRRepoName -TrustRepository -Scope CurrentUser $pkg = Get-InstalledPSResource $testModuleName $pkg.Name | Should -Be $testModuleName $pkg.InstalledLocation.ToString().Contains("$env:HOME/.local") | Should -Be $true @@ -181,40 +179,40 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' { # Unix only # Expected path should be similar to: '/home/janelane/.local/share/powershell/Modules' It "Install resource under no specified scope - Unix only" -Skip:(Get-IsWindows) { - Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository + Install-PSResource -Name $testModuleName -Repository $ACRRepoName -TrustRepository $pkg = Get-InstalledPSResource $testModuleName $pkg.Name | Should -Be $testModuleName $pkg.InstalledLocation.ToString().Contains("$env:HOME/.local") | Should -Be $true } It "Should not install resource that is already installed" { - Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository + Install-PSResource -Name $testModuleName -Repository $ACRRepoName -TrustRepository $pkg = Get-InstalledPSResource $testModuleName $pkg.Name | Should -Be $testModuleName - Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository -WarningVariable WarningVar -warningaction SilentlyContinue + Install-PSResource -Name $testModuleName -Repository $ACRRepoName -TrustRepository -WarningVariable WarningVar -warningaction SilentlyContinue $WarningVar | Should -Not -BeNullOrEmpty } It "Reinstall resource that is already installed with -Reinstall parameter" { - Install-PSResource -Name $testModuleName -Repository $ADORepoName -TrustRepository + Install-PSResource -Name $testModuleName -Repository $ACRRepoName -TrustRepository $pkg = Get-InstalledPSResource $testModuleName $pkg.Name | Should -Be $testModuleName $pkg.Version | Should -Be "5.0.0" - Install-PSResource -Name $testModuleName -Repository $ADORepoName -Reinstall -TrustRepository + Install-PSResource -Name $testModuleName -Repository $ACRRepoName -Reinstall -TrustRepository $pkg = Get-InstalledPSResource $testModuleName $pkg.Name | Should -Be $testModuleName $pkg.Version | Should -Be "5.0.0" } It "Install PSResourceInfo object piped in" { - Find-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $ADORepoName | Install-PSResource -TrustRepository + Find-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $ACRRepoName | Install-PSResource -TrustRepository $res = Get-InstalledPSResource -Name $testModuleName $res.Name | Should -Be $testModuleName $res.Version | Should -Be "1.0.0" } It "Install module using -PassThru" { - $res = Install-PSResource -Name $testModuleName -Repository $ADORepoName -PassThru -TrustRepository + $res = Install-PSResource -Name $testModuleName -Repository $ACRRepoName -PassThru -TrustRepository $res.Name | Should -Contain $testModuleName } } From 323e2cdaea59d3cf9126bfc265ff5ee29fe2404f Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Tue, 13 Feb 2024 21:01:52 -0800 Subject: [PATCH 10/22] Update tests --- .../InstallPSResourceACRServer.Tests.ps1 | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1 b/test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1 index 24f2b9f1b..7328ce20c 100644 --- a/test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1 +++ b/test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1 @@ -46,13 +46,15 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' { $pkg.Version | Should -Be "5.0.0" } + <# TODO: enable after implementing script functionality It "Install specific script resource by name" { Install-PSResource -Name $testScriptName -Repository $ACRRepoName -TrustRepository $pkg = Get-InstalledPSResource $testScriptName $pkg.Name | Should -Be $testScriptName $pkg.Version | Should -Be "1.0.0" } - + #> + It "Install multiple resources by name" { $pkgNames = @($testModuleName, $testModuleName2) Install-PSResource -Name $pkgNames -Repository $ACRRepoName -TrustRepository @@ -65,7 +67,7 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' { $pkg = Get-InstalledPSResource "NonExistantModule" $pkg | Should -BeNullOrEmpty $err.Count | Should -BeGreaterThan 0 - $err[0].FullyQualifiedErrorId | Should -BeExactly "InstallPackageFailure,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource" + $err[0].FullyQualifiedErrorId | Should -BeExactly "ResourceNotFound,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource" } # Do some version testing, but Find-PSResource should be doing thorough testing @@ -118,6 +120,7 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' { $pkg.Version | Should -Be "5.0.0" } + <# TODO: enable when prerelease functionality is implemented It "Install resource with latest (including prerelease) version given Prerelease parameter" { Install-PSResource -Name $testModuleName -Prerelease -Repository $ACRRepoName -TrustRepository $pkg = Get-InstalledPSResource $testModuleName @@ -125,6 +128,7 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' { $pkg.Version | Should -Be "5.2.5" $pkg.Prerelease | Should -Be "alpha001" } + #> It "Install resource via InputObject by piping from Find-PSresource" { Find-PSResource -Name $testModuleName -Repository $ACRRepoName | Install-PSResource -TrustRepository @@ -134,10 +138,9 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' { } It "Install resource with companyname and repository source location and validate properties" { - Install-PSResource -Name $testModuleName -Version "5.2.5-alpha001" -Repository $ACRRepoName -TrustRepository + Install-PSResource -Name $testModuleName -Version "5.0.0" -Repository $ACRRepoName -TrustRepository $pkg = Get-InstalledPSResource $testModuleName - $pkg.Version | Should -Be "5.2.5" - $pkg.Prerelease | Should -Be "alpha001" + $pkg.Version | Should -Be "5.0.0" $pkg.CompanyName | Should -Be "None" $pkg.RepositorySourceLocation | Should -Be $ADORepoUri From d841b253e5e58ba697e18b2e60201f45a400109d Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Tue, 13 Feb 2024 21:41:27 -0800 Subject: [PATCH 11/22] Update test --- .../InstallPSResourceACRServer.Tests.ps1 | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1 b/test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1 index 7328ce20c..c8de0750a 100644 --- a/test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1 +++ b/test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1 @@ -137,12 +137,14 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' { $pkg.Version | Should -Be "5.0.0" } - It "Install resource with companyname and repository source location and validate properties" { - Install-PSResource -Name $testModuleName -Version "5.0.0" -Repository $ACRRepoName -TrustRepository - $pkg = Get-InstalledPSResource $testModuleName - $pkg.Version | Should -Be "5.0.0" - - $pkg.CompanyName | Should -Be "None" + It "Install resource with copyright, description and repository source location and validate properties" { + $testModule = "test_module" + Install-PSResource -Name $testModule -Version "7.0.0" -Repository $ACRRepoName -TrustRepository + $pkg = Get-InstalledPSResource $testModule + $pkg.Name | Should -Be $testModule + $pkg.Version | Should -Be "7.0.0" + $pkg.Copyright | Should -Be "(c) Anam Navied. All rights reserved." + $pkg.Description | Should -Be "This is a test module, for PSGallery team internal testing. Do not take a dependency on this package. This version contains tags for the package." $pkg.RepositorySourceLocation | Should -Be $ADORepoUri } From 7e3831284c82f663ce37206d5243147881f387ac Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Tue, 13 Feb 2024 21:53:27 -0800 Subject: [PATCH 12/22] Update test --- .../InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1 b/test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1 index c8de0750a..0d0952588 100644 --- a/test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1 +++ b/test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1 @@ -145,7 +145,7 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' { $pkg.Version | Should -Be "7.0.0" $pkg.Copyright | Should -Be "(c) Anam Navied. All rights reserved." $pkg.Description | Should -Be "This is a test module, for PSGallery team internal testing. Do not take a dependency on this package. This version contains tags for the package." - $pkg.RepositorySourceLocation | Should -Be $ADORepoUri + $pkg.RepositorySourceLocation | Should -Be $ACRRepoUri } # Windows only From e1ad8352634fa0e7c3df09175fef0420715f58a3 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Tue, 13 Feb 2024 22:35:08 -0800 Subject: [PATCH 13/22] Add / to repo uri --- .../InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1 b/test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1 index 0d0952588..655d06ce6 100644 --- a/test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1 +++ b/test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1 @@ -12,7 +12,7 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' { $testModuleName2 = "test_local_mod2" $testScriptName = "test_ado_script" $ACRRepoName = "ACRRepo" - $ACRRepoUri = "https://psresourcegettest.azurecr.io" + $ACRRepoUri = "https://psresourcegettest.azurecr.io/" Get-NewPSResourceRepositoryFile $psCredInfo = New-Object Microsoft.PowerShell.PSResourceGet.UtilClasses.PSCredentialInfo ("SecretStore", "$env:TENANTID") Register-PSResourceRepository -Name $ACRRepoName -ApiVersion 'acr' -Uri $ACRRepoUri -CredentialInfo $psCredInfo -Verbose From b7f8f476f29cf5ea65b834eb81d73eeca126450e Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Tue, 13 Feb 2024 22:50:22 -0800 Subject: [PATCH 14/22] Add debugging --- .../InstallPSResourceGithubPackages.Tests.ps1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/InstallPSResourceTests/InstallPSResourceGithubPackages.Tests.ps1 b/test/InstallPSResourceTests/InstallPSResourceGithubPackages.Tests.ps1 index c8ed9cd96..44a3ff6e1 100644 --- a/test/InstallPSResourceTests/InstallPSResourceGithubPackages.Tests.ps1 +++ b/test/InstallPSResourceTests/InstallPSResourceGithubPackages.Tests.ps1 @@ -5,7 +5,7 @@ $ProgressPreference = "SilentlyContinue" $modPath = "$psscriptroot/../PSGetTestUtils.psm1" Import-Module $modPath -Force -Verbose -Describe 'Test Install-PSResource for V3Server scenarios' -tags 'CI' { +Describe 'Test Install-PSResource for GitHub packages' -tags 'CI' { BeforeAll { $testModuleName = "test_module" @@ -38,6 +38,9 @@ Describe 'Test Install-PSResource for V3Server scenarios' -tags 'CI' { $err.Count | Should -BeGreaterThan 0 $err[0].FullyQualifiedErrorId | Should -BeExactly "$ErrorId,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource" $res = Get-InstalledPSResource $testModuleName + Write-Output ($res.Name) + $res.Count | Should -Be 1 + $res.Name | Should -Be "Test_local_module" $res | Should -BeNullOrEmpty } From 5f46a60c4ee34b1af0f813f8d63f4466ca9221c0 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Tue, 13 Feb 2024 23:16:40 -0800 Subject: [PATCH 15/22] Add separate tests for install -Name '*' --- .../InstallPSResourceGithubPackages.Tests.ps1 | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/test/InstallPSResourceTests/InstallPSResourceGithubPackages.Tests.ps1 b/test/InstallPSResourceTests/InstallPSResourceGithubPackages.Tests.ps1 index 44a3ff6e1..5f4df50dc 100644 --- a/test/InstallPSResourceTests/InstallPSResourceGithubPackages.Tests.ps1 +++ b/test/InstallPSResourceTests/InstallPSResourceGithubPackages.Tests.ps1 @@ -28,8 +28,7 @@ Describe 'Test Install-PSResource for GitHub packages' -tags 'CI' { Get-RevertPSResourceRepositoryFile } - $testCases = @{Name="*"; ErrorId="NameContainsWildcard"}, - @{Name="Test_local_m*"; ErrorId="NameContainsWildcard"}, + $testCases = @{Name="Test_local_m*"; ErrorId="NameContainsWildcard"}, @{Name="Test?local","Test[local"; ErrorId="ErrorFilteringNamesForUnsupportedWildcards"} It "Should not install resource with wildcard in name" -TestCases $testCases { @@ -38,9 +37,16 @@ Describe 'Test Install-PSResource for GitHub packages' -tags 'CI' { $err.Count | Should -BeGreaterThan 0 $err[0].FullyQualifiedErrorId | Should -BeExactly "$ErrorId,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource" $res = Get-InstalledPSResource $testModuleName - Write-Output ($res.Name) + $res | Should -BeNullOrEmpty + } + + It "Should install resource with -Name '*'" { + Install-PSResource -Name "*" -Repository $GithubPackagesRepoName -Credential $credential -ErrorVariable err -ErrorAction SilentlyContinue + $err.Count | Should -BeGreaterThan 0 + $err[0].FullyQualifiedErrorId | Should -BeExactly "$ErrorId,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource" + $res = Get-InstalledPSResource $testModuleName $res.Count | Should -Be 1 - $res.Name | Should -Be "Test_local_module" + $res.Name | Should -Be "test_module" $res | Should -BeNullOrEmpty } From 429a864d6316e825500af595c570fe8a622fdfd7 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Tue, 13 Feb 2024 23:43:57 -0800 Subject: [PATCH 16/22] update github wildcard tests --- .../InstallPSResourceGithubPackages.Tests.ps1 | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/test/InstallPSResourceTests/InstallPSResourceGithubPackages.Tests.ps1 b/test/InstallPSResourceTests/InstallPSResourceGithubPackages.Tests.ps1 index 5f4df50dc..9b740d2e9 100644 --- a/test/InstallPSResourceTests/InstallPSResourceGithubPackages.Tests.ps1 +++ b/test/InstallPSResourceTests/InstallPSResourceGithubPackages.Tests.ps1 @@ -28,25 +28,29 @@ Describe 'Test Install-PSResource for GitHub packages' -tags 'CI' { Get-RevertPSResourceRepositoryFile } - $testCases = @{Name="Test_local_m*"; ErrorId="NameContainsWildcard"}, - @{Name="Test?local","Test[local"; ErrorId="ErrorFilteringNamesForUnsupportedWildcards"} + It "Should not install resource with wildcard in name" { + Install-PSResource -Name "Test?module" -Repository $GithubPackagesRepoName -Credential $credential -ErrorVariable err -ErrorAction SilentlyContinue + $err.Count | Should -BeGreaterThan 0 + $err[0].FullyQualifiedErrorId | Should -BeExactly "NameContainsWildcard,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource" + $res = Get-InstalledPSResource $testModuleName + $res | Should -BeNullOrEmpty + } - It "Should not install resource with wildcard in name" -TestCases $testCases { - param($Name, $ErrorId) - Install-PSResource -Name $Name -Repository $GithubPackagesRepoName -Credential $credential -ErrorVariable err -ErrorAction SilentlyContinue + It "Should install resource with wildcard at end of name" { + Install-PSResource -Name "Test_m*" -Repository $GithubPackagesRepoName -Credential $credential -ErrorVariable err -ErrorAction SilentlyContinue $err.Count | Should -BeGreaterThan 0 $err[0].FullyQualifiedErrorId | Should -BeExactly "$ErrorId,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource" $res = Get-InstalledPSResource $testModuleName + $res.Count | Should -Be 1 + $res.Name | Should -Be "test_module" $res | Should -BeNullOrEmpty } It "Should install resource with -Name '*'" { Install-PSResource -Name "*" -Repository $GithubPackagesRepoName -Credential $credential -ErrorVariable err -ErrorAction SilentlyContinue $err.Count | Should -BeGreaterThan 0 - $err[0].FullyQualifiedErrorId | Should -BeExactly "$ErrorId,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource" + $err[0].FullyQualifiedErrorId | Should -BeExactly "NameContainsWildcard,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource" $res = Get-InstalledPSResource $testModuleName - $res.Count | Should -Be 1 - $res.Name | Should -Be "test_module" $res | Should -BeNullOrEmpty } From 83c68917fc9406c21ff0538eae2d8ac62662a8ae Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Tue, 13 Feb 2024 23:57:15 -0800 Subject: [PATCH 17/22] update github tests --- .../InstallPSResourceGithubPackages.Tests.ps1 | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/InstallPSResourceTests/InstallPSResourceGithubPackages.Tests.ps1 b/test/InstallPSResourceTests/InstallPSResourceGithubPackages.Tests.ps1 index 9b740d2e9..8d4f763f4 100644 --- a/test/InstallPSResourceTests/InstallPSResourceGithubPackages.Tests.ps1 +++ b/test/InstallPSResourceTests/InstallPSResourceGithubPackages.Tests.ps1 @@ -39,10 +39,8 @@ Describe 'Test Install-PSResource for GitHub packages' -tags 'CI' { It "Should install resource with wildcard at end of name" { Install-PSResource -Name "Test_m*" -Repository $GithubPackagesRepoName -Credential $credential -ErrorVariable err -ErrorAction SilentlyContinue $err.Count | Should -BeGreaterThan 0 - $err[0].FullyQualifiedErrorId | Should -BeExactly "$ErrorId,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource" + $err[0].FullyQualifiedErrorId | Should -BeExactly "ErrorFilteringNamesForUnsupportedWildcards,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource" $res = Get-InstalledPSResource $testModuleName - $res.Count | Should -Be 1 - $res.Name | Should -Be "test_module" $res | Should -BeNullOrEmpty } From 3e54e61a5306d85ac0db885b2a7330ff0aa311d0 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Wed, 14 Feb 2024 00:00:58 -0800 Subject: [PATCH 18/22] update tests --- .../InstallPSResourceGithubPackages.Tests.ps1 | 24 ++++++------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/test/InstallPSResourceTests/InstallPSResourceGithubPackages.Tests.ps1 b/test/InstallPSResourceTests/InstallPSResourceGithubPackages.Tests.ps1 index 8d4f763f4..2a69a6fe4 100644 --- a/test/InstallPSResourceTests/InstallPSResourceGithubPackages.Tests.ps1 +++ b/test/InstallPSResourceTests/InstallPSResourceGithubPackages.Tests.ps1 @@ -28,29 +28,19 @@ Describe 'Test Install-PSResource for GitHub packages' -tags 'CI' { Get-RevertPSResourceRepositoryFile } - It "Should not install resource with wildcard in name" { - Install-PSResource -Name "Test?module" -Repository $GithubPackagesRepoName -Credential $credential -ErrorVariable err -ErrorAction SilentlyContinue - $err.Count | Should -BeGreaterThan 0 - $err[0].FullyQualifiedErrorId | Should -BeExactly "NameContainsWildcard,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource" - $res = Get-InstalledPSResource $testModuleName - $res | Should -BeNullOrEmpty - } + $testCases = @{Name="*"; ErrorId="NameContainsWildcard"}, + @{Name="Test_m*"; ErrorId="NameContainsWildcard"}, + @{Name="Test?module","Test[module"; ErrorId="ErrorFilteringNamesForUnsupportedWildcards"} - It "Should install resource with wildcard at end of name" { - Install-PSResource -Name "Test_m*" -Repository $GithubPackagesRepoName -Credential $credential -ErrorVariable err -ErrorAction SilentlyContinue + It "Should not install resource with wildcard in name" -TestCases $testCases { + param($Name, $ErrorId) + Install-PSResource -Name $Name -Repository $GithubPackagesRepoName -Credential $credential -ErrorVariable err -ErrorAction SilentlyContinue $err.Count | Should -BeGreaterThan 0 - $err[0].FullyQualifiedErrorId | Should -BeExactly "ErrorFilteringNamesForUnsupportedWildcards,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource" + $err[0].FullyQualifiedErrorId | Should -BeExactly "$ErrorId,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource" $res = Get-InstalledPSResource $testModuleName $res | Should -BeNullOrEmpty } - It "Should install resource with -Name '*'" { - Install-PSResource -Name "*" -Repository $GithubPackagesRepoName -Credential $credential -ErrorVariable err -ErrorAction SilentlyContinue - $err.Count | Should -BeGreaterThan 0 - $err[0].FullyQualifiedErrorId | Should -BeExactly "NameContainsWildcard,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource" - $res = Get-InstalledPSResource $testModuleName - $res | Should -BeNullOrEmpty - } It "Install specific module resource by name" { Install-PSResource -Name $testModuleName -Repository $GithubPackagesRepoName -Credential $credential -TrustRepository From a45cafc98cdf5ee2a3100fba3b8774f047a8d1ab Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Wed, 14 Feb 2024 00:01:15 -0800 Subject: [PATCH 19/22] Remove whitespace --- .../InstallPSResourceGithubPackages.Tests.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/test/InstallPSResourceTests/InstallPSResourceGithubPackages.Tests.ps1 b/test/InstallPSResourceTests/InstallPSResourceGithubPackages.Tests.ps1 index 2a69a6fe4..a45175290 100644 --- a/test/InstallPSResourceTests/InstallPSResourceGithubPackages.Tests.ps1 +++ b/test/InstallPSResourceTests/InstallPSResourceGithubPackages.Tests.ps1 @@ -41,7 +41,6 @@ Describe 'Test Install-PSResource for GitHub packages' -tags 'CI' { $res | Should -BeNullOrEmpty } - It "Install specific module resource by name" { Install-PSResource -Name $testModuleName -Repository $GithubPackagesRepoName -Credential $credential -TrustRepository $pkg = Get-InstalledPSResource $testModuleName From b3d4bd5cecf99d7a7978367b798c046566f740da Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Wed, 14 Feb 2024 00:54:56 -0800 Subject: [PATCH 20/22] uninstall all test resources before running tests --- .../InstallPSResourceGithubPackages.Tests.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/InstallPSResourceTests/InstallPSResourceGithubPackages.Tests.ps1 b/test/InstallPSResourceTests/InstallPSResourceGithubPackages.Tests.ps1 index a45175290..79b520ac2 100644 --- a/test/InstallPSResourceTests/InstallPSResourceGithubPackages.Tests.ps1 +++ b/test/InstallPSResourceTests/InstallPSResourceGithubPackages.Tests.ps1 @@ -8,6 +8,8 @@ Import-Module $modPath -Force -Verbose Describe 'Test Install-PSResource for GitHub packages' -tags 'CI' { BeforeAll { + Uninstall-PSResource $testModuleName, $testScriptName -Version "*" -SkipDependencyCheck -ErrorAction SilentlyContinue + $testModuleName = "test_module" $testModuleName2 = "test_module2" $testScriptName = "test_script" From d1bfd3c65fd78e30769ae140ecc43fab4791c78e Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Wed, 14 Feb 2024 09:43:26 -0800 Subject: [PATCH 21/22] Move uninstall to end of beforeall statement --- .../InstallPSResourceGithubPackages.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/InstallPSResourceTests/InstallPSResourceGithubPackages.Tests.ps1 b/test/InstallPSResourceTests/InstallPSResourceGithubPackages.Tests.ps1 index 79b520ac2..7c4e68d6a 100644 --- a/test/InstallPSResourceTests/InstallPSResourceGithubPackages.Tests.ps1 +++ b/test/InstallPSResourceTests/InstallPSResourceGithubPackages.Tests.ps1 @@ -8,8 +8,6 @@ Import-Module $modPath -Force -Verbose Describe 'Test Install-PSResource for GitHub packages' -tags 'CI' { BeforeAll { - Uninstall-PSResource $testModuleName, $testScriptName -Version "*" -SkipDependencyCheck -ErrorAction SilentlyContinue - $testModuleName = "test_module" $testModuleName2 = "test_module2" $testScriptName = "test_script" @@ -20,6 +18,8 @@ Describe 'Test Install-PSResource for GitHub packages' -tags 'CI' { $secureString = ConvertTo-SecureString $env:MAPPED_GITHUB_PAT -AsPlainText -Force $credential = New-Object pscredential ($env:GITHUB_USERNAME, $secureString) + + Uninstall-PSResource $testModuleName, $testScriptName -Version "*" -SkipDependencyCheck -ErrorAction SilentlyContinue } AfterEach { From 41e6549bbcd7ce4e876c6f4e7195db097510cb19 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Wed, 14 Feb 2024 10:30:54 -0800 Subject: [PATCH 22/22] Update test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1 Co-authored-by: Aditya Patwardhan --- .../InstallPSResourceACRServer.Tests.ps1 | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1 b/test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1 index 655d06ce6..9809d4388 100644 --- a/test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1 +++ b/test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1 @@ -102,12 +102,7 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' { # TODO: Update this test and others like it that use try/catch blocks instead of Should -Throw It "Should not install resource with incorrectly formatted version such as exclusive version (1.0.0.0)" { $Version = "(1.0.0.0)" - try { - Install-PSResource -Name $testModuleName -Version $Version -Repository $ACRRepoName -TrustRepository -ErrorAction SilentlyContinue - } - catch - {} - $Error[0].FullyQualifiedErrorId | Should -be "IncorrectVersionFormat,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource" + { Install-PSResource -Name $testModuleName -Version $Version -Repository $ACRRepoName -TrustRepository -ErrorAction SilentlyContinue } | Should -Throw -ErrorId "IncorrectVersionFormat,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource" $res = Get-InstalledPSResource $testModuleName $res | Should -BeNullOrEmpty