ps/Modules/Alkami.PowerShell.Configuration/Public/Get-AppSetting.tests.ps1
2023-05-30 22:51:22 -07:00

46 lines
1.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 "Get-AppSetting - base" {
$fakeConfigFile = "TestDrive:\doesnt_matter\fake.config"
Context "Throws an error if the configuration Node doesn't exist" {
$appSettingsTestContents = @"
"@
Mock -ModuleName $moduleForMock -CommandName Write-Error -MockWith {}
Mock -ModuleName $moduleForMock -CommandName Write-Host -MockWith {}
Mock -ModuleName $moduleForMock -CommandName Write-Warning -MockWith {}
$value = $null
#TODO - Test the inverse... if there's a good value here, does the ScriptBlock context actually
# set a value to $value?
{$value = Get-AppSetting -Path $fakeConfigFile -Key "FakeSetting"} | Should -Not -Throw
It "should not have a value" {
$value | Should -BeNull
}
It "did not write an error" {
Assert-MockCalled -ModuleName $moduleForMock -CommandName Write-Error -Times 0 -Scope Context
}
It "wrote a warning to the console for missed content" {
Assert-MockCalled -ModuleName $moduleForMock -CommandName Write-Warning -Times 1 -Scope Context
}
It "wrote no other messages" {
Assert-MockCalled -ModuleName $moduleForMock -CommandName Write-Host -Times 0 -Scope Context
}
}
}