ps/Modules/Alkami.DevOps.SystemEngineering/Private/Get-YeatsRotationLambdaArn.tests.ps1

86 lines
3.5 KiB
PowerShell
Raw Normal View History

2023-05-30 22:51:22 -07:00
. $PSScriptRoot\..\..\Load-PesterModules.ps1
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.tests\.', '.'
$global:functionPath = Join-Path -Path $here -ChildPath $sut
InModuleScope -ModuleName Alkami.DevOps.SystemEngineering -ScriptBlock {
Write-Host "InModuleScope - Overriding SUT: $global:functionPath"
Import-Module $global:functionPath -Force
$inScopeModule = "Alkami.DevOps.SystemEngineering"
Describe "Get-YeatsRotationLambdaArn" {
Mock -CommandName Get-LogLeadName -ModuleName $inScopeModule -MockWith { return 'Get-YeatsRotationLambdaArn.tests' }
Mock -CommandName Get-AWSRegion -ModuleName $inScopeModule -MockWith { return @{region = 'us-east-1'} }
Mock -CommandName Import-AWSModule -ModuleName $inScopeModule -MockWith {}
Mock -CommandName Write-Warning -ModuleName $inScopeModule -MockWith {}
Context "Parameter Validation" {
It "Throws if EnvironmentTag is Null" {
{ Get-YeatsRotationLambdaArn -EnvironmentTag $null } | Should -Throw
}
It "Throws if EnvironmentName is Empty" {
{ Get-YeatsRotationLambdaArn -EnvironmentTag '' } | Should -Throw
}
It "Throws if ProfileName is Null" {
{ Get-YeatsRotationLambdaArn -EnvironmentTag "test" -ProfileName $null } | Should -Throw
}
It "Throws if ProfileName is Empty" {
{ Get-YeatsRotationLambdaArn -EnvironmentTag "test" -ProfileName '' } | Should -Throw
}
It "Throws if Region is Not In Validation List" {
{ Get-YeatsRotationLambdaArn -EnvironmentTag "test" -ProfileName 'test' -Region 'us-west-2' } | Should -Throw
}
}
Context "Logic" {
It "Returns a String" {
(Get-Command Get-YeatsRotationLambdaArn).OutputType.Type.ToString() | Should -BeExactly "System.String"
}
It "Does not Throw on AWS Exception" {
Mock -CommandName Get-LMFunctionConfiguration -ModuleName $inScopeModule -MockWith { throw "This is a test" }
{ Get-YeatsRotationLambdaArn -EnvironmentTag "test" -ProfileName 'temp-test' } | Should -Not -Throw
}
It "Writes Warning on AWS Exception" {
Mock -CommandName Get-LMFunctionConfiguration -ModuleName $inScopeModule -MockWith { throw "This is a test" }
Get-YeatsRotationLambdaArn -EnvironmentTag "test" -ProfileName 'temp-test' | Out-Null
Assert-MockCalled -ModuleName $inScopeModule -CommandName Write-Warning -Times 1 -Exactly -Scope It `
-ParameterFilter { $Message -match 'Unable to find Yeats rotation Lambda' }
}
It "Returns Null on AWS Exception" {
Mock -CommandName Get-LMFunctionConfiguration -ModuleName $inScopeModule -MockWith { throw "This is a test" }
$result = Get-YeatsRotationLambdaArn -EnvironmentTag "test" -ProfileName 'temp-test'
$result | Should -BeNull
}
It "Returns ARN from AWS Results" {
$testString = "ThisIsAnArn"
Mock -CommandName Get-LMFunctionConfiguration -ModuleName $inScopeModule -MockWith { return @{'FunctionArn' = $testString} }
$result = Get-YeatsRotationLambdaArn -EnvironmentTag "test" -ProfileName 'temp-test'
$result | Should -BeExactly $testString
}
}
}
}