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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env bats
# tests/e2e/lifecycle.bats
#
# End-to-end tests for the compose up / ps / down lifecycle.
#
# Tests that compose up starts services, ps reports them as running,
# and down stops them cleanly.
#
# Prerequisites:
# - Run as root (sudo -E bats tests/e2e/lifecycle.bats)
# - alpine:latest pulled (pelagos image pull alpine:latest)
# - pelagos binary built (cargo build)
load helpers.bash
FIXTURE="$(dirname "$BATS_TEST_FILENAME")/fixtures/sleep-probe.reml"
PROJECT="bats-e2e-lifecycle"
setup_file() {
require_root
compose_up "$FIXTURE" "$PROJECT"
}
teardown_file() {
compose_down "$FIXTURE" "$PROJECT" 2>/dev/null || true
[[ -n "${COMPOSE_PID:-}" ]] && kill "$COMPOSE_PID" 2>/dev/null || true
}
# ---------------------------------------------------------------------------
# Tests
# ---------------------------------------------------------------------------
@test "compose up writes project state file" {
[[ -f "/run/pelagos/compose/${PROJECT}/state.json" ]]
}
@test "compose ps shows probe as running" {
run "$PELAGOS" compose ps -f "$FIXTURE" -p "$PROJECT"
[ "$status" -eq 0 ]
[[ "$output" =~ "probe" ]]
[[ "$output" =~ "running" ]]
}
@test "compose ps header contains SERVICE CONTAINER STATUS PID columns" {
run "$PELAGOS" compose ps -f "$FIXTURE" -p "$PROJECT"
[ "$status" -eq 0 ]
[[ "$output" =~ "SERVICE" ]]
[[ "$output" =~ "CONTAINER" ]]
[[ "$output" =~ "STATUS" ]]
[[ "$output" =~ "PID" ]]
}
@test "probe container name is scoped as PROJECT-SERVICE" {
run "$PELAGOS" compose ps -f "$FIXTURE" -p "$PROJECT"
[ "$status" -eq 0 ]
[[ "$output" =~ "${PROJECT}-probe" ]]
}
@test "probe PID is alive in /proc" {
local pid
pid=$(service_pid "$PROJECT" "probe")
[[ -n "$pid" ]]
[[ -d "/proc/$pid" ]]
}
@test "compose down stops the probe container" {
# Down the project and verify the state file is removed
run compose_down "$FIXTURE" "$PROJECT"
[ "$status" -eq 0 ]
# Wait a moment for cleanup
sleep 1
# State file should be gone
[[ ! -f "/run/pelagos/compose/${PROJECT}/state.json" ]]
}