156 lines
6.9 KiB
PowerShell
156 lines
6.9 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 "Enable-AlkamiServiceFabricNode" {
|
|
|
|
Mock -CommandName Get-LogLeadName -ModuleName $moduleForMock -MockWith { return 'Enable-AlkamiServiceFabricNode.tests' }
|
|
Mock -CommandName Connect-AlkamiServiceFabricCluster -ModuleName $moduleForMock -MockWith {}
|
|
Mock -CommandName Enable-ServiceFabricNode -ModuleName $moduleForMock -MockWith {}
|
|
Mock -CommandName Wait-AlkamiServiceFabricNodeStatus -ModuleName $moduleForMock -MockWith {}
|
|
Mock -CommandName Wait-AlkamiServiceFabricClusterHealthy -ModuleName $moduleForMock -MockWith {}
|
|
Mock -CommandName Write-Error -ModuleName $moduleForMock -MockWith {}
|
|
|
|
Context "Parameter Validation" {
|
|
|
|
It "Throws if Hostname is Null" {
|
|
{ Enable-AlkamiServiceFabricNode -Hostname $null } | Should -Throw
|
|
}
|
|
|
|
It "Throws if Hostname is Empty" {
|
|
{ Enable-AlkamiServiceFabricNode -Hostname '' } | Should -Throw
|
|
}
|
|
|
|
It "Throws if Sleep Interval is Zero" {
|
|
{ Enable-AlkamiServiceFabricNode -SleepIntervalSeconds 0 } | Should -Throw
|
|
}
|
|
|
|
It "Throws if Sleep Interval is Too Large" {
|
|
{ Enable-AlkamiServiceFabricNode -SleepIntervalSeconds 180 } | Should -Throw
|
|
}
|
|
}
|
|
|
|
Context "Error Handling" {
|
|
|
|
It "Writes Error if Node is Not Present in Cluster" {
|
|
|
|
Mock -CommandName Get-ServiceFabricNode -ModuleName $moduleForMock -MockWith {
|
|
return @{ 'NodeName' = 'Test' }
|
|
}
|
|
|
|
Enable-AlkamiServiceFabricNode -Hostname 'NotTest'
|
|
|
|
Assert-MockCalled -CommandName Connect-AlkamiServiceFabricCluster -Times 1 -Exactly -Scope It
|
|
Assert-MockCalled -CommandName Get-ServiceFabricNode -Times 1 -Exactly -Scope It
|
|
|
|
Assert-MockCalled -CommandName Write-Error -Times 1 -Exactly -Scope It `
|
|
-ParameterFilter { $Message -match "Could not retrieve the Service Fabric node" }
|
|
}
|
|
}
|
|
|
|
Context "Logic" {
|
|
|
|
It "Uses Localhost Hostname By Default" {
|
|
|
|
$testHostname = "$env:COMPUTERNAME"
|
|
|
|
Mock -CommandName Get-ServiceFabricNode -ModuleName $moduleForMock -MockWith {
|
|
return @{ 'NodeName' = $testHostname }
|
|
}
|
|
|
|
Enable-AlkamiServiceFabricNode
|
|
|
|
Assert-MockCalled -CommandName Write-Error -Times 0 -Exactly -Scope It
|
|
|
|
Assert-MockCalled -CommandName Connect-AlkamiServiceFabricCluster -Times 1 -Exactly -Scope It `
|
|
-ParameterFilter { $Hostname -eq 'localhost' }
|
|
}
|
|
|
|
It "Resolves Localhost Hostname to Computername for Node Operations" {
|
|
|
|
$testHostname = "$env:COMPUTERNAME"
|
|
|
|
Mock -CommandName Get-ServiceFabricNode -ModuleName $moduleForMock -MockWith {
|
|
return @{ 'NodeName' = $testHostname }
|
|
}
|
|
|
|
Enable-AlkamiServiceFabricNode
|
|
|
|
Assert-MockCalled -CommandName Get-ServiceFabricNode -Times 1 -Exactly -Scope It
|
|
Assert-MockCalled -CommandName Write-Error -Times 0 -Exactly -Scope It
|
|
|
|
Assert-MockCalled -CommandName Connect-AlkamiServiceFabricCluster -Times 1 -Exactly -Scope It `
|
|
-ParameterFilter { $Hostname -eq 'localhost' }
|
|
Assert-MockCalled -CommandName Enable-ServiceFabricNode -Times 1 -Exactly -Scope It `
|
|
-ParameterFilter { $NodeName -eq $testHostname }
|
|
Assert-MockCalled -CommandName Wait-AlkamiServiceFabricNodeStatus -Times 1 -Exactly -Scope It `
|
|
-ParameterFilter { $Hostname -eq $testHostname }
|
|
Assert-MockCalled -CommandName Wait-AlkamiServiceFabricClusterHealthy -Times 1 -Exactly -Scope It `
|
|
-ParameterFilter { $Hostname -eq $testHostname }
|
|
}
|
|
|
|
It "Uses Hostname Parameter if Provided" {
|
|
|
|
$testHostname = "Test"
|
|
|
|
Mock -CommandName Get-ServiceFabricNode -ModuleName $moduleForMock -MockWith {
|
|
return @{ 'NodeName' = $testHostname }
|
|
}
|
|
|
|
Enable-AlkamiServiceFabricNode -Hostname $testHostname
|
|
|
|
Assert-MockCalled -CommandName Get-ServiceFabricNode -Times 1 -Exactly -Scope It
|
|
Assert-MockCalled -CommandName Write-Error -Times 0 -Exactly -Scope It
|
|
|
|
Assert-MockCalled -CommandName Connect-AlkamiServiceFabricCluster -Times 1 -Exactly -Scope It `
|
|
-ParameterFilter { $Hostname -eq $testHostname }
|
|
Assert-MockCalled -CommandName Enable-ServiceFabricNode -Times 1 -Exactly -Scope It `
|
|
-ParameterFilter { $NodeName -eq $testHostname }
|
|
Assert-MockCalled -CommandName Wait-AlkamiServiceFabricNodeStatus -Times 1 -Exactly -Scope It `
|
|
-ParameterFilter { $Hostname -eq $testHostname }
|
|
Assert-MockCalled -CommandName Wait-AlkamiServiceFabricClusterHealthy -Times 1 -Exactly -Scope It `
|
|
-ParameterFilter { $Hostname -eq $testHostname }
|
|
}
|
|
|
|
It "Performs Health Checks By Default" {
|
|
|
|
$testHostname = "Test"
|
|
|
|
Mock -CommandName Get-ServiceFabricNode -ModuleName $moduleForMock -MockWith {
|
|
return @{ 'NodeName' = $testHostname }
|
|
}
|
|
|
|
Enable-AlkamiServiceFabricNode -Hostname $testHostname
|
|
|
|
Assert-MockCalled -CommandName Write-Error -Times 0 -Exactly -Scope It
|
|
Assert-MockCalled -CommandName Enable-ServiceFabricNode -Times 1 -Exactly -Scope It
|
|
Assert-MockCalled -CommandName Wait-AlkamiServiceFabricClusterHealthy -Times 1 -Exactly -Scope It
|
|
|
|
Assert-MockCalled -CommandName Wait-AlkamiServiceFabricNodeStatus -Times 1 -Exactly -Scope It `
|
|
-ParameterFilter { $SkipHealthCheck -eq $false }
|
|
}
|
|
|
|
It "Skips Health Checks if Parameter is Provided" {
|
|
|
|
$testHostname = "Test"
|
|
|
|
Mock -CommandName Get-ServiceFabricNode -ModuleName $moduleForMock -MockWith {
|
|
return @{ 'NodeName' = $testHostname }
|
|
}
|
|
|
|
Enable-AlkamiServiceFabricNode -Hostname $testHostname -SkipHealthCheck
|
|
|
|
Assert-MockCalled -CommandName Write-Error -Times 0 -Exactly -Scope It
|
|
Assert-MockCalled -CommandName Enable-ServiceFabricNode -Times 1 -Exactly -Scope It
|
|
Assert-MockCalled -CommandName Wait-AlkamiServiceFabricClusterHealthy -Times 0 -Exactly -Scope It
|
|
|
|
Assert-MockCalled -CommandName Wait-AlkamiServiceFabricNodeStatus -Times 1 -Exactly -Scope It `
|
|
-ParameterFilter { $SkipHealthCheck -eq $true }
|
|
}
|
|
}
|
|
}
|