-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-api-tests.ps1
More file actions
58 lines (47 loc) · 1.96 KB
/
run-api-tests.ps1
File metadata and controls
58 lines (47 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
Param(
[switch]$Rebuild,
[switch]$AttachLogs
)
$ErrorActionPreference = "Stop"
Write-Host "Starting API test environment..." -ForegroundColor Green
if ($Rebuild) {
docker compose -f docker-compose.test.yml build --no-cache
}
# Ensure clean slate
try { docker compose -f docker-compose.test.yml down -v --remove-orphans | Out-Null } catch {}
# Start in detached mode to avoid interactive UI (no keyboard hints / blocking)
docker compose -f docker-compose.test.yml up -d --build
# Optionally stream logs while waiting
if ($AttachLogs) {
Start-Job -ScriptBlock { docker compose -f docker-compose.test.yml logs -f } | Out-Null
}
# Prefer compose 'wait' if available; fallback to manual wait
$exitCode = 0
$waitSupported = $false
try {
docker compose -f docker-compose.test.yml wait test-runner | Out-Null
$waitSupported = $true
} catch {
$waitSupported = $false
}
if ($waitSupported) {
# Get exit code via inspect on the named container
$exitCode = (docker inspect -f "{{.State.ExitCode}}" focuz-test-runner)
} else {
# Poll until container exits, then read exit code
do {
Start-Sleep -Seconds 1
$status = (docker inspect -f "{{.State.Status}}" focuz-test-runner 2>$null)
} while ($status -ne "exited" -and $status -ne "dead")
$exitCode = (docker inspect -f "{{.State.ExitCode}}" focuz-test-runner)
}
# If tests failed, dump useful logs before tearing everything down
if ([int]$exitCode -ne 0) {
Write-Host "Tests failed (exit code $exitCode). Showing logs..." -ForegroundColor Red
try { docker compose -f docker-compose.test.yml logs --no-color test-runner | Write-Host } catch {}
try { docker compose -f docker-compose.test.yml logs --no-color test-api | Write-Host } catch {}
}
Write-Host "Cleaning up API test environment..." -ForegroundColor Green
try { docker compose -f docker-compose.test.yml down -v --remove-orphans | Out-Null } catch {}
# Exit with the test runner's exit code to integrate with CI and close the window automatically
exit [int]$exitCode