forked from mtusi2026/mtusi2026lab5
48 lines
2.7 KiB
PowerShell
48 lines
2.7 KiB
PowerShell
$ErrorActionPreference = 'Stop'
|
|
Set-Location (Split-Path $PSScriptRoot -Parent)
|
|
$env:BASE_URL = 'http://127.0.0.1:18085'
|
|
$production = @('compose', '-f', 'docker-compose.yml', '-f', 'compose.local.yaml')
|
|
$testing = $production + @('-f', 'compose.test.yaml')
|
|
$summary = 'evidence/test-suite.txt'
|
|
"Started: $([DateTimeOffset]::Now.ToString('o'))" | Set-Content $summary
|
|
|
|
function Invoke-Check {
|
|
param([string]$Name, [string]$Executable, [string[]]$Arguments)
|
|
Write-Host "Running $Name"
|
|
& $Executable @Arguments *> "evidence/$Name.txt"
|
|
$result = $LASTEXITCODE
|
|
"$Name exit=$result at $([DateTimeOffset]::Now.ToString('o'))" | Add-Content $summary
|
|
if ($result -ne 0) {
|
|
Get-Content "evidence/$Name.txt" -Tail 30
|
|
throw "$Name failed ($result)"
|
|
}
|
|
}
|
|
|
|
try {
|
|
Invoke-Check 'style' 'py' @('scripts/style.py')
|
|
Invoke-Check 'contract-check' 'py' @('scripts/check_contract.py')
|
|
Invoke-Check 'openapi-validation' 'py' @('scripts/validate_openapi.py')
|
|
Invoke-Check 'java-build' '.\gradlew.bat' @('test', '--rerun-tasks')
|
|
Invoke-Check 'docker-build' 'docker' ($testing + @('up', '-d', '--build'))
|
|
& py -c "import sys;sys.path.insert(0,'tests');from pipeline_support import ready_api;ready_api()"
|
|
if ($LASTEXITCODE -ne 0) { throw 'API not ready' }
|
|
foreach ($name in @('smoke', 'pipeline_core', 'pipeline_faults', 'pipeline_retention', 'pipeline_boundaries', 'pipeline_ack_guard', 'pipeline_filename', 'pipeline_upload_crash', 'pipeline_history_capacity')) {
|
|
Invoke-Check ($name.Replace('_', '-')) 'py' @("tests/$name.py")
|
|
}
|
|
Invoke-Check 'production-restore' 'docker' ($production + @('up', '-d'))
|
|
& py -c "import sys;sys.path.insert(0,'tests');from pipeline_support import ready_api;ready_api()"
|
|
if ($LASTEXITCODE -ne 0) { throw 'production API not ready' }
|
|
Invoke-Check 'load' 'py' @('tests/load.py', '--duration', '30', '--concurrency', '4', '--output', 'evidence/load.json')
|
|
Invoke-Check 'persistence' 'py' @('tests/resilience.py', '--mode', 'persistence', '--action-script', 'scripts/restart.cmd')
|
|
& py -c "import sys;sys.path.insert(0,'tests');from pipeline_support import ready_api;ready_api()"
|
|
if ($LASTEXITCODE -ne 0) { throw 'Two routable API replicas required before failover' }
|
|
Invoke-Check 'failover' 'py' @('tests/resilience.py', '--mode', 'failover', '--action-script', 'scripts/stop-one.cmd')
|
|
Invoke-Check 'restore-api' 'docker' ($production + @('up', '-d', 'api'))
|
|
Invoke-Check 'smoke' 'py' @('tests/smoke.py')
|
|
Invoke-Check 'capture' 'py' @('scripts/capture_evidence.py')
|
|
'PASS all executable lab5 tests, validation and style checks' | Add-Content $summary
|
|
} finally {
|
|
& docker @production up -d
|
|
if ($LASTEXITCODE -ne 0) { throw 'Failed to restore production profile' }
|
|
}
|