From 8dfbdc2bcb10e97739f51ed4ee13906e5595f614 Mon Sep 17 00:00:00 2001 From: Jimmy Bartlett Date: Mon, 27 Jul 2020 18:51:46 -0700 Subject: [PATCH 1/4] Ensure empty array output is not enumerated prematurely. --- CHANGELOG.md | 3 +++ .../MSFT_WindowsOptionalFeature.psm1 | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc3d3d39..12a38055 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +* Proposed fix for WindowsOptionalFeature DSC Resource GET method when the OptionalFeature has no Custom Properties. + [Issue #191](https://github.com/PowerShell/PSDscResources/issues/191) + ## 2.12.0.0 * Ports style fixes that were recently made in xPSDesiredStateConfiguration diff --git a/DscResources/MSFT_WindowsOptionalFeature/MSFT_WindowsOptionalFeature.psm1 b/DscResources/MSFT_WindowsOptionalFeature/MSFT_WindowsOptionalFeature.psm1 index d9d7d705..8c44ba6b 100644 --- a/DscResources/MSFT_WindowsOptionalFeature/MSFT_WindowsOptionalFeature.psm1 +++ b/DscResources/MSFT_WindowsOptionalFeature/MSFT_WindowsOptionalFeature.psm1 @@ -330,7 +330,7 @@ function Convert-CustomPropertyArrayToStringArray } } - return $propertiesAsStrings + Write-Output $propertiesAsStrings -NoEnumerate } <# From a7a903a77582c9ba7e712f8594cf39d52ecd4a3e Mon Sep 17 00:00:00 2001 From: Jimmy Bartlett Date: Mon, 27 Jul 2020 18:52:13 -0700 Subject: [PATCH 2/4] Added unit test --- Tests/Unit/MSFT_WindowsOptionalFeature.Tests.ps1 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Tests/Unit/MSFT_WindowsOptionalFeature.Tests.ps1 b/Tests/Unit/MSFT_WindowsOptionalFeature.Tests.ps1 index 27775394..728f91e7 100644 --- a/Tests/Unit/MSFT_WindowsOptionalFeature.Tests.ps1 +++ b/Tests/Unit/MSFT_WindowsOptionalFeature.Tests.ps1 @@ -317,6 +317,10 @@ try $propertiesAsStrings.Contains("Name = Object $objectNumber, Value = Value $objectNumber, Path = Path $objectNumber") | Should -BeTrue } } + + It 'Should return an empty array and not a null object when input is empty' { + $propertiesAsStrings = (Convert-CustomPropertyArrayToStringArray -CustomProperties @()) -is [String[]] | Should -BeTrue + } } } } From c6323a494ad47ba14ab82435451f58c70ccefdf8 Mon Sep 17 00:00:00 2001 From: Jimmy Bartlett Date: Tue, 28 Jul 2020 10:03:23 -0700 Subject: [PATCH 3/4] Removed unneeded variable assignment in unit test. --- Tests/Unit/MSFT_WindowsOptionalFeature.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Unit/MSFT_WindowsOptionalFeature.Tests.ps1 b/Tests/Unit/MSFT_WindowsOptionalFeature.Tests.ps1 index 728f91e7..402f55e1 100644 --- a/Tests/Unit/MSFT_WindowsOptionalFeature.Tests.ps1 +++ b/Tests/Unit/MSFT_WindowsOptionalFeature.Tests.ps1 @@ -319,7 +319,7 @@ try } It 'Should return an empty array and not a null object when input is empty' { - $propertiesAsStrings = (Convert-CustomPropertyArrayToStringArray -CustomProperties @()) -is [String[]] | Should -BeTrue + (Convert-CustomPropertyArrayToStringArray -CustomProperties @()) -is [String[]] | Should -BeTrue } } } From bc54ae499a5870baca2a048e5e65075e2b9788dd Mon Sep 17 00:00:00 2001 From: Jimmy Bartlett Date: Tue, 16 Mar 2021 17:15:06 -0700 Subject: [PATCH 4/4] Updated Unit test description. --- Tests/Unit/MSFT_WindowsOptionalFeature.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Unit/MSFT_WindowsOptionalFeature.Tests.ps1 b/Tests/Unit/MSFT_WindowsOptionalFeature.Tests.ps1 index 402f55e1..d5e844e6 100644 --- a/Tests/Unit/MSFT_WindowsOptionalFeature.Tests.ps1 +++ b/Tests/Unit/MSFT_WindowsOptionalFeature.Tests.ps1 @@ -318,7 +318,7 @@ try } } - It 'Should return an empty array and not a null object when input is empty' { + It 'Should return an empty array and not a null object when input is an empty array' { (Convert-CustomPropertyArrayToStringArray -CustomProperties @()) -is [String[]] | Should -BeTrue } }