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

49 lines
1.8 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
Describe "Get-AlkamiIamAssumeRolePolicyString" {
Context "Parameter Validation" {
It "Throws if ServiceName is Null" {
{ Get-AlkamiIamAssumeRolePolicyString -ServiceName $null } | Should -Throw
}
It "Throws if ServiceName is Empty" {
{ Get-AlkamiIamAssumeRolePolicyString -ServiceName '' } | Should -Throw
}
}
Context "Logic" {
It "Returns a String" {
(Get-Command Get-AlkamiIamAssumeRolePolicyString).OutputType.Type.ToString() | Should -BeExactly "System.String"
}
It "Returns a String With a Valid JSON Conversion" {
{ ConvertFrom-Json (Get-AlkamiIamAssumeRolePolicyString -ServiceName 'test') } | Should -Not -Throw
}
It "Appends '.amazonaws.com' If Not Provided" {
$result = ConvertFrom-Json (Get-AlkamiIamAssumeRolePolicyString -ServiceName 'test')
$result.Statement[0].Principal.Service | Should -BeExactly 'test.amazonaws.com'
}
It "Does Not Append '.amazonaws.com' If Provided" {
$result = ConvertFrom-Json (Get-AlkamiIamAssumeRolePolicyString -ServiceName 'test.amazonaws.com')
$result.Statement[0].Principal.Service | Should -BeExactly 'test.amazonaws.com'
}
}
}
}