ps/Modules/Alkami.DevOps.SystemEngineering/Private/Get-YeatsLambdaIamRoleArn.tests.ps1
2023-05-30 22:51:22 -07:00

81 lines
3.2 KiB
PowerShell

. $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-YeatsLambdaIamRoleArn" {
Mock -CommandName Get-LogLeadName -ModuleName $inScopeModule -MockWith { return 'Get-YeatsLambdaIamRoleArn.tests' }
Mock -CommandName Import-AWSModule -ModuleName $inScopeModule -MockWith {}
Mock -CommandName Write-Warning -ModuleName $inScopeModule -MockWith {}
Context "Parameter Validation" {
It "Throws if EnvironmentTag is Null" {
{ Get-YeatsLambdaIamRoleArn -EnvironmentTag $null } | Should -Throw
}
It "Throws if EnvironmentName is Empty" {
{ Get-YeatsLambdaIamRoleArn -EnvironmentTag '' } | Should -Throw
}
It "Throws if ProfileName is Null" {
{ Get-YeatsLambdaIamRoleArn -EnvironmentTag "test" -ProfileName $null } | Should -Throw
}
It "Throws if ProfileName is Empty" {
{ Get-YeatsLambdaIamRoleArn -EnvironmentTag "test" -ProfileName '' } | Should -Throw
}
}
Context "Logic" {
It "Returns a String" {
(Get-Command Get-YeatsLambdaIamRoleArn).OutputType.Type.ToString() | Should -BeExactly "System.String"
}
It "Does not Throw on AWS Exception" {
Mock -CommandName Get-IamRole -ModuleName $inScopeModule -MockWith { throw "This is a test" }
{ Get-YeatsLambdaIamRoleArn -EnvironmentTag "test" -ProfileName 'temp-test' } | Should -Not -Throw
}
It "Writes Warning on AWS Exception" {
Mock -CommandName Get-IamRole -ModuleName $inScopeModule -MockWith { throw "This is a test" }
Get-YeatsLambdaIamRoleArn -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 Lambda IAM role' }
}
It "Returns Null on AWS Exception" {
Mock -CommandName Get-IamRole -ModuleName $inScopeModule -MockWith { throw "This is a test" }
$result = Get-YeatsLambdaIamRoleArn -EnvironmentTag "test" -ProfileName 'temp-test'
$result | Should -BeNull
}
It "Returns ARN from AWS Results" {
$testString = "ThisIsAnArn"
Mock -CommandName Get-IamRole -ModuleName $inScopeModule -MockWith { return @{'Arn' = $testString} }
$result = Get-YeatsLambdaIamRoleArn -EnvironmentTag "test" -ProfileName 'temp-test'
$result | Should -BeExactly $testString
}
}
}
}