ps/Modules/Alkami.PowerShell.Configuration/Public/Test-AlkamiManifest.tests.ps1

167 lines
6.0 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\.', '.'
$functionPath = Join-Path -Path $here -ChildPath $sut
Write-Host "Overriding SUT: $functionPath"
Import-Module $functionPath -Force
$moduleForMock = ""
Describe "Test-AlkamiManifest" {
function New-FakeServiceManifest {
$sampleManifest = @"
<?xml version="1.0"?>
<packageManifest>
<version>1.0</version>
<general>
<creatorCode>Alkami</creatorCode>
<element>Alkami.MicroServices.Testing.FakeService</element>
<componentType>Service</componentType>
<bankIdentifiers>
<bankIdentifier name="MyFIName">DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF</bankIdentifier>
</bankIdentifiers>
</general>
<serviceManifest>
<runtime>framework</runtime>
<entryPoint>Alkami.MicroServices.Testing.FakeService</entryPoint>
<migrations>
<package id="Alkami.MicroServices.Testing.FakeService" version="1.0" />
</migrations>
<db_role>my_service_role</db_role>
</serviceManifest>
</packageManifest>
"@
$testFile = "TestDrive:\NewServiceAlkamiManifest.xml"
Set-Content -Path $testFile -value $sampleManifest
}
function New-FakeServiceManifestWithReleaseManagement {
$sampleManifest = @"
<?xml version="1.0"?>
<packageManifest>
<version>1.0</version>
<general>
<creatorCode>Alkami</creatorCode>
<element>Alkami.MicroServices.Testing.FakeService</element>
<componentType>Service</componentType>
<bankIdentifiers>
<bankIdentifier name="MyFIName">DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF</bankIdentifier>
</bankIdentifiers>
<releaseManagement>
<alwaysDeploy>true</alwaysDeploy>
</releaseManagement>
</general>
<serviceManifest>
<runtime>framework</runtime>
<entryPoint>Alkami.MicroServices.Testing.FakeService</entryPoint>
<migrations>
<package id="Alkami.MicroServices.Testing.FakeService" version="1.0" />
</migrations>
<db_role>my_service_role</db_role>
</serviceManifest>
</packageManifest>
"@
$testFile = "TestDrive:\NewServiceAlkamiManifest.xml"
Set-Content -Path $testFile -value $sampleManifest
}
function New-InvalidServiceManifestWithReleaseManagement {
$sampleManifest = @"
<?xml version="1.0"?>
<packageManifest>
<version>1.0</version>
<general>
<creatorCode>Alkami</creatorCode>
<element>Alkami.MicroServices.Testing.FakeService</element>
<componentType>Service</componentType>
<bankIdentifiers>
<bankIdentifier name="MyFIName">DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF</bankIdentifier>
</bankIdentifiers>
<releaseManagement>
<alwaysDeploy>not_a_bool</alwaysDeploy>
</releaseManagement>
</general>
<serviceManifest>
<runtime>framework</runtime>
<entryPoint>Alkami.MicroServices.Testing.FakeService</entryPoint>
<migrations>
<package id="Alkami.MicroServices.Testing.FakeService" version="1.0" />
</migrations>
<db_role>my_service_role</db_role>
</serviceManifest>
</packageManifest>
"@
$testFile = "TestDrive:\NewServiceAlkamiManifest.xml"
Set-Content -Path $testFile -value $sampleManifest
}
function New-ValidFluentMigrationManifest {
$sampleManifest = @"
<?xml version="1.0" encoding="UTF-8"?>
<packageManifest>
<version>1.0</version>
<general>
<creatorCode>Alkami</creatorCode>
<element>Alkami.Migrations.UserReporting.Migrations</element>
<componentType>FluentMigration</componentType>
</general>
<fluentMigrationManifest>
<runtime>framework</runtime>
<version>1.4.0</version>
<migrationType online="false">tenant</migrationType>
<serverType>MSSQL</serverType>
<entryPoint>Alkami.Migrations.UserReporting.Migrations.dll</entryPoint>
<db_role>Alkami.Migrations.UserReporting_Service</db_role>
</fluentMigrationManifest>
</packageManifest>
"@
$testFile = "TestDrive:\NewFluentMigrationAlkamiManifest.xml"
Set-Content -Path $testFile -value $sampleManifest
}
Mock -ModuleName $moduleForMock -CommandName Get-LogLeadName -MockWith { return "SUT" }
Mock -ModuleName $moduleForMock -CommandName Write-Verbose -MockWith { }
Mock -ModuleName $moduleForMock -CommandName Write-Host -MockWith { }
Mock -ModuleName $moduleForMock -CommandName Get-AlkamiManifestFilename -MockWith { return "NewServiceAlkamiManifest.xml" }
# The expectation is that we will have multiple versions here. We might need more contexts per version at that point.
Context "When Testing a Service Manifest" {
New-FakeServiceManifest
Mock -ModuleName $moduleForMock -CommandName Test-AlkamiServiceManifest10 -MockWith { return @{ success = $true } }
It "Calls Test-AlkamiServiceManifest10" {
Test-AlkamiManifest -Source "TestDrive:\NewServiceAlkamiManifest.xml"
Assert-MockCalled -CommandName Test-AlkamiServiceManifest10 -Scope It
}
}
Context "When Testing a Service Manifest with Release Management" {
New-FakeServiceManifestWithReleaseManagement
It "Returns true" {
Test-AlkamiManifest -Source "TestDrive:\NewServiceAlkamiManifest.xml" | Should -BeTrue
}
}
Context "When Testing a FluentMigration manifest" {
Mock -ModuleName $moduleForMock -CommandName Get-AlkamiManifestFilename -MockWith { return "NewFluentMigrationAlkamiManifest.xml" }
New-ValidFluentMigrationManifest
It "Returns true" {
Test-AlkamiManifest -Source "TestDrive:\NewFluentMigrationAlkamiManifest.xml" | Should -BeTrue
}
}
Context "When Testing an invalid Service Manifest with Release Management" {
New-InvalidServiceManifestWithReleaseManagement
It "Returns false" {
Test-AlkamiManifest -Source "TestDrive:\NewServiceAlkamiManifest.xml" | Should -BeFalse
}
}
}