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

77 lines
1.7 KiB
PowerShell

. $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 "Test-IsStringIPAddress" {
$validIPs = @(
"127.0.0.1",
"192.168.1.1",
"10.50.1.150"
)
$invalidIPs = @(
"256.0.0.1",
"999.999.999.999",
"1.1.1.257"
)
$testStrings = @(
"HelloThereGeneralKenobi",
"IHateSand123",
"127001"
)
Context "When a Valid IP Address Is Specified" {
foreach ($ip in $validIPs) {
It "Returns True for $ip" {
Test-IsStringIPAddress $ip | Should -BeTrue
}
}
}
Context "When an Invalid IP-Like String is Specified" {
foreach ($ip in $invalidIPS) {
It "Returns False for $ip" {
Test-IsStringIPAddress $ip | Should -BeFalse
}
}
}
Context "When a String is Specified" {
foreach ($testString in $testStrings) {
It "Returns False for $testString" {
Test-IsStringIPAddress $testString | Should -BeFalse
}
}
}
Context "When a String is Piped To the Function" {
It "Returns True if the String is an IP Address" {
"127.0.0.1" | Test-IsStringIPAddress | Should -BeTrue
}
It "Returns False if the String is Not an IP Address" {
"IHaveTheHighGround" | Test-IsStringIPAddress | Should -BeFalse
}
}
}