Skip to content

Commit

Permalink
Fix integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PlagueHO committed Jul 4, 2020
1 parent ee63ca1 commit 917736e
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ function Get-TextEolCharacter
{
[CmdletBinding()]
[OutputType([System.String])]
param (
param
(
[Parameter(Mandatory = $true)]
[System.String]
$Text
Expand Down Expand Up @@ -86,7 +87,8 @@ function Get-TextEolCharacter
function Set-IniSettingFileValue
{
[CmdletBinding()]
param (
param
(
[Parameter(Mandatory = $true)]
[System.String]
$Path,
Expand Down Expand Up @@ -125,7 +127,8 @@ function Get-IniSettingFileValue
{
[CmdletBinding()]
[OutputType([System.String])]
param (
param
(
[Parameter(Mandatory = $true)]
[System.String]
$Path,
Expand Down
3 changes: 0 additions & 3 deletions tests/Integration/DSC_KeyValuePairFile.Integration.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ $script:testEnvironment = Initialize-TestEnvironment `

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

# Helper module import required for the Get-FileEncoding function
Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\..\source\Modules\FileContentDsc.Common') -Force

try
{
Describe "$($script:dscResourceName)_Integration" {
Expand Down
3 changes: 0 additions & 3 deletions tests/Integration/DSC_ReplaceText.Integration.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ $script:testEnvironment = Initialize-TestEnvironment `

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

# Helper module import required for the Get-FileEncoding function
Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\..\source\Modules\FileContentDsc.Common') -Force

try
{
Describe "$($script:dscResourceName)_Integration" {
Expand Down
56 changes: 54 additions & 2 deletions tests/TestHelpers/CommonTestHelper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,59 @@ function Get-InvalidOperationRecord
return New-Object @newObjectParams
}

<#
.SYNOPSIS
Gets file encoding. Defaults to ASCII.
.DESCRIPTION
The Get-FileEncoding function determines encoding by looking at Byte Order Mark (BOM).
Based on port of C# code from http://www.west-wind.com/Weblog/posts/197245.aspx
.EXAMPLE
Get-ChildItem *.ps1 | select FullName, @{n='Encoding';e={Get-FileEncoding $_.FullName}} | where {$_.Encoding -ne 'ASCII'}
This command gets ps1 files in current directory where encoding is not ASCII
.EXAMPLE
Get-ChildItem *.ps1 | select FullName, @{n='Encoding';e={Get-FileEncoding $_.FullName}} | where {$_.Encoding -ne 'ASCII'} | `
foreach {(get-content $_.FullName) | set-content $_.FullName -Encoding ASCII}
Same as previous example but fixes encoding using set-content
#>
function Get-FileEncoding
{
[CmdletBinding()]
[OutputType([System.String])]
param
(
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
[System.String]
$Path
)

[System.Byte[]] $byte = Get-Content -Encoding byte -ReadCount 4 -TotalCount 4 -Path $Path

if ($byte[0] -eq 0xef -and $byte[1] -eq 0xbb -and $byte[2] -eq 0xbf)
{
return 'UTF8'
}
elseif ($byte[0] -eq 0xff -and $byte[1] -eq 0xfe)
{
return 'UTF32'
}
elseif ($byte[0] -eq 0xfe -and $byte[1] -eq 0xff)
{
return 'BigEndianUnicode'
}
elseif ($byte[0] -eq 0 -and $byte[1] -eq 0 -and $byte[2] -eq 0xfe -and $byte[3] -eq 0xff)
{
return 'BigEndianUTF32'
}
else
{
return 'ASCII'
}
}

Export-ModuleMember -Function `
'Get-InvalidArgumentRecord', `
'Get-InvalidOperationRecord'

'Get-InvalidOperationRecord', `
'Get-FileEncoding'

0 comments on commit 917736e

Please sign in to comment.