Skip to content

Commit 8ee78d7

Browse files
authored
Remaining find tests (#250)
1 parent 1c63016 commit 8ee78d7

8 files changed

+1303
-454
lines changed

Diff for: test/FindResource.Command.Tests.ps1

+226
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
Import-Module "$psscriptroot\PSGetTestUtils.psm1" -Force
5+
6+
Describe 'Test Find-PSResource for Command' {
7+
8+
BeforeAll{
9+
$TestGalleryName = Get-PoshTestGalleryName
10+
$PSGalleryName = Get-PSGalleryName
11+
Get-NewPSResourceRepositoryFile
12+
}
13+
14+
AfterAll {
15+
Get-RevertPSResourceRepositoryFile
16+
}
17+
18+
# Purpose: find Command resource given Name paramater
19+
#
20+
# Action: Find-PSResource -Name Az.Compute
21+
#
22+
# Expected Result: returns Az.Compute resource
23+
It "find Command resource given Name parameter" {
24+
$res = Find-PSResource -Name Az.Compute
25+
$res | Should -Not -BeNullOrEmpty
26+
$res.Name | Should -Be "Az.Compute"
27+
}
28+
29+
# Purpose: not find Command resource given unavailable name
30+
#
31+
# Action: Find-PSResource -Name NonExistantCommand
32+
#
33+
# Expected result: should not return NonExistantCommand resource
34+
It "should not find Command resource given unavailable name" {
35+
$res = Find-PSResource -Name NonExistantCommand
36+
$res | Should -BeNullOrEmpty
37+
}
38+
39+
# Purpose: find Command resource with exact version, given Version parameter
40+
#
41+
# Action: Find-PSResource -Name Az.Compute -Version "[4.3.0.0]"
42+
#
43+
# Expected Result: should return Az.Compute resource with version 4.3.0.0
44+
It "find Command resource given Name to <Reason>" -TestCases @(
45+
@{Version="[4.3.0.0]"; ExpectedVersion="4.3.0.0"; Reason="validate version, exact match"},
46+
@{Version="4.3.0.0"; ExpectedVersion="4.3.0.0"; Reason="validate version, exact match without bracket syntax"},
47+
@{Version="[4.2.0.0, 4.4.0.0]"; ExpectedVersion="4.4.0.0"; Reason="validate version, exact range inclusive"},
48+
@{Version="(4.2.0.0, 4.4.0.0)"; ExpectedVersion="4.3.1.0"; Reason="validate version, exact range exclusive"},
49+
@{Version="[4.4.0.0,)"; ExpectedVersion="4.4.0.0"; Reason="validate version, minimum version inclusive"},
50+
@{Version="(4.2.1.0,)"; ExpectedVersion="4.4.0.0"; Reason="validate version, minimum version exclusive"},
51+
@{Version="(,4.3.1.0)"; ExpectedVersion="4.3.0.0"; Reason="validate version, maximum version exclusive"},
52+
@{Version="(,4.3.1.0]"; ExpectedVersion="4.3.1.0"; Reason="validate version, maximum version inclusive"},
53+
@{Version="[4.2.0.0, 4.3.1.0)"; ExpectedVersion="4.3.0.0"; Reason="validate version, mixed inclusive minimum and exclusive maximum version"}
54+
)
55+
{
56+
param($Version, $ExpectedVersion)
57+
$res = Find-PSResource -Name "Az.Compute" -Version $Version -Repository $TestGalleryName
58+
$res.Name | Should -Be "Az.Compute"
59+
$res.Version | Should -Be $ExpectedVersion
60+
}
61+
62+
# Purpose: not find resources with invalid version
63+
#
64+
# Action: Find-PSResource -Name "Az.Compute" -Version "(4.2.1.0)"
65+
#
66+
# Expected Result: should not return a resource
67+
It "not find resource with incorrectly formatted version such as <Description>" -TestCases @(
68+
@{Version="(4.2.1.0)"; Description="exlcusive version (4.2.1.0)"},
69+
@{Version="[4-2-1-0]"; Description="version formatted with invalid delimiter"},
70+
@{Version="[4.*.0]"; Description="version with wilcard in middle"},
71+
@{Version="[*.2.1.0]"; Description="version with wilcard at start"},
72+
@{Version="[4.*.1.0]"; Description="version with wildcard at second digit"},
73+
@{Version="[4.2.*.0]"; Description="version with wildcard at third digit"}
74+
@{Version="[4.2.1.*"; Description="version with wildcard at end"},
75+
@{Version="[4..1.0]"; Description="version with missing digit in middle"},
76+
@{Version="[4.2.1.]"; Description="version with missing digit at end"},
77+
@{Version="[4.2.1.0.0]"; Description="version with more than 4 digits"}
78+
)
79+
{
80+
param($Version, $Description)
81+
$res = Find-PSResource -Name "Az.Compute" -Version $Version -Repository $TestGalleryName
82+
$res | Should -BeNullOrEmpty
83+
}
84+
85+
# Purpose: find Command resource with wildcard version, given Version parameter -> '*'
86+
#
87+
# Action: Find-PSResource -Name Az.Compute -Version "*"
88+
#
89+
# Expected Result: should return all Az.Compute resources (versions in descending order)
90+
It "find Command resource given Name to validate version wilcard match " {
91+
$res = Find-PSResource -Name "Az.Compute" -Version "*"
92+
$res.Count | Should -BeGreaterOrEqual 40
93+
}
94+
95+
# Purpose: find Command resource with latest version (including preview versions), with Prerelease parameter
96+
#
97+
# Action: Find-PSResource -Name Az.Accounts -Prerelease
98+
#
99+
# Expected Result: should return latest version (including preview versions) of Az.Accounts resource
100+
It "find Command resource with latest version (including preview versions), with Prerelease parameter" {
101+
$res = Find-PSResource -Name "Az.Accounts"
102+
$res.Version | Should -Be "1.9.4.0"
103+
104+
$resPrerelease = Find-PSResource -Name Az.Accounts -Prerelease
105+
$resPrerelease.Version | Should -Be "2.0.1.0"
106+
}
107+
108+
# Purpose: find Command resource given ModuleName parameter with Version null or empty
109+
#
110+
# Action: Find-PSResource -ModuleName "Az.Accounts" -Repository "PoshTestGallery"
111+
#
112+
# Expected Result: should return resource with latest version
113+
It "find Command resource given ModuleName with Version null or empty" {
114+
$res = Find-PSResource -ModuleName "Az.Compute" -Repository $TestGalleryName
115+
$res.Name | Should -Be "Az.Compute"
116+
}
117+
118+
# Purpose: find command resource when given ModuleName and any Version parameter
119+
#
120+
# Action: Find-PSResource -Name "Az.Accounts" -Version [2.0.0.0] -Repository "PoshTestGallery"
121+
#
122+
# Expected Result: should find a command resource when given ModuleName and any version value
123+
It "find Command resource given ModuleName to <Reason>" -TestCases @(
124+
@{Version="[4.3.0.0]"; ExpectedVersion="4.3.0.0"; Reason="validate version, exact match"},
125+
@{Version="4.3.0.0"; ExpectedVersion="4.3.0.0"; Reason="validate version, exact match without bracket syntax"},
126+
@{Version="[4.2.0.0, 4.4.0.0]"; ExpectedVersion="4.4.0.0"; Reason="validate version, exact range inclusive"},
127+
@{Version="(4.2.0.0, 4.4.0.0)"; ExpectedVersion="4.3.1.0"; Reason="validate version, exact range exclusive"},
128+
@{Version="[4.4.0.0,)"; ExpectedVersion="4.4.0.0"; Reason="validate version, minimum version inclusive"},
129+
@{Version="(4.2.1.0,)"; ExpectedVersion="4.4.0.0"; Reason="validate version, minimum version exclusive"},
130+
@{Version="(,4.3.1.0)"; ExpectedVersion="4.3.0.0"; Reason="validate version, maximum version exclusive"},
131+
@{Version="(,4.3.1.0]"; ExpectedVersion="4.3.1.0"; Reason="validate version, maximum version inclusive"},
132+
@{Version="[4.2.0.0, 4.3.1.0)"; ExpectedVersion="4.3.0.0"; Reason="validate version, mixed inclusive minimum and exclusive maximum version"}
133+
)
134+
{
135+
param($Version, $ExpectedVersion)
136+
$res = Find-PSResource -ModuleName "Az.Compute" -Version $Version -Repository $TestGalleryName
137+
$res.Name | Should -Be "Az.Compute"
138+
$res.Version | Should -Be $ExpectedVersion
139+
}
140+
141+
# Purpose: find Command resource given ModuleName to validate version match
142+
#
143+
# Action: Find-PSResource -ModuleName Az.Compute -Version "*"
144+
#
145+
# Expected Result: should return all Az.Compute resources (versions in descending order)
146+
It "find Command resource given ModuleName to validate version wildcard match " {
147+
$res = Find-PSResource -ModuleName "Az.Compute" -Version "*"
148+
$res.Count | Should -BeGreaterOrEqual 40
149+
}
150+
151+
# Purpose: find resource with tag, given single Tags parameter
152+
#
153+
# Action: Find-PSResource -Tags "Azure" -Repository PoshTestGallery | Where-Object { $_.Name -eq "Az.Accounts" }
154+
#
155+
# Expected Result: should return Az.Accounts resource
156+
It "find resource with single tag, given Tags parameter" {
157+
$res = Find-PSResource -Tags "Azure" -Repository $TestGalleryName | Where-Object { $_.Name -eq "Az.Accounts" }
158+
$res | Should -Not -BeNullOrEmpty
159+
$res.Name | Should -Be "Az.Accounts"
160+
161+
}
162+
163+
# Purpose: find resource with tags, given multiple Tags parameter values
164+
#
165+
# Action: Find-PSResource -Tags "Azure","Authentication","ARM" -Repository PoshTestGallery | Where-Object { $_.Name -eq "Az.Accounts" }
166+
#
167+
# Expected Result: should return Az.Accounts resource
168+
It "find resource with multiple tags, given Tags parameter" {
169+
$res = Find-PSResource -Tags "Azure","Authentication","ARM" -Repository $TestGalleryName | Where-Object { $_.Name -eq "Az.Accounts" }
170+
$res | Should -Not -BeNullOrEmpty
171+
$res.Name | Should -Be "Az.Accounts"
172+
}
173+
174+
# Purpose: not find Command resource from repository where it is not available, given Repository parameter
175+
#
176+
# Action: Find-PSResource -Name "xWindowsUpdate" -Repository PoshTestGallery
177+
#
178+
# Expected Result: should not find xWindowsUpdate resource
179+
It "not find Command resource from repository where it is not available, given Repository parameter" {
180+
$res = Find-PSResource -Name "xWindowsUpdate" -Repository $TestGalleryName
181+
$res | Should -BeNullOrEmpty
182+
}
183+
184+
# Purpose: find Command resource from repository where it is available, given Repository parameter
185+
#
186+
# Action: Find-PSResource -Name "xWindowsUpdate" -Repository PSGallery
187+
#
188+
# Expected Result: should find xWindowsUpdate resource
189+
It "find Command resource, given Repository parameter" {
190+
$res = Find-PSResource -Name "xWindowsUpdate" -Repository $PSGalleryName
191+
$res | Should -Not -BeNullOrEmpty
192+
$res.Name | Should -Be "xWindowsUpdate"
193+
}
194+
195+
# Purpose: find resource in first repository where it exists given Repository parameter
196+
#
197+
# Action: Find-PSResource "Az.Accounts"
198+
# Find-PSResource "Az.Accounts" -Repository PSGallery
199+
#
200+
# Expected Result: Returns resource from first avaiable or specfied repository
201+
It "find Resource given repository parameter, where resource exists in multiple repos" {
202+
# first availability found in PoshTestGallery
203+
$res = Find-PSResource "Az.Accounts"
204+
$res.Repository | Should -Be "PoshTestGallery"
205+
206+
# check that same resource can be returned from non-first-availability/non-default repo
207+
$resNonDefault = Find-PSResource "Az.Accounts" -Repository $PSGalleryName
208+
$resNonDefault | Should -Not -BeNullOrEmpty
209+
$resNonDefault.Repository | Should -Be "PSGallery"
210+
}
211+
212+
# Purpose: find resource in local repository given Repository parameter
213+
#
214+
# Action: Find-PSResource -Name "local_command_module" -Repository "psgettestlocal"
215+
#
216+
# Expected Result: should find resource from local repository
217+
It "find resource in local repository given Repository parameter" {
218+
$publishCmdName = "TestFindCommandModule"
219+
Get-CommandResourcePublishedToLocalRepoTestDrive $publishCmdName
220+
221+
$res = Find-PSResource -Name $publishCmdName -Repository "psgettestlocal"
222+
$res | Should -Not -BeNullOrEmpty
223+
$res.Name | Should -Be $publishCmdName
224+
$res.Repository | Should -Be "psgettestlocal"
225+
}
226+
}

0 commit comments

Comments
 (0)