46 lines
2.3 KiB
PowerShell
46 lines
2.3 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 "Start-ServicesByTier" {
|
|
|
|
Mock -ModuleName $moduleForMock -CommandName Get-ServicesByTier -MockWith { return @("Fake.Service.One", "Fake.Service.Two") }
|
|
Mock -ModuleName $moduleForMock -CommandName Start-ServicesInParallel
|
|
Mock -ModuleName $moduleForMock -CommandName Test-IsCollectionNullOrEmpty -MockWith { return @("Fake.Service.One", "Fake.Service.Two") }
|
|
Mock -ModuleName $moduleForMock -CommandName Get-Service
|
|
Mock -ModuleName $moduleForMock -CommandName Write-Warning
|
|
Mock -ModuleName $moduleForMock -CommandName Write-Host
|
|
|
|
Context "Start services by tier with different parameters" {
|
|
|
|
It "Assert Get-ServicesByTier called with -IncludeLowerTiers" {
|
|
|
|
Start-ServicesByTier -Tier 2 -IncludeLowerTiers
|
|
Assert-MockCalled -CommandName Get-ServicesByTier -Times 1 -Exactly -Scope It -ModuleName $moduleForMock -ParameterFilter { $IncludeLowerTiers -match $null }
|
|
}
|
|
|
|
It "Assert Get-ServicesByTier called without -IncludeLowerTiers" {
|
|
|
|
Start-ServicesByTier -Tier 2
|
|
Assert-MockCalled -CommandName Get-ServicesByTier -Times 1 -Exactly -Scope It -ModuleName $moduleForMock -ParameterFilter { $IncludeLowerTiers -match $null }
|
|
}
|
|
|
|
}
|
|
|
|
Context "Start services by tier foreach logic output" {
|
|
|
|
It "Assert Start-ServicesInParallel with Tier 0" {
|
|
|
|
Mock -ModuleName $moduleForMock -CommandName Get-ServicesByTier -MockWith { return @("Fake.Service.One") }
|
|
Mock -ModuleName $moduleForMock -CommandName Test-IsCollectionNullOrEmpty -MockWith { return $false }
|
|
Mock -ModuleName $moduleForMock -CommandName Get-Service -MockWith { return @{ Status = "Stopped" } }
|
|
|
|
Start-ServicesByTier -Tier 0
|
|
Assert-MockCalled -CommandName Start-ServicesInParallel -Times 1 -Exactly -Scope It -ModuleName $moduleForMock -ParameterFilter { $ServiceNamestoStart -match "Fake.Service.One" }
|
|
}
|
|
}
|
|
} |