68 lines
3.6 KiB
PowerShell
68 lines
3.6 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 "Invoke-TopshelfPath" {
|
|||
|
Context "throws on an array with error text" {
|
|||
|
$output = @(
|
|||
|
"Topshelf.HostFactory Error: 0 : An exception occurred creating the host, Topshelf.HostConfigurationException: The service was not properly configured: ",
|
|||
|
"[Failure] Command Line An unknown command-line option was found: ARGUMENT: -?",
|
|||
|
"[Success] Name Alkami.Services.Subscriptions.Host",
|
|||
|
"[Success] ServiceName Alkami.Services.Subscriptions.Host",
|
|||
|
" at Topshelf.Configurators.ValidateConfigurationResult.CompileResults(IEnumerable`1 results)",
|
|||
|
" at Topshelf.HostFactory.New(Action`1 configureCallback)",
|
|||
|
"Topshelf.HostFactory Error: 0 : The service terminated abnormally, Topshelf.HostConfigurationException: The service was not properly configured: ",
|
|||
|
"[Failure] Command Line An unknown command-line option was found: ARGUMENT: -?",
|
|||
|
"[Success] Name Alkami.Services.Subscriptions.Host",
|
|||
|
"[Success] ServiceName Alkami.Services.Subscriptions.Host",
|
|||
|
" at Topshelf.Configurators.ValidateConfigurationResult.CompileResults(IEnumerable`1 results)",
|
|||
|
" at Topshelf.HostFactory.New(Action`1 configureCallback)",
|
|||
|
" at Topshelf.HostFactory.Run(Action`1 configureCallback)"
|
|||
|
)
|
|||
|
Mock -ModuleName $moduleForMock -CommandName Invoke-CallOperatorWithPathAndParameters -MockWith { return $output }
|
|||
|
|
|||
|
It "throws as expected" {
|
|||
|
{ Invoke-TopshelfPath "ignored" @("ignored") } | Should -Throw
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
Context "throws on an array with Win32Exception text" {
|
|||
|
$output = @(
|
|||
|
"Running a transacted installation.",
|
|||
|
"Beginning the Install phase of the installation.",
|
|||
|
"Installing service Alkami.MS.RDC.Ensenta.Service.Host...",
|
|||
|
"Creating EventLog source Alkami.MS.RDC.Ensenta.Service.Host in log Application...",
|
|||
|
"An exception occurred during the Install phase.",
|
|||
|
"System.ComponentModel.Win32Exception: The name is already in use as either a service name or a service display name",
|
|||
|
"The Rollback phase of the installation is beginning.",
|
|||
|
"Restoring event log to previous state for source Alkami.MS.RDC.Ensenta.Service.Host.",
|
|||
|
"The Rollback phase completed successfully.",
|
|||
|
"The transacted install has completed."
|
|||
|
)
|
|||
|
Mock -ModuleName $moduleForMock -CommandName Invoke-CallOperatorWithPathAndParameters -MockWith { return $output }
|
|||
|
|
|||
|
It "throws as expected" {
|
|||
|
{ Invoke-TopshelfPath "ignored" @("ignored") } | Should -Throw
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
Context "doesn't throw if no exit code is present" {
|
|||
|
$output = @(
|
|||
|
"Configuration Result:",
|
|||
|
"[Success] Name Alkami.Services.Subscriptions.Host",
|
|||
|
"[Success] ServiceName Alkami.Services.Subscriptions.Host",
|
|||
|
"Topshelf v3.1.122.0, .NET Framework v4.0.30319.42000",
|
|||
|
"The Alkami.Services.Subscriptions.Host service is already installed."
|
|||
|
)
|
|||
|
Mock -ModuleName $moduleForMock -CommandName Invoke-CallOperatorWithPathAndParameters -MockWith { $global:LASTEXITCODE = 0; return $output }
|
|||
|
|
|||
|
It "does not throw (as expected)" {
|
|||
|
{ Invoke-TopshelfPath "ignored" @("ignored") } | Should -Not -Throw
|
|||
|
}
|
|||
|
}
|
|||
|
}
|