ps/Modules/Alkami.DevOps.Operations/Retired/Copy-AlkamiReleaseManifest.Tests.retired.ps1
2023-05-30 22:51:22 -07:00

129 lines
4.7 KiB
PowerShell

# Load the Dependant Modules From Disk
if (Get-Module -Name Alkami.DevOps.Common) {
Remove-Module -Name Alkami.DevOps.Common
}
$commonModulePath = Get-ChildItem -Filter 'Alkami.DevOps.Common.psd1' -Recurse -ErrorAction Continue
Write-Host ("Forcing load of Alkami.DevOps.Common from {0}" -f $commonModulePath.FullName)
Import-Module $commonModulePath.FullName -Force
## TODO: There is no more Alkami.DevOps.Operations module ...
# Load the Module Under Test From Disk
$deployModulePath = Get-ChildItem -Filter 'Alkami.DevOps.Operations.psd1' -Recurse -ErrorAction Continue
Write-Host ("Forcing load of Alkami.DevOps.Operations from {0}" -f $deployModulePath.FullName)
if (Get-Module -Name Alkami.DevOps.Operations) {
Remove-Module -Name Alkami.DevOps.Operations -Force}
Import-Module $deployModulePath.FullName -Force
InModuleScope Alkami.DevOps.Operations {
Describe "Copy-AlkamiReleaseManifest" {
# Temp folder to do tests in.
$tempFile = [System.IO.Path]::GetTempFileName()
$tempPath = $tempFile.Split(".") | Select-Object -First 1
New-Item -ItemType Directory $tempPath -ErrorAction SilentlyContinue | Out-Null
Write-Host "Writing test files to $tempPath"
# Make Directories/Files for Tests
$testFiles = @{
# Current Deploy
"Current\test.txt" = "test"
"Current\DirA\a.txt" = "a"
"Current\DirA\b.txt" = "b"
"Current\DirA\c.txt" = "oldValue"
"NewRelease\DirA\a.txt" = "a"
"NewRelease\DirA\b.txt" = "b"
"NewRelease\DirA\c.txt" = "newValue"
"NewRelease\DirB\d.txt" = "d"
"NewRelease\DirB\e.txt" = "e"
"NewerRelease\DirA\a.txt" = "a"
"NewerRelease\DirA\b.txt" = "1"
"NewerRelease\DirA\c.txt" = "c"
"NewerRelease\DirB\d.txt" = "2"
}
foreach($key in $testFiles.keys)
{
$file = (Join-Path $tempPath $key)
$content = $testFiles[$key]
New-Item -ItemType File -Path $file -Force | Out-Null
Set-Content -Force -Path $file -Value $content
}
# Do the first copy from "NewRelease" into "Current"
$src = (Join-Path $tempPath "NewRelease")
$dst = (Join-Path $tempPath "Current")
Copy-AlkamiReleaseManifest $src $dst -DiffMove -Verbose
It "Deletes a file that was not in the newest release." {
$deletedFile = (Join-Path $dst "test.txt")
Write-Host "Checking that $deletedFile does not exist.."
Test-Path $deletedFile | Should Be $false
}
It "Creates new folder and files in the release." {
$newFile1 = (Join-Path $dst "DirB\d.txt")
$newFile2 = (Join-Path $dst "DirB\e.txt")
Test-Path $newFile1 | Should Be $true
Get-Content $newFile1 | Should Match "d"
Test-Path $newFile2 | Should Be $true
Get-Content $newFile2 | Should Match "e"
}
It "Updated a changed file." {
$changedFile = (Join-Path $dst "DirA\c.txt")
Test-Path $changedFile | Should Be $true
Get-Content $changedFile | Should Match "newValue"
}
It "Created manifest files." {
$manifest = (Join-Path $dst "manifest.txt")
$manifestLeftovers = (Join-Path $dst "manifestLeftovers.txt")
Test-Path $manifest | Should Be $true
Test-Path $manifestLeftovers | Should Be $true
}
# Copy in an extra file to make sure it gets preserved through the next copy.
$extraFile = (Join-Path $dst "DirB\extraFile.txt")
New-Item -ItemType File -Path $extraFile -Force | Out-Null
Set-Content -Force -Path $extraFile -Value "things and stuff!"
# Do the next copy from "NewerRelease" into "Current"
$src = (Join-Path $tempPath "NewerRelease")
$dst = (Join-Path $tempPath "Current")
Copy-AlkamiReleaseManifest $src $dst -DiffMove -Verbose
It "Does not delete the extra file from outside the release." {
Test-Path $extraFile | Should Be $true
Get-Content $extraFile | Should Match "things and stuff!"
}
It "Updated the further-changed files." {
foreach($key in $testFiles.keys)
{
if($key -like "NewerRelease")
{
$file = (Join-Path $dst $key)
$content = $testFiles[$key]
Get-Content -Path $file | Should Match $content
}
}
}
It "Deleted file removed from release." {
$deletedFile = (Join-Path $dst "DirB\e.txt")
Test-Path $deletedFile | Should Be $false
}
}
}