Skip to content

Commit 844d36f

Browse files
Implementation complete with tests passing
1 parent bd5a4b9 commit 844d36f

File tree

3 files changed

+26
-32
lines changed

3 files changed

+26
-32
lines changed

src/dsc/psresourceget.ps1

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -467,35 +467,6 @@ function ExportOperation {
467467
}
468468
}
469469

470-
filter Where-PSResource {
471-
param(
472-
[string]$name,
473-
[string]$version,
474-
[Scope]$scope,
475-
[string]$repositoryName
476-
)
477-
478-
process {
479-
$nameMatch = if ($name) { $_.Name -eq $name } else { $true }
480-
$versionMatch = if ($_.Version) {
481-
try {
482-
SatisfiesVersion -version $_.Version -versionRange $version
483-
}
484-
catch {
485-
$_.Version.ToString() -eq $version
486-
}
487-
}
488-
else { $true }
489-
$scopeMatch = if ($_.Scope) { $_.Scope -eq $scope } else { $true }
490-
$repositoryMatch = if ($_.Repository) { $_.Repository -eq $repositoryName } else { $true }
491-
492-
if ($nameMatch -and $versionMatch -and $scopeMatch -and $repositoryMatch) {
493-
Write-Trace -message "Resource matches filter criteria: Name=$($_.Name), Version=$($_.Version), Scope=$($_.Scope), Repository=$($_.Repository)" -level trace
494-
$_
495-
}
496-
}
497-
}
498-
499470
function SetPSResourceList {
500471
param(
501472
$inputObj
@@ -516,7 +487,7 @@ function SetPSResourceList {
516487
$scope = if ($resourceDesiredState.scope) { $resourceDesiredState.scope } else { "CurrentUser" }
517488

518489
# Resource should not exist - uninstall if it does
519-
$currentState.resources | Where-PSResource -name $name -version $version -scope $scope -repositoryName $repositoryName | ForEach-Object {
490+
$currentState.resources | ForEach-Object {
520491

521492
$isInDesiredState = $_.IsInDesiredState($resourceDesiredState)
522493

@@ -564,7 +535,8 @@ function SetPSResourceList {
564535

565536
Write-Trace -message "Installing resources: $($resourcesToInstall.Values | ForEach-Object { " $($_.Name) -- $($_.Version) " })"
566537
$resourcesToInstall.Values | ForEach-Object {
567-
Install-PSResource -Name $_.Name -Version $_.Version -Scope $scope -Repository $repositoryName -ErrorAction Stop -TrustRepository:$inputObj.trustedRepository
538+
$usePrerelease = if ($_.preRelease) { $true } else { $false }
539+
Install-PSResource -Name $_.Name -Version $_.Version -Scope $scope -Repository $repositoryName -ErrorAction Stop -TrustRepository:$inputObj.trustedRepository -Prerelease:$usePrerelease -Reinstall
568540
}
569541

570542
$resourcesChanged = $true

test/DscResource/PSResourceGetDSCResource.Tests.ps1

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,4 +387,25 @@ Describe 'E2E tests for PSResourceList resource' -Tags 'CI' {
387387
$version | Should -BeIn @("101.0.99.beta1", "0.0.93")
388388
}
389389
}
390+
391+
It 'Can install modules with one existing other not' {
392+
$mod = Get-PSResource -Name 'testmodule99' -ErrorAction SilentlyContinue
393+
if ($mod) {
394+
$mod | Uninstall-PSResource -ErrorAction SilentlyContinue
395+
}
396+
397+
Install-PSResource -Name 'testmodule99' -ErrorAction SilentlyContinue -Repository PSGallery -Reinstall -TrustRepository -Version '0.0.93'
398+
399+
$configPath = Join-Path -Path $PSScriptRoot -ChildPath 'configs/psresourcegetlist.oneexisting.install.dsc.yaml'
400+
& $script:dscExe config set -f $configPath
401+
402+
$psresource = Get-PSResource -Name 'testmodule99' -ErrorAction SilentlyContinue
403+
$psresource | Should -HaveCount 2
404+
405+
$psresource | ForEach-Object {
406+
$version = if ($_.prerelease) { "$($_.Version)" + '.' + "$($_.PreRelease)" } else { $_.Version.ToString() }
407+
408+
$version | Should -BeIn @("101.0.99.beta1", "0.0.93")
409+
}
410+
}
390411
}

test/DscResource/configs/psresourcegetlist.prerelease.install.dsc.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ resources:
99
- name: testmodule99
1010
version: '[[0.0.93,)'
1111
_exist: true
12-
preRelease: true
12+
preRelease: false
1313
- name: testmodule99
1414
version: '[[100.0.99,)'
1515
_exist: true
1616
preRelease: true
17+

0 commit comments

Comments
 (0)