138 lines
5.0 KiB
PowerShell
138 lines
5.0 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 "Get-ArmorList" {
|
||
|
|
||
|
Context "Parameter Validation" {
|
||
|
|
||
|
It "Null Environment Name Should Throw" {
|
||
|
|
||
|
{ Get-ArmorList -EnvironmentName $null } | Should Throw
|
||
|
}
|
||
|
|
||
|
It "Empty Environment Name Should Throw" {
|
||
|
|
||
|
{ Get-ArmorList -EnvironmentName '' } | Should Throw
|
||
|
}
|
||
|
|
||
|
It "Invalid Tier Should Throw" {
|
||
|
|
||
|
{ Get-ArmorList -EnvironmentName 'Test' -Tier 'Test' } | Should Throw
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Context "Result Respects NoDomain Parameter" {
|
||
|
|
||
|
Mock -CommandName Get-HostnamesByEnvironmentName -MockWith { return @( 'A', 'B' ) } -ModuleName $moduleForMock
|
||
|
|
||
|
It "Appends Domain By Default" {
|
||
|
|
||
|
( Get-ArmorList -EnvironmentName 'Test' ) | Should -BeExactly 'A.fh.local,B.fh.local'
|
||
|
}
|
||
|
|
||
|
It "Does Not Append Domain When Switch Is Present" {
|
||
|
|
||
|
( Get-ArmorList -EnvironmentName 'Test' -NoDomain ) | Should -BeExactly 'A,B'
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Context "Result Respects List Parameter" {
|
||
|
|
||
|
It "Returns a Comma-Delimited String By Default" {
|
||
|
|
||
|
Mock -CommandName Get-HostnamesByEnvironmentName -MockWith { return @( 'A', 'B' ) } -ModuleName $moduleForMock
|
||
|
|
||
|
( Get-ArmorList -EnvironmentName 'Test' -NoDomain ) | Should -BeExactly 'A,B'
|
||
|
}
|
||
|
|
||
|
It "Returns a String Type By Default" {
|
||
|
|
||
|
Mock -CommandName Get-HostnamesByEnvironmentName -MockWith { return @( 'A', 'B' ) } -ModuleName $moduleForMock
|
||
|
|
||
|
( Get-ArmorList -EnvironmentName 'Test' -NoDomain ) -is [string] | Should -BeTrue
|
||
|
}
|
||
|
|
||
|
It "Returns An Array When Switch Is Present" {
|
||
|
|
||
|
Mock -CommandName Get-HostnamesByEnvironmentName -MockWith { return @( 'A', 'B' ) } -ModuleName $moduleForMock
|
||
|
|
||
|
( Get-ArmorList -EnvironmentName 'Test' -NoDomain -List ) | Should -BeExactly @( 'A', 'B' )
|
||
|
}
|
||
|
|
||
|
It "Returns An Array Type When Switch Is Present" {
|
||
|
|
||
|
Mock -CommandName Get-HostnamesByEnvironmentName -MockWith { return @( 'A', 'B' ) } -ModuleName $moduleForMock
|
||
|
|
||
|
( Get-ArmorList -EnvironmentName 'Test' -NoDomain -List ) -is [array] | Should -BeTrue
|
||
|
}
|
||
|
|
||
|
It "Returns a String Type By Default When There Is A Single Hostname" {
|
||
|
|
||
|
Mock -CommandName Get-HostnamesByEnvironmentName -MockWith { return @( 'A' ) } -ModuleName $moduleForMock
|
||
|
|
||
|
( Get-ArmorList -EnvironmentName 'Test' -NoDomain ) -is [string] | Should -BeTrue
|
||
|
}
|
||
|
|
||
|
It "Returns An Array Type When Switch Is Present When There Is A Single Hostname" {
|
||
|
|
||
|
Mock -CommandName Get-HostnamesByEnvironmentName -MockWith { return @( 'A' ) } -ModuleName $moduleForMock
|
||
|
|
||
|
# This test feels worthless, but Powershell is coercing a single element array to a string on return.
|
||
|
# I verified through debug prints that the variable is of type [string[]] all the way up to the return
|
||
|
# statement. Have fun reading https://superuser.com/a/414666
|
||
|
[string[]] $result = Get-ArmorList -EnvironmentName 'Test' -NoDomain -List
|
||
|
$result -is [array] | Should -BeTrue
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Context "Result Respects Quote Parameter" {
|
||
|
|
||
|
Mock -CommandName Get-HostnamesByEnvironmentName -MockWith { return @( 'A', 'B' ) } -ModuleName $moduleForMock
|
||
|
|
||
|
It "Returns Unquoted Values By Default" {
|
||
|
|
||
|
( Get-ArmorList -EnvironmentName 'Test' -NoDomain ) | Should -BeExactly 'A,B'
|
||
|
}
|
||
|
|
||
|
It "Returns Quoted Values When Switch Is Present" {
|
||
|
|
||
|
( Get-ArmorList -EnvironmentName 'Test' -NoDomain -Quote ) | Should -BeExactly '"A","B"'
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Context "Result Respects Tier Parameter" {
|
||
|
|
||
|
Mock -CommandName Get-HostnamesByEnvironmentName -MockWith { return @( 'WEB123', 'APP123', 'MIC123', 'FAB123' ) } -ModuleName $moduleForMock
|
||
|
|
||
|
It "Returns All Tiers By Default" {
|
||
|
|
||
|
( Get-ArmorList -EnvironmentName 'Test' -NoDomain -List ) | Should -BeExactly @( 'WEB123', 'APP123', 'MIC123', 'FAB123' )
|
||
|
}
|
||
|
|
||
|
It "Returns Only Web Servers When Web Tier Filtering" {
|
||
|
|
||
|
( Get-ArmorList -EnvironmentName 'Test' -NoDomain -List -Tier 'Web') | Should -BeExactly @( 'WEB123' )
|
||
|
}
|
||
|
|
||
|
It "Returns Only App Servers When App Tier Filtering" {
|
||
|
|
||
|
( Get-ArmorList -EnvironmentName 'Test' -NoDomain -List -Tier 'App') | Should -BeExactly @( 'APP123' )
|
||
|
}
|
||
|
|
||
|
It "Returns Only Mic Servers When Mic Tier Filtering" {
|
||
|
|
||
|
( Get-ArmorList -EnvironmentName 'Test' -NoDomain -List -Tier 'Mic') | Should -BeExactly @( 'MIC123' )
|
||
|
}
|
||
|
|
||
|
It "Returns Only Fab Servers When Fab Tier Filtering" {
|
||
|
|
||
|
( Get-ArmorList -EnvironmentName 'Test' -NoDomain -List -Tier 'Fab') | Should -BeExactly @( 'FAB123' )
|
||
|
}
|
||
|
}
|
||
|
}
|