Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

Commit 576c3fe

Browse files
ThomasNietoalerickson
authored andcommitted
Add Support for SourceLocation and ScriptSourceLocation Using Same URI (#427)
1 parent 2c2e910 commit 576c3fe

File tree

7 files changed

+217
-107
lines changed

7 files changed

+217
-107
lines changed

Tests/PSGetFindModule.Tests.ps1

Lines changed: 57 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,28 @@ function SuiteSetup {
3131
$psgetModuleInfo = Import-Module PowerShellGet -Global -Force -Passthru
3232
Import-LocalizedData script:LocalizedData -filename PSGet.Resource.psd1 -BaseDirectory $psgetModuleInfo.ModuleBase
3333

34-
$script:moduleSourcesFilePath= Join-Path $script:PSGetLocalAppDataPath "PSRepositories.xml"
34+
$script:moduleSourcesFilePath = Join-Path $script:PSGetLocalAppDataPath "PSRepositories.xml"
3535
$script:moduleSourcesBackupFilePath = Join-Path $script:PSGetLocalAppDataPath "PSRepositories.xml_$(get-random)_backup"
36-
if(Test-Path $script:moduleSourcesFilePath)
37-
{
36+
if (Test-Path $script:moduleSourcesFilePath) {
3837
Rename-Item $script:moduleSourcesFilePath $script:moduleSourcesBackupFilePath -Force
3938
}
4039

4140
GetAndSet-PSGetTestGalleryDetails -SetPSGallery
4241
}
4342

4443
function SuiteCleanup {
45-
if(Test-Path $script:moduleSourcesBackupFilePath)
46-
{
44+
if (Test-Path $script:moduleSourcesBackupFilePath) {
4745
Move-Item $script:moduleSourcesBackupFilePath $script:moduleSourcesFilePath -Force
4846
}
49-
else
50-
{
47+
else {
5148
RemoveItem $script:moduleSourcesFilePath
5249
}
5350

5451
# Import the PowerShellGet provider to reload the repositories.
5552
$null = Import-PackageProvider -Name PowerShellGet -Force
5653
}
5754

58-
Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT','InnerLoop' {
55+
Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT', 'InnerLoop' {
5956

6057
BeforeAll {
6158
SuiteSetup
@@ -120,7 +117,29 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT','InnerLoop' {
120117
#
121118
It "FindModuleNonExistentModule" {
122119
AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module NonExistentModule} `
123-
-expectedFullyQualifiedErrorId "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage"
120+
-expectedFullyQualifiedErrorId "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage"
121+
}
122+
123+
# Purpose: FindScriptNotModule
124+
#
125+
# Action: Find-Module Fabrikam-ServerScript
126+
#
127+
# Expected Result: Should fail
128+
#
129+
It "FindScriptNotModule" {
130+
AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module Fabrikam-ServerScript} `
131+
-expectedFullyQualifiedErrorId 'MatchInvalidType,Find-Module'
132+
}
133+
134+
# Purpose: FindScriptNotModuleWildcard
135+
#
136+
# Action: Find-Module Fabrikam-ServerScript
137+
#
138+
# Expected Result: Should not return anything
139+
#
140+
It "FindScriptNotModuleWildcard" {
141+
$res = Find-Module Fabrikam-ServerScript*
142+
Assert (-not $res) "Find-Module returned a script"
124143
}
125144

126145
# Purpose: FindModuleWithVersionParams
@@ -131,7 +150,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT','InnerLoop' {
131150
#
132151
It "FindModuleWithVersionParams" {
133152
AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module ContosoServer -MinimumVersion 1.0 -RequiredVersion 5.0} `
134-
-expectedFullyQualifiedErrorId "VersionRangeAndRequiredVersionCannotBeSpecifiedTogether,Find-Module"
153+
-expectedFullyQualifiedErrorId "VersionRangeAndRequiredVersionCannotBeSpecifiedTogether,Find-Module"
135154
}
136155

137156
# Purpose: Find a module using MinimumVersion
@@ -153,7 +172,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT','InnerLoop' {
153172
#
154173
It "FindModuleWithMinVersionNotAvailable" {
155174
AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module ContosoServer -MinimumVersion 10.0} `
156-
-expectedFullyQualifiedErrorId "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage"
175+
-expectedFullyQualifiedErrorId "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage"
157176
}
158177

159178
# Purpose: FindModuleWithReqVersionNotAvailable
@@ -164,7 +183,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT','InnerLoop' {
164183
#
165184
It "FindModuleWithReqVersionNotAvailable" {
166185
AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module ContosoServer -RequiredVersion 10.0} `
167-
-expectedFullyQualifiedErrorId "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage"
186+
-expectedFullyQualifiedErrorId "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage"
168187
}
169188

170189
# Purpose: FindModuleWithRequiredVersion
@@ -185,8 +204,8 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT','InnerLoop' {
185204
# Expected Result: Should fail with error id
186205
#
187206
It "FindModuleWithMultipleModuleNamesAndReqVersion" {
188-
AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module ContosoServer,ContosoClient -RequiredVersion 1.0} `
189-
-expectedFullyQualifiedErrorId "VersionParametersAreAllowedOnlyWithSingleName,Find-Module"
207+
AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module ContosoServer, ContosoClient -RequiredVersion 1.0} `
208+
-expectedFullyQualifiedErrorId "VersionParametersAreAllowedOnlyWithSingleName,Find-Module"
190209
}
191210

192211
# Purpose: FindModuleWithMultipleModuleNamesAndMinVersion
@@ -196,8 +215,8 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT','InnerLoop' {
196215
# Expected Result: Should fail with error id
197216
#
198217
It "FindModuleWithMultipleModuleNamesAndMinVersion" {
199-
AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module ContosoServer,ContosoClient -MinimumVersion 1.0} `
200-
-expectedFullyQualifiedErrorId "VersionParametersAreAllowedOnlyWithSingleName,Find-Module"
218+
AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module ContosoServer, ContosoClient -MinimumVersion 1.0} `
219+
-expectedFullyQualifiedErrorId "VersionParametersAreAllowedOnlyWithSingleName,Find-Module"
201220
}
202221

203222
# Purpose: FindModuleWithWildcardNameAndReqVersion
@@ -208,7 +227,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT','InnerLoop' {
208227
#
209228
It "FindModuleWithWildcardNameAndReqVersion" {
210229
AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module Contoso*er -RequiredVersion 1.0} `
211-
-expectedFullyQualifiedErrorId "VersionParametersAreAllowedOnlyWithSingleName,Find-Module"
230+
-expectedFullyQualifiedErrorId "VersionParametersAreAllowedOnlyWithSingleName,Find-Module"
212231
}
213232

214233
# Purpose: FindModuleWithWildcardNameAndMinVersion
@@ -219,7 +238,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT','InnerLoop' {
219238
#
220239
It "FindModuleWithWildcardNameAndMinVersion" {
221240
AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module Contoso*er -MinimumVersion 1.0} `
222-
-expectedFullyQualifiedErrorId "VersionParametersAreAllowedOnlyWithSingleName,Find-Module"
241+
-expectedFullyQualifiedErrorId "VersionParametersAreAllowedOnlyWithSingleName,Find-Module"
223242
}
224243

225244
# Purpose: FindModuleWithMultiNames
@@ -229,7 +248,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT','InnerLoop' {
229248
# Expected Result: should find ContosoClient and ContosoServer modules
230249
#
231250
It "FindModuleWithMultiNames" {
232-
$res = Find-Module ContosoClient,ContosoServer -Repository PSGallery
251+
$res = Find-Module ContosoClient, ContosoServer -Repository PSGallery
233252
Assert ($res.Count -eq 2) "Find-Module with multiple names should not fail, $res"
234253
}
235254

@@ -334,7 +353,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT','InnerLoop' {
334353
# Expected Result: Should return two role capabilities
335354
#
336355
It FindRoleCapabilityWithTwoRoleCapabilityNames {
337-
$psgetRoleCapabilityInfos = Find-RoleCapability -Name Lev1Maintenance,Lev2Maintenance
356+
$psgetRoleCapabilityInfos = Find-RoleCapability -Name Lev1Maintenance, Lev2Maintenance
338357

339358
AssertEquals $psgetRoleCapabilityInfos.Count 2 "Find-RoleCapability did not return the expected RoleCapabilities, $psgetRoleCapabilityInfos"
340359

@@ -360,7 +379,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT','InnerLoop' {
360379
# Expected Result: Should return two resources
361380
#
362381
It FindDscResourceWithTwoResourceNames {
363-
$psgetDscResourceInfos = Find-DscResource -Name DscTestResource,NewDscTestResource
382+
$psgetDscResourceInfos = Find-DscResource -Name DscTestResource, NewDscTestResource
364383

365384
Assert ($psgetDscResourceInfos.Count -ge 2) "Find-DscResource did not return the expected DscResources, $psgetDscResourceInfos"
366385

@@ -387,7 +406,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT','InnerLoop' {
387406
# Expected Result: Should return two command names
388407
#
389408
It FindCommandWithTwoResourceNames {
390-
$psgetCommandInfos = Find-Command -Name Get-ContosoServer,Get-ContosoClient
409+
$psgetCommandInfos = Find-Command -Name Get-ContosoServer, Get-ContosoClient
391410

392411
Assert ($psgetCommandInfos.Count -ge 2) "Find-Command did not return the expected command names, $psgetCommandInfos"
393412

@@ -396,7 +415,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT','InnerLoop' {
396415
}
397416
}
398417

399-
Describe PowerShell.PSGet.FindModuleTests.P1 -Tags 'P1','OuterLoop' {
418+
Describe PowerShell.PSGet.FindModuleTests.P1 -Tags 'P1', 'OuterLoop' {
400419

401420
BeforeAll {
402421
SuiteSetup
@@ -458,7 +477,7 @@ Describe PowerShell.PSGet.FindModuleTests.P1 -Tags 'P1','OuterLoop' {
458477
#
459478
It FindModuleWithAllVersionsAndMinimumVersion {
460479
AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module ContosoClient -MinimumVersion 2.0 -Repository PSGallery -AllVersions} `
461-
-expectedFullyQualifiedErrorId 'AllVersionsCannotBeUsedWithOtherVersionParameters,Find-Module'
480+
-expectedFullyQualifiedErrorId 'AllVersionsCannotBeUsedWithOtherVersionParameters,Find-Module'
462481
}
463482

464483
# Purpose: FindModuleWithAllVersionsAndRequiredVersion
@@ -469,7 +488,7 @@ Describe PowerShell.PSGet.FindModuleTests.P1 -Tags 'P1','OuterLoop' {
469488
#
470489
It FindModuleWithAllVersionsAndRequiredVersion {
471490
AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module ContosoClient -RequiredVersion 2.0 -Repository PSGallery -AllVersions} `
472-
-expectedFullyQualifiedErrorId 'AllVersionsCannotBeUsedWithOtherVersionParameters,Find-Module'
491+
-expectedFullyQualifiedErrorId 'AllVersionsCannotBeUsedWithOtherVersionParameters,Find-Module'
473492
}
474493

475494
# Purpose: Validate Find-Module -Filter KeyWordNotExists
@@ -498,7 +517,7 @@ Describe PowerShell.PSGet.FindModuleTests.P1 -Tags 'P1','OuterLoop' {
498517
$DepencyModuleNames = $res1.Dependencies.Name
499518

500519
$res2 = Find-Module -Name $ModuleName -IncludeDependencies -MaximumVersion "1.0" -MinimumVersion "0.1"
501-
Assert ($res2.Count -ge ($DepencyModuleNames.Count+1)) "Find-Module with -IncludeDependencies returned wrong results, $res2"
520+
Assert ($res2.Count -ge ($DepencyModuleNames.Count + 1)) "Find-Module with -IncludeDependencies returned wrong results, $res2"
502521

503522
$DepencyModuleNames | ForEach-Object { Assert ($res2.Name -Contains $_) "Find-Module with -IncludeDependencies didn't return the $_ module, $($res2.Name)"}
504523
}
@@ -507,8 +526,8 @@ Describe PowerShell.PSGet.FindModuleTests.P1 -Tags 'P1','OuterLoop' {
507526
Describe PowerShell.PSGet.FindModuleTests.P2 -Tags 'P2', 'OuterLoop' {
508527

509528
BeforeAll {
510-
if(($PSEdition -eq 'Core') -or ($env:APPVEYOR_TEST_PASS -eq 'True')) {
511-
return
529+
if (($PSEdition -eq 'Core') -or ($env:APPVEYOR_TEST_PASS -eq 'True')) {
530+
return
512531
}
513532

514533
SuiteSetup
@@ -518,8 +537,8 @@ Describe PowerShell.PSGet.FindModuleTests.P2 -Tags 'P2', 'OuterLoop' {
518537
SuiteCleanup
519538
}
520539

521-
if(($PSEdition -eq 'Core') -or ($env:APPVEYOR_TEST_PASS -eq 'True')) {
522-
return
540+
if (($PSEdition -eq 'Core') -or ($env:APPVEYOR_TEST_PASS -eq 'True')) {
541+
return
523542
}
524543

525544
<#
@@ -533,11 +552,10 @@ Describe PowerShell.PSGet.FindModuleTests.P2 -Tags 'P2', 'OuterLoop' {
533552

534553
$ParameterSetCount = $ParameterSets.Count
535554
$i = 1
536-
foreach ($inputParameters in $ParameterSets)
537-
{
555+
foreach ($inputParameters in $ParameterSets) {
538556
Write-Verbose -Message "Combination #$i out of $ParameterSetCount"
539557
Write-Verbose -Message "$($inputParameters | Out-String)"
540-
Write-Progress -Activity "Combination $i out of $ParameterSetCount" -PercentComplete $(($i/$ParameterSetCount) * 100)
558+
Write-Progress -Activity "Combination $i out of $ParameterSetCount" -PercentComplete $(($i / $ParameterSetCount) * 100)
541559

542560
$params = $inputParameters.FindModuleInputParameters
543561
Write-Verbose -Message ($params | Out-String)
@@ -546,25 +564,21 @@ Describe PowerShell.PSGet.FindModuleTests.P2 -Tags 'P2', 'OuterLoop' {
546564

547565
It "FindModuleParameterCombinationsTests - Combination $i/$ParameterSetCount" {
548566

549-
if($inputParameters.PositiveCase)
550-
{
567+
if ($inputParameters.PositiveCase) {
551568
$res = Invoke-Command -ScriptBlock $scriptBlock
552569

553-
if($inputParameters.ExpectedModuleCount -gt 1)
554-
{
570+
if ($inputParameters.ExpectedModuleCount -gt 1) {
555571
Assert ($res.Count -ge $inputParameters.ExpectedModuleCount) "Combination #$i : Find-Module did not return expected module count. Actual value $($res.Count) should be greater than or equal to the expected value $($inputParameters.ExpectedModuleCount)."
556572
}
557-
else
558-
{
573+
else {
559574
AssertEqualsCaseInsensitive $res.Name $inputParameters.ExpectedModuleNames "Combination #$i : Find-Module did not return expected module"
560575
}
561576
}
562-
else
563-
{
577+
else {
564578
AssertFullyQualifiedErrorIdEquals -Scriptblock $scriptBlock -ExpectedFullyQualifiedErrorId $inputParameters.FullyQualifiedErrorId
565579
}
566580
}
567581

568-
$i = $i+1
569-
}
582+
$i = $i + 1
583+
}
570584
}

0 commit comments

Comments
 (0)