Skip to content

Commit 72670db

Browse files
authored
change Find-PSResource tests to not test against production package Carbon (#530)
change Find tests to not test against production package Carbon
1 parent 7026ceb commit 72670db

File tree

1 file changed

+37
-36
lines changed

1 file changed

+37
-36
lines changed

test/FindPSResource.Tests.ps1

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Describe 'Test Find-PSResource for Module' {
99
$TestGalleryName = Get-PoshTestGalleryName
1010
$PSGalleryName = Get-PSGalleryName
1111
$NuGetGalleryName = Get-NuGetGalleryName
12-
$testModuleName = "testmodule"
12+
$testModuleName = "test_module"
1313
$testScriptName = "test_script"
1414
$commandName = "Get-TargetResource"
1515
$dscResourceName = "SystemLocale"
@@ -23,8 +23,8 @@ Describe 'Test Find-PSResource for Module' {
2323
}
2424

2525
It "find Specific Module Resource by Name" {
26-
$specItem = Find-PSResource -Name "Carbon"
27-
$specItem.Name | Should -Be "Carbon"
26+
$specItem = Find-PSResource -Name $testModuleName
27+
$specItem.Name | Should -Be $testModuleName
2828
}
2929

3030
It "should not find resource given nonexistant name" {
@@ -124,56 +124,56 @@ Describe 'Test Find-PSResource for Module' {
124124
$res.Count | Should -BeGreaterThan 1
125125
}
126126

127-
$testCases2 = @{Version="[2.10.0.0]"; ExpectedVersions=@("2.10.0.0"); Reason="validate version, exact match"},
128-
@{Version="2.10.0.0"; ExpectedVersions=@("2.10.0.0"); Reason="validate version, exact match without bracket syntax"},
129-
@{Version="[2.5.0.0, 2.8.0.0]"; ExpectedVersions=@("2.5.0.0", "2.5.1.0", "2.5.2.0", "2.5.3.0", "2.5.4.0", "2.6.0.0", "2.7.0.0", "2.8.0.0"); Reason="validate version, exact range inclusive"},
130-
@{Version="(2.5.0.0, 2.8.0.0)"; ExpectedVersions=@("2.5.1.0", "2.5.2.0", "2.5.3.0", "2.5.4.0", "2.6.0.0", "2.7.0.0"); Reason="validate version, exact range exclusive"},
131-
@{Version="(2.9.4.0,)"; ExpectedVersions=@("2.10.0.0", "2.10.1.0", "2.10.2.0"); Reason="validate version, minimum version exclusive"},
132-
@{Version="[2.9.4.0,)"; ExpectedVersions=@("2.9.4.0", "2.10.0.0", "2.10.1.0", "2.10.2.0"); Reason="validate version, minimum version inclusive"},
133-
@{Version="(,2.0.0.0)"; ExpectedVersions=@("1.9.0.0"); Reason="validate version, maximum version exclusive"},
134-
@{Version="(,2.0.0.0]"; ExpectedVersions=@("1.9.0.0", "2.0.0.0"); Reason="validate version, maximum version inclusive"},
135-
@{Version="[2.5.0.0, 2.8.0.0)"; ExpectedVersions=@("2.5.0.0", "2.5.1.0", "2.5.2.0", "2.5.3.0", "2.5.4.0", "2.6.0.0", "2.7.0.0", "2.8.0.0"); Reason="validate version, mixed inclusive minimum and exclusive maximum version"}
136-
@{Version="(2.5.0.0, 2.8.0.0]"; ExpectedVersions=@("2.5.1.0", "2.5.2.0", "2.5.3.0", "2.5.4.0", "2.6.0.0", "2.7.0.0", "2.8.0.0"); Reason="validate version, mixed exclusive minimum and inclusive maximum version"}
127+
$testCases2 = @{Version="[5.0.0.0]"; ExpectedVersions=@("5.0.0.0"); Reason="validate version, exact match"},
128+
@{Version="5.0.0.0"; ExpectedVersions=@("5.0.0.0"); Reason="validate version, exact match without bracket syntax"},
129+
@{Version="[2.5.0.0, 5.0.0.0]"; ExpectedVersions=@("2.5.0.0", "3.0.0.0", "4.0.0.0", "5.0.0.0"); Reason="validate version, exact range inclusive"},
130+
@{Version="(2.5.0.0, 5.0.0.0)"; ExpectedVersions=@("3.0.0.0", "4.0.0.0"); Reason="validate version, exact range exclusive"},
131+
@{Version="(2.5.0.0,)"; ExpectedVersions=@("3.0.0.0", "4.0.0.0", "5.0.0.0"); Reason="validate version, minimum version exclusive"},
132+
@{Version="[2.5.0.0,)"; ExpectedVersions=@("2.5.0.0", "3.0.0.0", "4.0.0.0", "5.0.0.0"); Reason="validate version, minimum version inclusive"},
133+
@{Version="(,2.5.0.0)"; ExpectedVersions=@("1.2.0.0", "1.5.0.0", "2.0.0.0"); Reason="validate version, maximum version exclusive"},
134+
@{Version="(,2.0.0.0]"; ExpectedVersions=@("1.2.0.0", "1.5.0.0", "2.0.0.0", "2.5.0.0"); Reason="validate version, maximum version inclusive"},
135+
@{Version="[2.5.0.0, 5.0.0.0)"; ExpectedVersions=@("2.5.0.0", "3.0.0.0", "4.0.0.0"); Reason="validate version, mixed inclusive minimum and exclusive maximum version"}
136+
@{Version="(2.5.0.0, 5.0.0.0]"; ExpectedVersions=@("3.0.0.0", "4.0.0.0", "5.0.0.0"); Reason="validate version, mixed exclusive minimum and inclusive maximum version"}
137137

138138
It "find resource when given Name to <Reason> <Version>" -TestCases $testCases2{
139139
param($Version, $ExpectedVersions)
140-
$res = Find-PSResource -Name "Carbon" -Version $Version -Repository $PSGalleryName
140+
$res = Find-PSResource -Name $testModuleName -Version $Version -Repository $TestGalleryName
141141
foreach ($item in $res) {
142-
$item.Name | Should -Be "Carbon"
142+
$item.Name | Should -Be $testModuleName
143143
$ExpectedVersions | Should -Contain $item.Version
144144
}
145145
}
146146

147147
It "not find resource with incorrectly formatted version such as <Description>" -TestCases @(
148-
@{Version='(2.10.0.0)'; Description="exclusive version (2.10.0.0)"},
149-
@{Version='[2-10-0-0]'; Description="version formatted with invalid delimiter"}
148+
@{Version='(2.5.0.0)'; Description="exclusive version (2.5.0.0)"},
149+
@{Version='[2-5-0-0]'; Description="version formatted with invalid delimiter"}
150150
) {
151151
param($Version, $Description)
152152

153-
$res = Find-PSResource -Name "Carbon" -Version $Version -Repository $PSGalleryName
153+
$res = Find-PSResource -Name $testModuleName -Version $Version -Repository $PSGalleryName
154154
$res | Should -BeNullOrEmpty
155155
}
156156

157157
$testCases = @{Version='[2.*.0.0]'; Description="version with wilcard in middle"},
158-
@{Version='[*.10.0.0]'; Description="version with wilcard at start"},
159-
@{Version='[2.10.*.0]'; Description="version with wildcard at third digit"}
160-
@{Version='[1.5.0.*'; Description="version with wildcard at end"},
161-
@{Version='[1..0.0]'; Description="version with missing digit in middle"},
162-
@{Version='[1.5.0.]'; Description="version with missing digit at end"},
163-
@{Version='[1.5.0.0.0]'; Description="version with more than 4 digits"}
158+
@{Version='[*.5.0.0]'; Description="version with wilcard at start"},
159+
@{Version='[2.5.*.0]'; Description="version with wildcard at third digit"}
160+
@{Version='[2.5.0.*'; Description="version with wildcard at end"},
161+
@{Version='[2..0.0]'; Description="version with missing digit in middle"},
162+
@{Version='[2.5.0.]'; Description="version with missing digit at end"},
163+
@{Version='[2.5.0.0.0]'; Description="version with more than 4 digits"}
164164

165165
It "not find resource and throw exception with incorrectly formatted version such as <Description>" -TestCases $testCases {
166166
param($Version, $Description)
167167

168-
Find-PSResource -Name "Carbon" -Version $Version -Repository $PSGalleryName -ErrorVariable err -ErrorAction SilentlyContinue
168+
Find-PSResource -Name $testModuleName -Version $Version -Repository $TestGalleryName -ErrorVariable err -ErrorAction SilentlyContinue
169169
$err.Count | Should -Not -Be 0
170170
$err[0].FullyQualifiedErrorId | Should -BeExactly "IncorrectVersionFormat,Microsoft.PowerShell.PowerShellGet.Cmdlets.FindPSResource"
171171
}
172172

173173
It "find resources when given Name, Version not null --> '*'" {
174-
$res = Find-PSResource -Name "Carbon" -Version "*" -Repository $PSGalleryName
174+
$res = Find-PSResource -Name $testModuleName -Version "*" -Repository $TestGalleryName
175175
$res | ForEach-Object {
176-
$_.Name | Should -Be "Carbon"
176+
$_.Name | Should -Be $testModuleName
177177
}
178178
$res.Count | Should -BeGreaterOrEqual 1
179179
}
@@ -203,9 +203,9 @@ Describe 'Test Find-PSResource for Module' {
203203
}
204204

205205
It "find resource when given Name, Version param null" {
206-
$res = Find-PSResource -Name "Carbon" -Repository $PSGalleryName
207-
$res.Name | Should -Be "Carbon"
208-
$res.Version | Should -Be "2.10.2.0"
206+
$res = Find-PSResource -Name $testModuleName -Repository $TestGalleryName
207+
$res.Name | Should -Be $testModuleName
208+
$res.Version | Should -Be "5.0.0.0"
209209
}
210210

211211
It "find resource with latest (including prerelease) version given Prerelease parameter" {
@@ -215,21 +215,22 @@ Describe 'Test Find-PSResource for Module' {
215215

216216
$resPrerelease = Find-PSResource -Name "test_module" -Prerelease -Repository $TestGalleryName
217217
$resPrerelease.Version | Should -Be "5.2.5.0"
218+
$resPrerelease.PrereleaseLabel | Should -Be "alpha001"
218219
}
219220

220221
It "find resources, including Prerelease version resources, when given Prerelease parameter" {
221-
$resWithoutPrerelease = Find-PSResource -Name "Carbon" -Version "*" -Repository $PSGalleryName
222-
$resWithPrerelease = Find-PSResource -Name "Carbon" -Version "*" -Repository $PSGalleryName
222+
$resWithoutPrerelease = Find-PSResource -Name $testModuleName -Version "*" -Repository $TestGalleryName
223+
$resWithPrerelease = Find-PSResource -Name $testModuleName -Version "*" -Repository $TestGalleryName
223224
$resWithPrerelease.Count | Should -BeGreaterOrEqual $resWithoutPrerelease.Count
224225
}
225226

226-
It "find resource of Type script or module from PSGallery, when no Type parameter provided" {
227+
It "find resource of Type script or module from PSGallery/PoshTestGallery, when no Type parameter provided" {
227228
$resScript = Find-PSResource -Name "AzureSqlScale" -Repository $PSGalleryName
228229
$resScript.Name | Should -Be "AzureSqlScale"
229230
$resScript.Type | Should -Be "Script"
230231

231-
$resModule = Find-PSResource -Name "Carbon" -Repository $PSGalleryName
232-
$resModule.Name | Should -Be "Carbon"
232+
$resModule = Find-PSResource -Name $testModuleName -Repository $TestGalleryName
233+
$resModule.Name | Should -Be $testModuleName
233234
$resModuleType = Out-String -InputObject $resModule.Type
234235
$resModuleType.Replace(",", " ").Split() | Should -Contain "Module"
235236
}
@@ -274,7 +275,7 @@ Describe 'Test Find-PSResource for Module' {
274275
It "find all resources with specified tag given Tag property" {
275276
$foundTestModule = $False
276277
$foundTestScript = $False
277-
$tagToFind = "Tag1"
278+
$tagToFind = "Tag2"
278279
$res = Find-PSResource -Tag $tagToFind -Repository $TestGalleryName
279280
foreach ($item in $res) {
280281
$item.Tags -contains $tagToFind | Should -Be $True

0 commit comments

Comments
 (0)