ps/Modules/Alkami.PowerShell.Services/Public/New-AppTierWindowsServices.tests.ps1
2023-05-30 22:51:22 -07:00

69 lines
2.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 "New-AppTierWindowsServices" {
Context "Ensure that it does the simple happy path for one service defined" {
Mock -ModuleName $moduleForMock -CommandName Get-AppTierServices -MockWith { @(
@{
FolderName = 'Fake Path'
AssemblyInfo = 'Fake.Service.exe'
Name = "Fake Service"
User = "REPLACEME"
Password = "REPLACEME"
IsGMSAAccount = $true
Binary = $basePath + "\Nag\Alkami.App.Nag.Host.Service.exe"
}
) }
Mock -ModuleName $moduleForMock -CommandName Install-AlkamiService -MockWith { }
Mock -ModuleName $moduleForMock -CommandName Set-WindowsServiceExecutionAccount -MockWith { }
Mock -ModuleName $moduleForMock -CommandName Get-OrbPath -MockWith { return "fakepath" }
It "Does not throw" {
{ New-AppTierWindowsServices } | Should -Not -Throw
}
It "Calls Install-AlkamiService once for a single service being called" {
New-AppTierWindowsServices
Assert-MockCalled -CommandName Install-AlkamiService -Times 1 -Scope It -ModuleName $moduleForMock
}
It "Calls Set-WindowsServiceExecutionAccount once for a single service being called" {
New-AppTierWindowsServices
Assert-MockCalled -CommandName Set-WindowsServiceExecutionAccount -Times 1 -Scope It -ModuleName $moduleForMock
}
}
Context "Ensure that it does not call inner functions for empty array" {
Mock -ModuleName $moduleForMock -CommandName Get-AppTierServices -MockWith { @() }
Mock -ModuleName $moduleForMock -CommandName Install-AlkamiService -MockWith { }
Mock -ModuleName $moduleForMock -CommandName Set-WindowsServiceExecutionAccount -MockWith { }
Mock -ModuleName $moduleForMock -CommandName Get-OrbPath -MockWith { return "fakepath" }
It "Does not throw" {
{ New-AppTierWindowsServices } | Should -Not -Throw
}
It "Does not call Install-AlkamiService if no service being called to install" {
New-AppTierWindowsServices
Assert-MockCalled -CommandName Install-AlkamiService -Times 0 -Scope It -ModuleName $moduleForMock
}
It "Does not call Set-WindowsServiceExecutionAccount if no service being called to install" {
New-AppTierWindowsServices
Assert-MockCalled -CommandName Set-WindowsServiceExecutionAccount -Times 0 -Scope It -ModuleName $moduleForMock
}
}
}