|
| 1 | +# Copyright (c) Microsoft Corporation. |
| 2 | +# Licensed under the MIT License. |
| 3 | + |
| 4 | +$modPath = "$psscriptroot/../PSGetTestUtils.psm1" |
| 5 | +Import-Module $modPath -Force -Verbose |
| 6 | + |
| 7 | +$psmodulePaths = $env:PSModulePath -split ';' |
| 8 | +Write-Verbose -Verbose "Current module search paths: $psmodulePaths" |
| 9 | + |
| 10 | +Describe 'Test HTTP Find-PSResource for ADO V2 Server Protocol' -tags 'CI' { |
| 11 | + |
| 12 | + BeforeAll{ |
| 13 | + $testModuleName = "test_local_mod" |
| 14 | + $ADOV2RepoName = "PSGetTestingPublicFeed" |
| 15 | + $ADOV2RepoUri = "https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell-public-test/nuget/v2" |
| 16 | + Get-NewPSResourceRepositoryFile |
| 17 | + Register-PSResourceRepository -Name $ADOV2RepoName -Uri $ADOV2RepoUri |
| 18 | + } |
| 19 | + |
| 20 | + AfterAll { |
| 21 | + Get-RevertPSResourceRepositoryFile |
| 22 | + } |
| 23 | + |
| 24 | + It "Find resource given specific Name, Version null" { |
| 25 | + $res = Find-PSResource -Name $testModuleName -Repository $ADOV2RepoName |
| 26 | + $res.Name | Should -Be $testModuleName |
| 27 | + $res.Version | Should -Be "5.0.0" |
| 28 | + } |
| 29 | + |
| 30 | + It "Should not find resource given nonexistant Name" { |
| 31 | + $res = Find-PSResource -Name NonExistantModule -Repository $ADOV2RepoName -ErrorVariable err -ErrorAction SilentlyContinue |
| 32 | + $res | Should -BeNullOrEmpty |
| 33 | + $err.Count | Should -BeGreaterThan 0 |
| 34 | + $err[0].FullyQualifiedErrorId | Should -BeExactly "ResourceNotFound,Microsoft.PowerShell.PSResourceGet.Cmdlets.FindPSResource" |
| 35 | + $res | Should -BeNullOrEmpty |
| 36 | + } |
| 37 | + |
| 38 | + It "Find resource(s) given wildcard Name" { |
| 39 | + # FindNameGlobbing |
| 40 | + $foundScript = $False |
| 41 | + $res = Find-PSResource -Name "test_*" -Repository $ADOV2RepoName |
| 42 | + $res.Count | Should -BeGreaterThan 1 |
| 43 | + } |
| 44 | + |
| 45 | + $testCases2 = @{Version="[5.0.0]"; ExpectedVersions=@("5.0.0"); Reason="validate version, exact match"}, |
| 46 | + @{Version="5.0.0"; ExpectedVersions=@("5.0.0"); Reason="validate version, exact match without bracket syntax"}, |
| 47 | + @{Version="[1.0.0, 5.0.0]"; ExpectedVersions=@("1.0.0", "3.0.0", "5.0.0"); Reason="validate version, exact range inclusive"}, |
| 48 | + @{Version="(1.0.0, 5.0.0)"; ExpectedVersions=@("3.0.0"); Reason="validate version, exact range exclusive"}, |
| 49 | + @{Version="(1.0.0,)"; ExpectedVersions=@("3.0.0", "5.0.0"); Reason="validate version, minimum version exclusive"}, |
| 50 | + @{Version="[1.0.0,)"; ExpectedVersions=@("1.0.0", "3.0.0", "5.0.0"); Reason="validate version, minimum version inclusive"}, |
| 51 | + @{Version="(,3.0.0)"; ExpectedVersions=@("1.0.0"); Reason="validate version, maximum version exclusive"}, |
| 52 | + @{Version="(,3.0.0]"; ExpectedVersions=@("1.0.0", "3.0.0"); Reason="validate version, maximum version inclusive"}, |
| 53 | + @{Version="[1.0.0, 5.0.0)"; ExpectedVersions=@("1.0.0", "3.0.0"); Reason="validate version, mixed inclusive minimum and exclusive maximum version"} |
| 54 | + @{Version="(1.0.0, 5.0.0]"; ExpectedVersions=@("3.0.0", "5.0.0"); Reason="validate version, mixed exclusive minimum and inclusive maximum version"} |
| 55 | + |
| 56 | + It "Find resource when given Name to <Reason> <Version>" -TestCases $testCases2{ |
| 57 | + # FindVersionGlobbing() |
| 58 | + param($Version, $ExpectedVersions) |
| 59 | + $res = Find-PSResource -Name $testModuleName -Version $Version -Repository $ADOV2RepoName |
| 60 | + $res | Should -Not -BeNullOrEmpty |
| 61 | + foreach ($item in $res) { |
| 62 | + $item.Name | Should -Be $testModuleName |
| 63 | + $ExpectedVersions | Should -Contain $item.Version |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + It "Find all versions of resource when given specific Name, Version not null --> '*'" { |
| 68 | + # FindVersionGlobbing() |
| 69 | + $res = Find-PSResource -Name $testModuleName -Version "*" -Repository $ADOV2RepoName |
| 70 | + $res | ForEach-Object { |
| 71 | + $_.Name | Should -Be $testModuleName |
| 72 | + } |
| 73 | + |
| 74 | + $res.Count | Should -BeGreaterOrEqual 1 |
| 75 | + } |
| 76 | + |
| 77 | + It "Find resource with latest (including prerelease) version given Prerelease parameter" { |
| 78 | + # FindName() |
| 79 | + # test_module resource's latest version is a prerelease version, before that it has a non-prerelease version |
| 80 | + $res = Find-PSResource -Name $testModuleName -Repository $ADOV2RepoName |
| 81 | + $res.Version | Should -Be "5.0.0" |
| 82 | + |
| 83 | + $resPrerelease = Find-PSResource -Name $testModuleName -Prerelease -Repository $ADOV2RepoName |
| 84 | + $resPrerelease.Version | Should -Be "5.2.5" |
| 85 | + $resPrerelease.Prerelease | Should -Be "alpha001" |
| 86 | + } |
| 87 | + |
| 88 | + It "Find resources, including Prerelease version resources, when given Prerelease parameter" { |
| 89 | + # FindVersionGlobbing() |
| 90 | + $resWithoutPrerelease = Find-PSResource -Name $testModuleName -Version "*" -Repository $ADOV2RepoName |
| 91 | + $resWithPrerelease = Find-PSResource -Name $testModuleName -Version "*" -Repository $ADOV2RepoName |
| 92 | + $resWithPrerelease.Count | Should -BeGreaterOrEqual $resWithoutPrerelease.Count |
| 93 | + } |
| 94 | + |
| 95 | +<# LATER |
| 96 | + It "Find resource and its dependency resources with IncludeDependencies parameter" { |
| 97 | + # FindName() with deps |
| 98 | + $resWithoutDependencies = Find-PSResource -Name "TestModuleWithDependencyE" -Repository $ADOV2RepoName |
| 99 | + $resWithoutDependencies.Name | Should -Be "TestModuleWithDependencyE" |
| 100 | + $resWithoutDependencies | Should -HaveCount 1 |
| 101 | +
|
| 102 | + # TestModuleWithDependencyE has the following dependencies: |
| 103 | + # TestModuleWithDependencyC <= 1.0.0.0 |
| 104 | + # TestModuleWithDependencyB >= 1.0.0.0 |
| 105 | + # TestModuleWithDependencyD <= 1.0.0.0 |
| 106 | +
|
| 107 | + $resWithDependencies = Find-PSResource -Name "TestModuleWithDependencyE" -IncludeDependencies -Repository $ADOV2RepoName |
| 108 | + $resWithDependencies | Should -HaveCount 4 |
| 109 | +
|
| 110 | + $foundParentPkgE = $false |
| 111 | + $foundDepB = $false |
| 112 | + $foundDepBCorrectVersion = $false |
| 113 | + $foundDepC = $false |
| 114 | + $foundDepCCorrectVersion = $false |
| 115 | + $foundDepD = $false |
| 116 | + $foundDepDCorrectVersion = $false |
| 117 | + foreach ($pkg in $resWithDependencies) |
| 118 | + { |
| 119 | + if ($pkg.Name -eq "TestModuleWithDependencyE") |
| 120 | + { |
| 121 | + $foundParentPkgE = $true |
| 122 | + } |
| 123 | + elseif ($pkg.Name -eq "TestModuleWithDependencyC") |
| 124 | + { |
| 125 | + $foundDepC = $true |
| 126 | + $foundDepCCorrectVersion = [System.Version]$pkg.Version -le [System.Version]"1.0" |
| 127 | + } |
| 128 | + elseif ($pkg.Name -eq "TestModuleWithDependencyB") |
| 129 | + { |
| 130 | + $foundDepB = $true |
| 131 | + $foundDepBCorrectVersion = [System.Version]$pkg.Version -ge [System.Version]"1.0" |
| 132 | + } |
| 133 | + elseif ($pkg.Name -eq "TestModuleWithDependencyD") |
| 134 | + { |
| 135 | + $foundDepD = $true |
| 136 | + $foundDepDCorrectVersion = [System.Version]$pkg.Version -le [System.Version]"1.0" |
| 137 | + } |
| 138 | + } |
| 139 | +
|
| 140 | + $foundParentPkgE | Should -Be $true |
| 141 | + $foundDepC | Should -Be $true |
| 142 | + $foundDepCCorrectVersion | Should -Be $true |
| 143 | + $foundDepB | Should -Be $true |
| 144 | + $foundDepBCorrectVersion | Should -Be $true |
| 145 | + $foundDepD | Should -Be $true |
| 146 | + $foundDepDCorrectVersion | Should -Be $true |
| 147 | + } |
| 148 | +
|
| 149 | + It "find resource of Type script or module from PSGallery, when no Type parameter provided" { |
| 150 | + # FindName() script |
| 151 | + $resScript = Find-PSResource -Name $testScriptName -Repository $ADOV2RepoName |
| 152 | + $resScript.Name | Should -Be $testScriptName |
| 153 | + $resScriptType = Out-String -InputObject $resScript.Type |
| 154 | + $resScriptType.Replace(",", " ").Split() | Should -Contain "Script" |
| 155 | +
|
| 156 | + $resModule = Find-PSResource -Name $testModuleName -Repository $ADOV2RepoName |
| 157 | + $resModule.Name | Should -Be $testModuleName |
| 158 | + $resModuleType = Out-String -InputObject $resModule.Type |
| 159 | + $resModuleType.Replace(",", " ").Split() | Should -Contain "Module" |
| 160 | + } |
| 161 | +
|
| 162 | + It "find resource of Type Script from PSGallery, when Type Script specified" { |
| 163 | + # FindName() Type script |
| 164 | + $resScript = Find-PSResource -Name $testScriptName -Repository $ADOV2RepoName -Type "Script" |
| 165 | + $resScript.Name | Should -Be $testScriptName |
| 166 | + $resScriptType = Out-String -InputObject $resScript.Type |
| 167 | + $resScriptType.Replace(",", " ").Split() | Should -Contain "Script" |
| 168 | + } |
| 169 | +#> |
| 170 | + |
| 171 | + |
| 172 | + It "Find all resources of Type Module when Type parameter set is used" { |
| 173 | + $res = Find-PSResource -Name "test*" -Type Module -Repository $ADOV2RepoName -ErrorVariable err -ErrorAction SilentlyContinue |
| 174 | + $res | Should -BeNullOrEmpty |
| 175 | + $err.Count | Should -BeGreaterThan 0 |
| 176 | + $err[0].FullyQualifiedErrorId | Should -BeExactly "FindNameGlobbingNotSupportedForRepo,Microsoft.PowerShell.PSResourceGet.Cmdlets.FindPSResource" |
| 177 | + } |
| 178 | + |
| 179 | + It "Find resource that satisfies given Name and Tag property (single tag)" { |
| 180 | + # FindNameWithTag() |
| 181 | + $requiredTag = "Test" |
| 182 | + $res = Find-PSResource -Name $testModuleName -Tag $requiredTag -Repository $ADOV2RepoName |
| 183 | + $res.Name | Should -Be $testModuleName |
| 184 | + $res.Tags | Should -Contain $requiredTag |
| 185 | + } |
| 186 | + |
| 187 | + It "Should not find resource if Name and Tag are not both satisfied (single tag)" { |
| 188 | + # FindNameWithTag |
| 189 | + $requiredTag = "Windows" # tag "windows" is not present for test_module package |
| 190 | + $res = Find-PSResource -Name $testModuleName -Tag $requiredTag -Repository $ADOV2RepoName -ErrorVariable err -ErrorAction SilentlyContinue |
| 191 | + $res | Should -BeNullOrEmpty |
| 192 | + $err.Count | Should -BeGreaterThan 0 |
| 193 | + $err[0].FullyQualifiedErrorId | Should -BeExactly "PackageNotFound,Microsoft.PowerShell.PSResourceGet.Cmdlets.FindPSResource" |
| 194 | + } |
| 195 | + |
| 196 | + It "Find resource that satisfies given Name and Tag property (multiple tags)" { |
| 197 | + # FindNameWithTag() |
| 198 | + $requiredTags = @("Test", "Tag2") |
| 199 | + $res = Find-PSResource -Name $testModuleName -Tag $requiredTags -Repository $ADOV2RepoName |
| 200 | + $res.Name | Should -Be $testModuleName |
| 201 | + $res.Tags | Should -Contain $requiredTags[0] |
| 202 | + $res.Tags | Should -Contain $requiredTags[1] |
| 203 | + } |
| 204 | + |
| 205 | + It "Should not find resource if Name and Tag are not both satisfied (multiple tag)" { |
| 206 | + # FindNameWithTag |
| 207 | + $requiredTags = @("test", "Windows") # tag "windows" is not present for test_module package |
| 208 | + $res = Find-PSResource -Name $testModuleName -Tag $requiredTags -Repository $ADOV2RepoName -ErrorVariable err -ErrorAction SilentlyContinue |
| 209 | + $res | Should -BeNullOrEmpty |
| 210 | + $err.Count | Should -BeGreaterThan 0 |
| 211 | + $err[0].FullyQualifiedErrorId | Should -BeExactly "PackageNotFound,Microsoft.PowerShell.PSResourceGet.Cmdlets.FindPSResource" |
| 212 | + } |
| 213 | + |
| 214 | + It "Find all resources that satisfy Name pattern and have specified Tag (single tag)" { |
| 215 | + # FindNameGlobbingWithTag() |
| 216 | + $requiredTag = "test" |
| 217 | + $nameWithWildcard = "test_module*" |
| 218 | + $res = Find-PSResource -Name $nameWithWildcard -Tag $requiredTag -Repository $ADOV2RepoName -ErrorVariable err -ErrorAction SilentlyContinue |
| 219 | + $res | Should -BeNullOrEmpty |
| 220 | + $err.Count | Should -BeGreaterThan 0 |
| 221 | + $err[0].FullyQualifiedErrorId | Should -BeExactly "FindNameGlobbingAndTagFailure,Microsoft.PowerShell.PSResourceGet.Cmdlets.FindPSResource" |
| 222 | + |
| 223 | + } |
| 224 | + |
| 225 | + It "Should not find resources if both Name pattern and Tags are not satisfied (multiple tags)" { |
| 226 | + # FindNameGlobbingWithTag() # tag "windows" is not present for test_module package |
| 227 | + $requiredTags = @("Test", "windows") |
| 228 | + $res = Find-PSResource -Name $testModuleName -Tag $requiredTags -Repository $ADOV2RepoName -ErrorAction SilentlyContinue |
| 229 | + $res | Should -BeNullOrEmpty |
| 230 | + } |
| 231 | + |
| 232 | + It "Find resource that satisfies given Name, Version and Tag property (single tag)" { |
| 233 | + # FindVersionWithTag() |
| 234 | + $requiredTag = "Test" |
| 235 | + $res = Find-PSResource -Name $testModuleName -Version "5.0.0" -Tag $requiredTag -Repository $ADOV2RepoName |
| 236 | + $res.Name | Should -Be $testModuleName |
| 237 | + $res.Version | Should -Be "5.0.0" |
| 238 | + $res.Tags | Should -Contain $requiredTag |
| 239 | + } |
| 240 | + |
| 241 | + It "Should not find resource if Name, Version and Tag property are not all satisfied (single tag)" { |
| 242 | + # FindVersionWithTag() |
| 243 | + $requiredTag = "windows" # tag "windows" is not present for test_module package |
| 244 | + $res = Find-PSResource -Name $testModuleName -Version "5.0.0" -Tag $requiredTag -Repository $ADOV2RepoName -ErrorVariable err -ErrorAction SilentlyContinue |
| 245 | + $res | Should -BeNullOrEmpty |
| 246 | + $err.Count | Should -BeGreaterThan 0 |
| 247 | + $err[0].FullyQualifiedErrorId | Should -BeExactly "PackageNotFound,Microsoft.PowerShell.PSResourceGet.Cmdlets.FindPSResource" |
| 248 | + } |
| 249 | + |
| 250 | + It "Find resource that satisfies given Name, Version and Tag property (multiple tags)" { |
| 251 | + # FindVersionWithTag() |
| 252 | + $requiredTags = @("Test", "Tag2") |
| 253 | + $res = Find-PSResource -Name $testModuleName -Version "5.0.0" -Tag $requiredTags -Repository $ADOV2RepoName |
| 254 | + $res.Name | Should -Be $testModuleName |
| 255 | + $res.Version | Should -Be "5.0.0" |
| 256 | + $res.Tags | Should -Contain $requiredTags[0] |
| 257 | + $res.Tags | Should -Contain $requiredTags[1] |
| 258 | + |
| 259 | + } |
| 260 | + |
| 261 | + It "Should not find resource if Name, Version and Tag property are not all satisfied (multiple tags)" { |
| 262 | + # FindVersionWithTag() |
| 263 | + $requiredTags = @("test", "windows") |
| 264 | + $res = Find-PSResource -Name $testModuleName -Version "5.0.0" -Tag $requiredTags -Repository $ADOV2RepoName -ErrorVariable err -ErrorAction SilentlyContinue |
| 265 | + $res | Should -BeNullOrEmpty |
| 266 | + $err.Count | Should -BeGreaterThan 0 |
| 267 | + $err[0].FullyQualifiedErrorId | Should -BeExactly "PackageNotFound,Microsoft.PowerShell.PSResourceGet.Cmdlets.FindPSResource" |
| 268 | + } |
| 269 | +} |
0 commit comments