From 446a9c8e6f8b72f486c1033786f4da25712bbade Mon Sep 17 00:00:00 2001 From: p0w3rsh3ll Date: Fri, 6 Jul 2018 19:11:08 +0200 Subject: [PATCH 01/13] Update MSFT_WindowsPackageCab.psm1 --- .../MSFT_WindowsPackageCab.psm1 | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.psm1 b/DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.psm1 index a4e49c7..09c0b9a 100644 --- a/DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.psm1 +++ b/DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.psm1 @@ -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 } Write-Verbose -Message ($script:localizedData.RetrievingPackage -f $Name) @@ -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) From bc876b2c0064ead4f20078485698ee77fecc682d Mon Sep 17 00:00:00 2001 From: p0w3rsh3ll Date: Sun, 29 Jul 2018 13:08:35 +0200 Subject: [PATCH 02/13] Update MSFT_WindowsPackageCab.Tests.ps1 Test change made to Get-TargetResource on line 60 and 70 --- Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 b/Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 index 9e899f9..27808b6 100644 --- a/Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 +++ b/Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 @@ -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' { From 73477fa6c3cc18088e09247cb90aebb94ecdcf01 Mon Sep 17 00:00:00 2001 From: p0w3rsh3ll Date: Sun, 29 Jul 2018 13:12:48 +0200 Subject: [PATCH 03/13] Update MSFT_WindowsPackageCab.Tests.ps1 Test changes made to Set-TargetResource --- Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 b/Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 index 27808b6..7e01f9f 100644 --- a/Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 +++ b/Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 @@ -104,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' { + 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' { From df1a971cfecc966de88944af870508f4f4455a13 Mon Sep 17 00:00:00 2001 From: p0w3rsh3ll Date: Sun, 29 Jul 2018 13:19:37 +0200 Subject: [PATCH 04/13] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index b0f2a6d..7214149 100644 --- a/README.md +++ b/README.md @@ -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 From ebcc5c7aade720f35cfecb5e6e4fb4476e210ca2 Mon Sep 17 00:00:00 2001 From: p0w3rsh3ll Date: Tue, 28 Aug 2018 11:13:45 +0200 Subject: [PATCH 05/13] Update MSFT_WindowsPackageCab.psm1 Restore the previously deleted LogPath property in the initialized $windowsPackageCab variable returned by the Get-TargetResource function. Update it with the value of the $windowsPackageInfo variable that is the object returned by the dism cmdlet when it succeeds. --- DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.psm1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.psm1 b/DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.psm1 index 09c0b9a..ab127bc 100644 --- a/DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.psm1 +++ b/DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.psm1 @@ -57,6 +57,7 @@ function Get-TargetResource Name = $Name Ensure = 'Present' SourcePath = $SourcePath + LogPath = $LogPath } $getWindowsPackageParams = @{ @@ -75,6 +76,7 @@ function Get-TargetResource try { $windowsPackageInfo = Dism\Get-WindowsPackage @getWindowsPackageParams + $windowsPackageCab['LogPath'] = $windowsPackageInfo.LogPath } catch { From fcbb60c334d6fbcfeefbdda056ba630970065b5e Mon Sep 17 00:00:00 2001 From: p0w3rsh3ll Date: Fri, 31 Aug 2018 11:36:11 +0200 Subject: [PATCH 06/13] Update MSFT_WindowsPackageCab.psm1 Based on my testing last night, this is the line that made tests fail unexpectedly. --- DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.psm1 | 1 - 1 file changed, 1 deletion(-) diff --git a/DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.psm1 b/DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.psm1 index ab127bc..7bcd0d5 100644 --- a/DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.psm1 +++ b/DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.psm1 @@ -76,7 +76,6 @@ function Get-TargetResource try { $windowsPackageInfo = Dism\Get-WindowsPackage @getWindowsPackageParams - $windowsPackageCab['LogPath'] = $windowsPackageInfo.LogPath } catch { From 67f48d106e2845661acd09f1024e171270867602 Mon Sep 17 00:00:00 2001 From: p0w3rsh3ll Date: Fri, 31 Aug 2018 11:40:29 +0200 Subject: [PATCH 07/13] Update MSFT_WindowsPackageCab.Tests.ps1 Updating tests. Make sure there's a logpath in the hashtable returned by the `Get-TargetResource` when a logpath wasn't specified. --- Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 b/Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 index 7e01f9f..9628098 100644 --- a/Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 +++ b/Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 @@ -70,8 +70,8 @@ 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 + It 'Should return an empty log path when it was not specified' { + (Get-TargetResource -Name $script:testPackageName @getTargetResourceCommonParams)['LogPath'] -eq [string]::Empty| Should be $true } } From 78085b5d9154818109aa0bf335d3996695c8f288 Mon Sep 17 00:00:00 2001 From: p0w3rsh3ll Date: Thu, 6 Sep 2018 13:43:37 +0200 Subject: [PATCH 08/13] Update MSFT_WindowsPackageCab.psm1 Line not needed anymore as line 60 was restored --- DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.psm1 | 1 - 1 file changed, 1 deletion(-) diff --git a/DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.psm1 b/DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.psm1 index 7bcd0d5..c9bb236 100644 --- a/DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.psm1 +++ b/DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.psm1 @@ -68,7 +68,6 @@ function Get-TargetResource if ($PSBoundParameters.ContainsKey('LogPath')) { $getWindowsPackageParams['LogPath'] = $LogPath - $windowsPackageCab['LogPath'] = $LogPath } Write-Verbose -Message ($script:localizedData.RetrievingPackage -f $Name) From 772c0f20ac527f8f3119c8cc30d4596e0b99eaab Mon Sep 17 00:00:00 2001 From: p0w3rsh3ll Date: Thu, 6 Sep 2018 13:52:46 +0200 Subject: [PATCH 09/13] Update MSFT_WindowsPackageCab.Tests.ps1 - Matching the format on lines 74-75. - Adding parameter filter in already existing tests rather than adding new tests --- Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 b/Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 index 9628098..09bb15b 100644 --- a/Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 +++ b/Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 @@ -71,7 +71,8 @@ try Assert-MockCalled -CommandName 'Dism\Get-WindowsPackage' -ParameterFilter { $LogPath -eq $script:testLogPath } } It 'Should return an empty log path when it was not specified' { - (Get-TargetResource -Name $script:testPackageName @getTargetResourceCommonParams)['LogPath'] -eq [string]::Empty| Should be $true + $getTargetResourceResult = Get-TargetResource -Name $script:testPackageName @getTargetResourceCommonParams + $getTargetResourceResult.LogPath | Should be [string]::Empty } } @@ -87,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' { @@ -104,14 +105,6 @@ 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' { - 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' { From 1d8fbe9a808b0ac5383d9fb59402106eb0bf1595 Mon Sep 17 00:00:00 2001 From: p0w3rsh3ll Date: Thu, 6 Sep 2018 14:28:37 +0200 Subject: [PATCH 10/13] Update MSFT_WindowsPackageCab.Tests.ps1 fix failing test --- Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 b/Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 index 09bb15b..1b4513b 100644 --- a/Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 +++ b/Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 @@ -72,7 +72,7 @@ try } It 'Should return an empty log path when it was not specified' { $getTargetResourceResult = Get-TargetResource -Name $script:testPackageName @getTargetResourceCommonParams - $getTargetResourceResult.LogPath | Should be [string]::Empty + $getTargetResourceResult.LogPath | Should be '' } } From be80d32c0ec60d5b4e11a4da861b2a01f7827827 Mon Sep 17 00:00:00 2001 From: p0w3rsh3ll Date: Fri, 8 Feb 2019 13:45:57 +0100 Subject: [PATCH 11/13] Update MSFT_WindowsPackageCab.psm1 Trim in GH, not in VSCode :( --- DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.psm1 b/DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.psm1 index c9bb236..6be455b 100644 --- a/DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.psm1 +++ b/DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.psm1 @@ -151,7 +151,7 @@ function Set-TargetResource { $setTargetResourceParams['LogPath'] = $LogPath } - + if ($Ensure -ieq 'Present') { Write-Verbose -Message ($script:localizedData.AddingPackage -f $SourcePath) From 84a1b634d4759da10d23c3f866187f6ef1f969cf Mon Sep 17 00:00:00 2001 From: p0w3rsh3ll Date: Fri, 8 Feb 2019 13:55:27 +0100 Subject: [PATCH 12/13] Update MSFT_WindowsPackageCab.Tests.ps1 Add a linefeed. The test on line 74 is to check that Get-TargetResource returns an empty 'LogPath' when the LogPath parameter has not been used and passed to Get-TargetResource. --- Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 b/Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 index 1b4513b..33bac99 100644 --- a/Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 +++ b/Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 @@ -70,6 +70,7 @@ 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 '' From 9287bd0112df32e72dff7f306b940eee3c2a4dc8 Mon Sep 17 00:00:00 2001 From: p0w3rsh3ll Date: Mon, 25 Feb 2019 13:34:07 +0100 Subject: [PATCH 13/13] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index f7eef76..f05e2ea 100644 --- a/README.md +++ b/README.md @@ -583,7 +583,6 @@ The following parameters will be the same for each process in the set: ### 2.10.0.0 * Fixed CompanyName typo - Fixes [Issue #100](https://github.com/PowerShell/PSDscResources/issues/100) - * Update LICENSE file to match the Microsoft Open Source Team standard - Fixes [Issue #120](https://github.com/PowerShell/PSDscResources/issues/120). * Update `CommonResourceHelper` unit tests to meet Pester 4.0.0