Skip to content
This repository was archived by the owner on Jun 14, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function Get-TargetResource

$getWindowsPackageParams = @{
PackageName = $Name
Online = $true
Online = [switch]::Present
}

if ($PSBoundParameters.ContainsKey('LogPath'))
Expand Down Expand Up @@ -141,16 +141,26 @@ function Set-TargetResource
{
New-InvalidArgumentException -ArgumentName 'SourcePath' -Message ($script:localizedData.SourcePathDoesNotExist -f $SourcePath)
}

$setTargetResourceParams = @{
PackagePath = $SourcePath
Online = [switch]::Present
}

if ($PSBoundParameters.ContainsKey('LogPath'))
{
$setTargetResourceParams['LogPath'] = $LogPath
}

if ($Ensure -ieq 'Present')
{
Write-Verbose -Message ($script:localizedData.AddingPackage -f $SourcePath)
Dism\Add-WindowsPackage -PackagePath $SourcePath -LogPath $LogPath -Online
Dism\Add-WindowsPackage @setTargetResourceParams
}
else
{
Write-Verbose -Message ($script:localizedData.RemovingPackage -f $SourcePath)
Dism\Remove-WindowsPackage -PackagePath $SourcePath -LogPath $LogPath -Online
Dism\Remove-WindowsPackage @setTargetResourceParams
}

Write-Verbose -Message ($script:localizedData.SetTargetResourceFinished -f $Name)
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,9 @@ The following parameters will be the same for each process in the set:

### Unreleased

* WindowsPackageCab
* Made the LogPath parameter optional as it is supposed to be.

### 2.9.0.0

* Added Description and Parameter description for composite resources
Expand Down
8 changes: 6 additions & 2 deletions Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ try
$null = Get-TargetResource -Name $script:testPackageName -LogPath $script:testLogPath @getTargetResourceCommonParams
Assert-MockCalled -CommandName 'Dism\Get-WindowsPackage' -ParameterFilter { $LogPath -eq $script:testLogPath }
}
It 'Should return an empty log path when it was not specified' {
$getTargetResourceResult = Get-TargetResource -Name $script:testPackageName @getTargetResourceCommonParams
$getTargetResourceResult.LogPath | Should be ''
}
}

Context 'Set-TargetResource' {
Expand All @@ -84,12 +88,12 @@ try

It 'Should call Add-WindowsPackage when Ensure is Present' {
Set-TargetResource -Name $script:testPackageName -SourcePath $script:testSourcePath -Ensure 'Present'
Assert-MockCalled -CommandName 'Dism\Add-WindowsPackage'
Assert-MockCalled -CommandName 'Dism\Add-WindowsPackage' -ParameterFilter { $null -eq $LogPath }
}

It 'Should call Remove-WindowsPackage when Ensure is Absent' {
Set-TargetResource -Name $script:testPackageName -SourcePath $script:testSourcePath -Ensure 'Absent'
Assert-MockCalled -CommandName 'Dism\Remove-WindowsPackage'
Assert-MockCalled -CommandName 'Dism\Remove-WindowsPackage' -ParameterFilter { $null -eq $LogPath }
}

It 'Should pass specified log path to Add-WindowsPackage' {
Expand Down