Skip to content

Commit 472a94f

Browse files
committed
minor formatting, logic, and test updates
1 parent 448038d commit 472a94f

3 files changed

Lines changed: 15 additions & 15 deletions

File tree

DSCResources/DSR_KeyValuePairFile/DSR_KeyValuePairFile.psm1

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ function Set-TargetResource
228228
{
229229
$fileProperties.Add('Encoding', $Encoding)
230230
}
231+
231232
if ($results.Count -eq 0)
232233
{
233234
# The key value pair was not found so add it to the end of the file
@@ -248,27 +249,24 @@ function Set-TargetResource
248249

249250
Write-Verbose -Message ($localizedData.KeyUpdateMessage -f `
250251
$Path, $Name)
251-
}#> # if
252+
} # if
252253
}
253254
else
254255
{
255256
if ($results.Count -eq 0)
256257
{
257-
if ($PSBoundParameters.ContainsKey('Encoding'))
258+
if ($PSBoundParameters.ContainsKey('Encoding') -and ($Encoding -eq $fileEncoding))
258259
{
259-
if ($Encoding -eq $fileEncoding)
260-
{
261260
# The Key does not exists and should not, and encoding is in the desired state, so don't do anything
262261
return
263-
}
264-
else
265-
{
266-
Write-Verbose -Message ($localizedData.FileEncodingNotInDesiredState -f `
267-
$fileEncoding, $Encoding)
268-
269-
# Add encoding parameter and value to the hashtable
270-
$fileProperties.add('Encoding', $Encoding)
271-
}
262+
}
263+
else
264+
{
265+
Write-Verbose -Message ($localizedData.FileEncodingNotInDesiredState -f `
266+
$fileEncoding, $Encoding)
267+
268+
# Add encoding parameter and value to the hashtable
269+
$fileProperties.add('Encoding', $Encoding)
272270
}
273271
}
274272
else

Tests/Integration/DSR_KeyValuePairFile.Integration.Tests.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCR
1616

1717
Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force
1818
Import-Module (Join-Path -Path $script:moduleRoot -ChildPath "$($script:DSCModuleName).psd1") -Force
19+
# Import the helper module for the Get-FileEncoding function
1920
Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'Modules\FileContentDsc.Common') -Force
2021
$TestEnvironment = Initialize-TestEnvironment `
2122
-DSCModuleName $script:DSCModuleName `

Tests/Unit/DSR_KeyValuePairFile.Tests.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ $($script:testAddedName)=$($script:testText)
520520
{ Set-TargetResource `
521521
-Path $script:testTextFile `
522522
-Name $script:testName.ToUpper() `
523+
-Encoding $script:fileEncodingParameters.Encoding `
523524
-Ensure 'Absent' `
524525
-Verbose
525526
} | Should -Not -Throw
@@ -536,7 +537,7 @@ $($script:testAddedName)=$($script:testText)
536537

537538
Assert-MockCalled `
538539
-CommandName Set-Content `
539-
-Exactly 1
540+
-Exactly 0
540541
}
541542
}
542543

@@ -650,7 +651,7 @@ $($script:testAddedName)=$($script:testText)
650651
}
651652
}
652653

653-
Context 'File exists and does not contain matching key but should not' {
654+
Context 'File exists and does not contain matching key and should not' {
654655
# verifiable (should be called) mocks
655656
Mock `
656657
-CommandName Assert-ParametersValid `

0 commit comments

Comments
 (0)