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