-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathFindPSResourceContainerRegistryServer.Tests.ps1
More file actions
263 lines (227 loc) · 12.7 KB
/
FindPSResourceContainerRegistryServer.Tests.ps1
File metadata and controls
263 lines (227 loc) · 12.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
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
$modPath = "$psscriptroot/../PSGetTestUtils.psm1"
Import-Module $modPath -Force -Verbose
Describe 'Test HTTP Find-PSResource for ACR Server Protocol' -tags 'CI' {
BeforeAll{
$testModuleName = "test-module"
$testModuleParentName = "test_parent_mod"
$testModuleDependencyName = "test_dependency_mod"
$testScriptName = "test-script"
$ACRRepoName = "ACRRepo"
$ACRRepoUri = "https://psresourcegettest.azurecr.io"
Get-NewPSResourceRepositoryFile
$usingAzAuth = $env:USINGAZAUTH -eq 'true'
if ($usingAzAuth)
{
Write-Verbose -Verbose "Using Az module for authentication"
Register-PSResourceRepository -Name $ACRRepoName -ApiVersion 'ContainerRegistry' -Uri $ACRRepoUri -Verbose
}
else
{
$psCredInfo = New-Object Microsoft.PowerShell.PSResourceGet.UtilClasses.PSCredentialInfo ("SecretStore", "$env:TENANTID")
Register-PSResourceRepository -Name $ACRRepoName -ApiVersion 'ContainerRegistry' -Uri $ACRRepoUri -CredentialInfo $psCredInfo -Verbose
}
}
AfterAll {
Get-RevertPSResourceRepositoryFile
}
It "Find resource given specific Name, Version null" {
# FindName()
$res = Find-PSResource -Name $testModuleName -Repository $ACRRepoName
$res.Name | Should -Be $testModuleName
$res.Version | Should -Be "5.0.0"
}
It "Should not find resource given nonexistant Name" {
# FindName()
$res = Find-PSResource -Name NonExistantModule -Repository $ACRRepoName -ErrorVariable err -ErrorAction SilentlyContinue
$res | Should -BeNullOrEmpty
$err.Count | Should -BeGreaterThan 0
$err[0].FullyQualifiedErrorId | Should -BeExactly "ResourceNotFound,Microsoft.PowerShell.PSResourceGet.Cmdlets.FindPSResource"
$res | Should -BeNullOrEmpty
}
$testCases2 = @{Version="[5.0.0.0]"; ExpectedVersions=@("5.0.0"); Reason="validate version, exact match"},
@{Version="5.0.0.0"; ExpectedVersions=@("5.0.0"); Reason="validate version, exact match without bracket syntax"},
@{Version="[1.0.0.0, 5.0.0.0]"; ExpectedVersions=@("1.0.0", "3.0.0", "5.0.0"); Reason="validate version, exact range inclusive"},
@{Version="(1.0.0.0, 5.0.0.0)"; ExpectedVersions=@("3.0.0"); Reason="validate version, exact range exclusive"},
@{Version="(1.0.0.0,)"; ExpectedVersions=@("3.0.0", "5.0.0"); Reason="validate version, minimum version exclusive"},
@{Version="[1.0.0.0,)"; ExpectedVersions=@("1.0.0", "3.0.0", "5.0.0"); Reason="validate version, minimum version inclusive"},
@{Version="(,3.0.0.0)"; ExpectedVersions=@("1.0.0"); Reason="validate version, maximum version exclusive"},
@{Version="(,3.0.0.0]"; ExpectedVersions=@("1.0.0", "3.0.0"); Reason="validate version, maximum version inclusive"},
@{Version="[1.0.0.0, 5.0.0.0)"; ExpectedVersions=@("1.0.0", "3.0.0"); Reason="validate version, mixed inclusive minimum and exclusive maximum version"}
@{Version="(1.0.0.0, 5.0.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 $ACRRepoName
$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 $ACRRepoName
$res | Should -Not -BeNullOrEmpty
$res | ForEach-Object {
$_.Name | Should -Be $testModuleName
}
$res.Count | Should -BeGreaterOrEqual 1
}
It "Find module and dependencies when -IncludeDependencies is specified" {
$res = Find-PSResource -Name $testModuleParentName -Repository $ACRRepoName -IncludeDependencies
$res | Should -Not -BeNullOrEmpty
$res.Name | Should -Be @($testModuleParentName, $testModuleDependencyName)
$res.Version[0].ToString() | Should -Be "1.0.0"
$res.Version[1].ToString() | Should -Be "1.0.0"
}
It "Find resource given specific Name, Version null but allowing Prerelease" {
# FindName()
$res = Find-PSResource -Name $testModuleName -Repository $ACRRepoName -Prerelease
$res.Name | Should -Be $testModuleName
$res.Version | Should -Be "5.2.5"
$res.Prerelease | Should -Be "alpha"
}
It "Find resource with latest (including prerelease) version given Prerelease parameter" {
# FindName()
# test_local_mod resource's latest version is a prerelease version, before that it has a non-prerelease version
$res = Find-PSResource -Name $testModuleName -Repository $ACRRepoName
$res.Version | Should -Be "5.0.0"
$resPrerelease = Find-PSResource -Name $testModuleName -Prerelease -Repository $ACRRepoName
$resPrerelease.Version | Should -Be "5.2.5"
$resPrerelease.Prerelease | Should -Be "alpha"
}
It "Find resources, including Prerelease version resources, when given Prerelease parameter" {
# FindVersionGlobbing()
$resWithoutPrerelease = Find-PSResource -Name $testModuleName -Version "*" -Repository $ACRRepoName
$resWithPrerelease = Find-PSResource -Name $testModuleName -Version "*" -Repository $ACRRepoName -Prerelease
$resWithPrerelease.Count | Should -BeGreaterOrEqual $resWithoutPrerelease.Count
}
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_local_mod package
$res = Find-PSResource -Name $testModuleName -Version "5.0.0.0" -Tag $requiredTag -Repository $ACRRepoName -ErrorVariable err -ErrorAction SilentlyContinue
$res | Should -BeNullOrEmpty
$err.Count | Should -BeGreaterThan 0
$err[0].FullyQualifiedErrorId | Should -BeExactly "FindVersionWithTagFailure,Microsoft.PowerShell.PSResourceGet.Cmdlets.FindPSResource"
}
It "Should not find resources given Tag property" {
# FindTag()
$tagToFind = "Tag2"
$res = Find-PSResource -Tag $tagToFind -Repository $ACRRepoName -ErrorVariable err -ErrorAction SilentlyContinue
$res | Should -BeNullOrEmpty
$err.Count | Should -BeGreaterThan 0
$err[0].FullyQualifiedErrorId | Should -BeExactly "FindTagsFailure,Microsoft.PowerShell.PSResourceGet.Cmdlets.FindPSResource"
}
It "Should not find resource given CommandName" {
# FindCommandOrDSCResource()
$res = Find-PSResource -CommandName "command" -Repository $ACRRepoName -ErrorVariable err -ErrorAction SilentlyContinue
$res | Should -BeNullOrEmpty
$err.Count | Should -BeGreaterThan 0
write-Host $($err[0].FullyQualifiedErrorId)
$err[0].FullyQualifiedErrorId | Should -BeExactly "FindCommandOrDscResourceFailure,Microsoft.PowerShell.PSResourceGet.Cmdlets.FindPSResource"
}
It "Should not find resource given DscResourceName" {
# FindCommandOrDSCResource()
$res = Find-PSResource -DscResourceName "dscResource" -Repository $ACRRepoName -ErrorVariable err -ErrorAction SilentlyContinue
$res | Should -BeNullOrEmpty
$err.Count | Should -BeGreaterThan 0
$err[0].FullyQualifiedErrorId | Should -BeExactly "FindCommandOrDscResourceFailure,Microsoft.PowerShell.PSResourceGet.Cmdlets.FindPSResource"
}
It "Should not find all resources given Name '*'" {
# FindAll()
$res = Find-PSResource -Name "*" -Repository $ACRRepoName -ErrorVariable err -ErrorAction SilentlyContinue
$res | Should -BeNullOrEmpty
$err.Count | Should -BeGreaterThan 0
$err[0].FullyQualifiedErrorId | Should -BeExactly "FindAllFailure,Microsoft.PowerShell.PSResourceGet.Cmdlets.FindPSResource"
}
It "Should find script given Name" {
# FindName()
$res = Find-PSResource -Name $testScriptName -Repository $ACRRepoName
$res | Should -Not -BeNullOrEmpty
$res.Name | Should -BeExactly $testScriptName
$res.Version | Should -Be "3.0.0"
$res.Type.ToString() | Should -Be "Script"
}
It "Should find script given Name and Prerelease" {
# latest version is a prerelease version
$res = Find-PSResource -Name $testScriptName -Prerelease -Repository $ACRRepoName
$res | Should -Not -BeNullOrEmpty
$res.Name | Should -BeExactly $testScriptName
$res.Version | Should -Be "5.0.0"
$res.Prerelease | Should -Be "alpha"
$res.Type.ToString() | Should -Be "Script"
}
It "Should find script given Name and Version" {
# FindVersion()
$res = Find-PSResource -Name $testScriptName -Version "1.0.0" -Repository $ACRRepoName
$res | Should -Not -BeNullOrEmpty
$res.Name | Should -BeExactly $testScriptName
$res.Version | Should -Be "1.0.0"
$res.Type.ToString() | Should -Be "Script"
}
It "Should find script given Name, Version and Prerelease" {
# latest version is a prerelease version
$res = Find-PSResource -Name $testScriptName -Version "5.0.0-alpha" -Prerelease -Repository $ACRRepoName
$res | Should -Not -BeNullOrEmpty
$res.Name | Should -BeExactly $testScriptName
$res.Version | Should -Be "5.0.0"
$res.Prerelease | Should -Be "alpha"
$res.Type.ToString() | Should -Be "Script"
}
It "Should find and return correct resource type - module" {
$res = Find-PSResource -Name $testModuleName -Repository $ACRRepoName
$res | Should -Not -BeNullOrEmpty
$res.Name | Should -BeExactly $testModuleName
$res.Version | Should -Be "5.0.0"
$res.Type.ToString() | Should -Be "Module"
}
It "Should find and return correct resource type - script" {
$scriptName = "test-script"
$res = Find-PSResource -Name $scriptName -Repository $ACRRepoName
$res | Should -Not -BeNullOrEmpty
$res.Name | Should -BeExactly $scriptName
$res.Version | Should -Be "3.0.0"
$res.Type.ToString() | Should -Be "Script"
}
It "Should find module with varying case sensitivity" {
$res = Find-PSResource -Name "test-camelCaseModule" -Repository $ACRRepoName
$res.Name | Should -BeExactly "test-camelCaseModule"
$res.Version | Should -Be "1.0.0"
$res.Type.ToString() | Should -Be "Module"
}
It "Should find script with varying case sensitivity" {
$res = Find-PSResource -Name "test-camelCaseScript" -Repository $ACRRepoName
$res.Name | Should -BeExactly "test-camelCaseScript"
$res.Version | Should -Be "1.0.0"
$res.Type.ToString() | Should -Be "Script"
}
It "Should find resource with dependency, given Name and Version" {
$res = Find-PSResource -Name "Az.Storage" -Version "8.0.0" -Repository $ACRRepoName
$res.Dependencies.Length | Should -Be 1
$res.Dependencies[0].Name | Should -Be "Az.Accounts"
}
}
Describe 'Test Find-PSResource for MAR Repository' -tags 'CI' {
BeforeAll {
Register-PSResourceRepository -Name "MAR" -Uri "https://mcr.microsoft.com" -ApiVersion "ContainerRegistry"
}
AfterAll {
Unregister-PSResourceRepository -Name "MAR"
}
It "Should find resource given specific Name, Version null" {
$res = Find-PSResource -Name "Az.Accounts" -Repository "MAR"
$res.Name | Should -Be "Az.Accounts"
$res.Version | Should -Be "4.0.2"
}
It "Should find resource and its dependency given specific Name and Version" {
$res = Find-PSResource -Name "Az.Storage" -Version "8.0.0" -Repository "MAR"
$res.Dependencies.Length | Should -Be 1
$res.Dependencies[0].Name | Should -Be "Az.Accounts"
}
It "Should find Azpreview resource and it's dependency given specific Name and Version" {
$res = Find-PSResource -Name "Azpreview" -Version "13.2.0" -Repository "MAR"
$res.Dependencies.Length | Should -Not -Be 0
}
}