Skip to content

Commit 917736e

Browse files
committed
Fix integration tests
1 parent ee63ca1 commit 917736e

File tree

4 files changed

+60
-11
lines changed

4 files changed

+60
-11
lines changed

source/Modules/FileContentDsc.Common/FileContentDsc.Common.psm1

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ function Get-TextEolCharacter
5151
{
5252
[CmdletBinding()]
5353
[OutputType([System.String])]
54-
param (
54+
param
55+
(
5556
[Parameter(Mandatory = $true)]
5657
[System.String]
5758
$Text
@@ -86,7 +87,8 @@ function Get-TextEolCharacter
8687
function Set-IniSettingFileValue
8788
{
8889
[CmdletBinding()]
89-
param (
90+
param
91+
(
9092
[Parameter(Mandatory = $true)]
9193
[System.String]
9294
$Path,
@@ -125,7 +127,8 @@ function Get-IniSettingFileValue
125127
{
126128
[CmdletBinding()]
127129
[OutputType([System.String])]
128-
param (
130+
param
131+
(
129132
[Parameter(Mandatory = $true)]
130133
[System.String]
131134
$Path,

tests/Integration/DSC_KeyValuePairFile.Integration.Tests.ps1

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ $script:testEnvironment = Initialize-TestEnvironment `
2121

2222
Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1')
2323

24-
# Helper module import required for the Get-FileEncoding function
25-
Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\..\source\Modules\FileContentDsc.Common') -Force
26-
2724
try
2825
{
2926
Describe "$($script:dscResourceName)_Integration" {

tests/Integration/DSC_ReplaceText.Integration.Tests.ps1

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ $script:testEnvironment = Initialize-TestEnvironment `
2121

2222
Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1')
2323

24-
# Helper module import required for the Get-FileEncoding function
25-
Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\..\source\Modules\FileContentDsc.Common') -Force
26-
2724
try
2825
{
2926
Describe "$($script:dscResourceName)_Integration" {

tests/TestHelpers/CommonTestHelper.psm1

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,59 @@ function Get-InvalidOperationRecord
8181
return New-Object @newObjectParams
8282
}
8383

84+
<#
85+
.SYNOPSIS
86+
Gets file encoding. Defaults to ASCII.
87+
88+
.DESCRIPTION
89+
The Get-FileEncoding function determines encoding by looking at Byte Order Mark (BOM).
90+
Based on port of C# code from http://www.west-wind.com/Weblog/posts/197245.aspx
91+
92+
.EXAMPLE
93+
Get-ChildItem *.ps1 | select FullName, @{n='Encoding';e={Get-FileEncoding $_.FullName}} | where {$_.Encoding -ne 'ASCII'}
94+
This command gets ps1 files in current directory where encoding is not ASCII
95+
96+
.EXAMPLE
97+
Get-ChildItem *.ps1 | select FullName, @{n='Encoding';e={Get-FileEncoding $_.FullName}} | where {$_.Encoding -ne 'ASCII'} | `
98+
foreach {(get-content $_.FullName) | set-content $_.FullName -Encoding ASCII}
99+
Same as previous example but fixes encoding using set-content
100+
#>
101+
function Get-FileEncoding
102+
{
103+
[CmdletBinding()]
104+
[OutputType([System.String])]
105+
param
106+
(
107+
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
108+
[System.String]
109+
$Path
110+
)
111+
112+
[System.Byte[]] $byte = Get-Content -Encoding byte -ReadCount 4 -TotalCount 4 -Path $Path
113+
114+
if ($byte[0] -eq 0xef -and $byte[1] -eq 0xbb -and $byte[2] -eq 0xbf)
115+
{
116+
return 'UTF8'
117+
}
118+
elseif ($byte[0] -eq 0xff -and $byte[1] -eq 0xfe)
119+
{
120+
return 'UTF32'
121+
}
122+
elseif ($byte[0] -eq 0xfe -and $byte[1] -eq 0xff)
123+
{
124+
return 'BigEndianUnicode'
125+
}
126+
elseif ($byte[0] -eq 0 -and $byte[1] -eq 0 -and $byte[2] -eq 0xfe -and $byte[3] -eq 0xff)
127+
{
128+
return 'BigEndianUTF32'
129+
}
130+
else
131+
{
132+
return 'ASCII'
133+
}
134+
}
135+
84136
Export-ModuleMember -Function `
85137
'Get-InvalidArgumentRecord', `
86-
'Get-InvalidOperationRecord'
87-
138+
'Get-InvalidOperationRecord', `
139+
'Get-FileEncoding'

0 commit comments

Comments
 (0)