ps/Modules/Alkami.PowerShell.Common/Public/ConvertTo-SafeTeamCityMessage.tests.ps1
2023-05-30 22:51:22 -07:00

93 lines
2.8 KiB
PowerShell
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

. $PSScriptRoot\..\..\Load-PesterModules.ps1
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.tests\.', '.'
$functionPath = Join-Path -Path $here -ChildPath $sut
Write-Host "Overriding SUT: $functionPath"
Import-Module $functionPath -Force
$moduleForMock = ""
Describe "ConvertTo-SafeTeamCityMessage" {
Context "When Provided With Non-Newline Characters" {
It "Should Properly Sanitize |" {
$testString = "I have a | pipe"
$resultString = ConvertTo-SafeTeamCityMessage $testString
$resultString | Should -Match "\|\|"
}
It "Should Properly Sanitize '" {
$testString = "I have an ' apostrophe"
$resultString = ConvertTo-SafeTeamCityMessage $testString
$resultString | Should -Match "`|'"
}
It "Should Properly Sanitize " {
$testString = "I have a *fancy* apostrophe"
$resultString = ConvertTo-SafeTeamCityMessage $testString
$resultString | Should -Match "`|"
}
It "Should Properly Sanitize [" {
$testString = "I have a left [ bracket"
$resultString = ConvertTo-SafeTeamCityMessage $testString
# Powershell wants the ` for the |, regex wants the \ for the [... Rage.
$resultString | Should -Match "`|\["
}
It "Should Properly Sanitize ]" {
$testString = "I have a right ] bracket"
$resultString = ConvertTo-SafeTeamCityMessage $testString
$resultString | Should -Match "`|]"
}
}
Context "When Provided With a Newline Charater" {
It "Should Properly Sanitize ``n" {
$testString = "I have an
end line"
$resultString = ConvertTo-SafeTeamCityMessage $testString
$resultString | Should -Match "`\|n"
}
}
Context "When Provided With a Character Return Character" {
It "Should Properly Sanitize ``r" {
$testString = "I have a character `r return"
$resultString = ConvertTo-SafeTeamCityMessage $testString
$resultString | Should -Match "`\|r"
}
}
Context "When Provided With a String Which Doesn't Need Any Modification" {
It "Should Make No Changes" {
$testString = "I am a string with no special characters."
$resultString = ConvertTo-SafeTeamCityMessage $testString
$resultString | Should -eq $testString
}
}
Context "When Provided With an empty string" {
It "Should Return an Empty string" {
$testString = ""
$resultString = ConvertTo-SafeTeamCityMessage $testString
$resultString | Should -eq $testString
}
}
}