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

Fix for issue #109 #110

Open
wants to merge 16 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
18 changes: 14 additions & 4 deletions DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ function Get-TargetResource
Name = $Name
Ensure = 'Present'
SourcePath = $SourcePath
LogPath = $LogPath
}

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

if ($PSBoundParameters.ContainsKey('LogPath'))
{
$getWindowsPackageParams['LogPath'] = $LogPath
$windowsPackageCab['LogPath'] = $LogPath
p0w3rsh3ll marked this conversation as resolved.
Show resolved Hide resolved
}

Write-Verbose -Message ($script:localizedData.RetrievingPackage -f $Name)
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
11 changes: 11 additions & 0 deletions Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ try
$null = Get-TargetResource -Name $script:testPackageName -LogPath $script:testLogPath @getTargetResourceCommonParams
Assert-MockCalled -CommandName 'Dism\Get-WindowsPackage' -ParameterFilter { $LogPath -eq $script:testLogPath }
}
It 'Should not return a log path when it was not specified' {
$null -eq (Get-TargetResource -Name $script:testPackageName @getTargetResourceCommonParams)['LogPath'] | Should be $true
}
}

Context 'Set-TargetResource' {
Expand Down Expand Up @@ -101,6 +104,14 @@ try
Set-TargetResource -Name $script:testPackageName -SourcePath $script:testSourcePath -Ensure 'Absent' -LogPath $script:testLogPath
Assert-MockCalled -CommandName 'Dism\Remove-WindowsPackage' -ParameterFilter { $LogPath -eq $script:testLogPath }
}
It 'Should not throw when a log path is not specified to Remove-WindowsPackage' {
p0w3rsh3ll marked this conversation as resolved.
Show resolved Hide resolved
Set-TargetResource -Name $script:testPackageName -SourcePath $script:testSourcePath -Ensure 'Absent'
Assert-MockCalled -CommandName 'Dism\Remove-WindowsPackage' -ParameterFilter { $null -eq $LogPath }
}
It 'Should not throw when a log path is not specified to Add-WindowsPackage' {
Set-TargetResource -Name $script:testPackageName -SourcePath $script:testSourcePath -Ensure 'Present'
Assert-MockCalled -CommandName 'Dism\Add-WindowsPackage' -ParameterFilter { $null -eq $LogPath }
}
}

Context 'Test-TargetResource' {
Expand Down