Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ACR Install tests #1560

Merged
merged 26 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
00aacfc
Enable testing against ACR
adityapatwardhan Feb 2, 2024
9929dfd
Fix yaml
adityapatwardhan Feb 2, 2024
b490e24
Add ACR install tests
alerickson Feb 10, 2024
179d096
Update test/FindPSResourceTests/FindPSResourceACRServer.Tests.ps1
adityapatwardhan Feb 10, 2024
de2179c
Merge branch 'master' of https://github.com/PowerShell/PSResourceGet …
alerickson Feb 13, 2024
2c81e02
Enable testing against ACR
adityapatwardhan Feb 2, 2024
f0a3f1c
Fix yaml
adityapatwardhan Feb 2, 2024
5e97ee4
Update test/FindPSResourceTests/FindPSResourceACRServer.Tests.ps1
adityapatwardhan Feb 10, 2024
cf7b385
Add ACR install tests
alerickson Feb 10, 2024
a1e36a8
Merge branch 'AddACRTests' of https://github.com/adityapatwardhan/PSR…
alerickson Feb 13, 2024
0aedf82
Merge branch 'addACRTests' of https://github.com/alerickson/PSResourc…
alerickson Feb 13, 2024
aa040c1
Merge branch 'master' of https://github.com/powershell/PSResourceGet …
alerickson Feb 14, 2024
0fad988
Update Install tests
alerickson Feb 14, 2024
323e2cd
Update tests
alerickson Feb 14, 2024
d841b25
Update test
alerickson Feb 14, 2024
7e38312
Update test
alerickson Feb 14, 2024
e1ad835
Add / to repo uri
alerickson Feb 14, 2024
b7f8f47
Add debugging
alerickson Feb 14, 2024
5f46a60
Add separate tests for install -Name '*'
alerickson Feb 14, 2024
429a864
update github wildcard tests
alerickson Feb 14, 2024
83c6891
update github tests
alerickson Feb 14, 2024
3e54e61
update tests
alerickson Feb 14, 2024
a45cafc
Remove whitespace
alerickson Feb 14, 2024
b3d4bd5
uninstall all test resources before running tests
alerickson Feb 14, 2024
d1bfd3c
Move uninstall to end of beforeall statement
alerickson Feb 14, 2024
41e6549
Update test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1
alerickson Feb 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
265 changes: 265 additions & 0 deletions test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,265 @@
# 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 $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
$res | Should -BeNullOrEmpty
}

It "Install specific module resource by name" {
Install-PSResource -Name $testModuleName -Repository $ACRRepoName -TrustRepository
$pkg = Get-InstalledPSResource $testModuleName
$pkg.Name | Should -Be $testModuleName
$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"
}
#>
adityapatwardhan marked this conversation as resolved.
Show resolved Hide resolved

It "Install multiple resources by name" {
$pkgNames = @($testModuleName, $testModuleName2)
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 $ACRRepoName -TrustRepository -ErrorVariable err -ErrorAction SilentlyContinue
$pkg = Get-InstalledPSResource "NonExistantModule"
$pkg | Should -BeNullOrEmpty
$err.Count | Should -BeGreaterThan 0
$err[0].FullyQualifiedErrorId | Should -BeExactly "ResourceNotFound,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 $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 $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 $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 $ACRRepoName -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)"
{ 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
}

It "Install resource when given Name, Version '*', should install the latest version" {
Install-PSResource -Name $testModuleName -Version "*" -Repository $ACRRepoName -TrustRepository
$pkg = Get-InstalledPSResource $testModuleName
$pkg.Name | Should -Be $testModuleName
$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
$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 $ACRRepoName | Install-PSResource -TrustRepository
$pkg = Get-InstalledPSResource $testModuleName
$pkg.Name | Should -Be $testModuleName
$pkg.Version | Should -Be "5.0.0"
}

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 $ACRRepoUri
}

# Windows only
It "Install resource under CurrentUser scope - Windows only" -Skip:(!(Get-IsWindows)) {
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
}

# Windows only
It "Install resource under AllUsers scope - Windows only" -Skip:(!((Get-IsWindows) -and (Test-IsAdmin))) {
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
}

# Windows only
It "Install resource under no specified scope - Windows only" -Skip:(!(Get-IsWindows)) {
Install-PSResource -Name $testModuleName -Repository $ACRRepoName -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 $ACRRepoName -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 $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 $ACRRepoName -TrustRepository
$pkg = Get-InstalledPSResource $testModuleName
$pkg.Name | Should -Be $testModuleName
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 $ACRRepoName -TrustRepository
$pkg = Get-InstalledPSResource $testModuleName
$pkg.Name | Should -Be $testModuleName
$pkg.Version | Should -Be "5.0.0"
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 $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 $ACRRepoName -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -18,6 +18,8 @@ Describe 'Test Install-PSResource for V3Server scenarios' -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 {
Expand All @@ -28,9 +30,9 @@ Describe 'Test Install-PSResource for V3Server scenarios' -tags 'CI' {
Get-RevertPSResourceRepositoryFile
}

$testCases = @{Name="*"; ErrorId="NameContainsWildcard"},
@{Name="Test_local_m*"; ErrorId="NameContainsWildcard"},
@{Name="Test?local","Test[local"; ErrorId="ErrorFilteringNamesForUnsupportedWildcards"}
$testCases = @{Name="*"; ErrorId="NameContainsWildcard"},
@{Name="Test_m*"; ErrorId="NameContainsWildcard"},
@{Name="Test?module","Test[module"; ErrorId="ErrorFilteringNamesForUnsupportedWildcards"}

It "Should not install resource with wildcard in name" -TestCases $testCases {
param($Name, $ErrorId)
Expand Down
Loading