Skip to content

Commit df39be2

Browse files
committed
feat(lab-01): implement standalone Lab 01 compose + test script
- Replace stub compose with complete multi-service stack - Add proper healthchecks, named volumes, and container conventions - Implement functional Phase 3 tests with real endpoint validation - Add cleanup() trap for reliable teardown (NO_CLEANUP=1 support) - Fix CI lab-01-smoke: reference correct module-numbered test script
1 parent 01c1e3d commit df39be2

3 files changed

Lines changed: 111 additions & 38 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ jobs:
102102
docker compose -f docker/docker-compose.standalone.yml ps
103103
104104
- name: Run Lab 01 test script
105-
run: bash tests/labs/test-lab-01.sh
105+
run: bash tests/labs/test-lab-16-01.sh
106106

107107
- name: Collect logs on failure
108108
if: failure()
Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,71 @@
1-
# Lab 01 — Standalone: Complete Snipe-IT IT asset management in isolation
2-
# No external dependencies required.
1+
# Lab 01 — Standalone: Snipe-IT IT asset management in isolation
2+
# Uses MariaDB as local database — no external dependencies required.
33
---
4+
name: it-stack-snipeit-lab01
5+
46
services:
5-
snipeit:
7+
8+
snipeit-s01-db:
9+
image: mariadb:10.11
10+
container_name: snipeit-s01-db
11+
restart: unless-stopped
12+
environment:
13+
MARIADB_ROOT_PASSWORD: root_lab_password
14+
MARIADB_DATABASE: snipeit
15+
MARIADB_USER: snipeit
16+
MARIADB_PASSWORD: snipeit_lab_password
17+
volumes:
18+
- snipeit-s01-db-data:/var/lib/mysql
19+
healthcheck:
20+
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
21+
interval: 15s
22+
timeout: 10s
23+
retries: 6
24+
start_period: 60s
25+
networks:
26+
- snipeit-s01-net
27+
28+
snipeit-s01-app:
629
image: snipe/snipe-it:latest
7-
container_name: it-stack-snipeit
30+
container_name: snipeit-s01-app
831
restart: unless-stopped
9-
ports:
10-
- "80:$firstPort"
32+
depends_on:
33+
snipeit-s01-db:
34+
condition: service_healthy
1135
environment:
12-
- IT_STACK_ENV=lab-01-standalone
36+
APP_ENV: local
37+
APP_DEBUG: "false"
38+
APP_KEY: "base64:3HLPbBKd9G4zWPKnQLxh4OTCKNWCGbSZFGbpfbpHPqk="
39+
APP_URL: "http://localhost:8401"
40+
DB_CONNECTION: mysql
41+
DB_HOST: snipeit-s01-db
42+
DB_PORT: 3306
43+
DB_DATABASE: snipeit
44+
DB_USERNAME: snipeit
45+
DB_PASSWORD: snipeit_lab_password
46+
DB_PREFIX: ""
47+
MAIL_DRIVER: log
48+
MAIL_PORT: 1025
49+
MAIL_ENCRYPTION: "null"
50+
SESSION_DRIVER: file
51+
CACHE_DRIVER: file
52+
ports:
53+
- "8401:80"
1354
volumes:
14-
- snipeit_data:/var/lib/snipeit
55+
- snipeit-s01-data:/var/lib/snipeit
1556
healthcheck:
1657
test: ["CMD-SHELL", "curl -sf http://localhost/health || exit 1"]
1758
interval: 30s
18-
timeout: 10s
19-
retries: 5
20-
start_period: 60s
59+
timeout: 15s
60+
retries: 8
61+
start_period: 120s
2162
networks:
22-
- it-stack-net
63+
- snipeit-s01-net
2364

2465
networks:
25-
it-stack-net:
66+
snipeit-s01-net:
2667
driver: bridge
2768

2869
volumes:
29-
snipeit_data:
70+
snipeit-s01-db-data:
71+
snipeit-s01-data:

tests/labs/test-lab-16-01.sh

Lines changed: 54 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,38 +26,69 @@ echo -e "${CYAN} Module: ${MODULE}${NC}"
2626
echo -e "${CYAN}======================================${NC}"
2727
echo ""
2828

29+
SNIPEIT_URL="http://localhost:8401"
30+
NO_CLEANUP=${NO_CLEANUP:-0}
31+
32+
cleanup() {
33+
if [ "${NO_CLEANUP}" = "1" ]; then
34+
info "NO_CLEANUP=1 — skipping teardown"
35+
else
36+
info "Phase 4: Cleanup"
37+
docker compose -f "${COMPOSE_FILE}" down -v --remove-orphans 2>/dev/null || true
38+
info "Cleanup complete"
39+
fi
40+
}
41+
trap cleanup EXIT
42+
43+
section() { echo -e "\n${CYAN}## $1${NC}"; }
44+
2945
# ── PHASE 1: Setup ────────────────────────────────────────────────────────────
30-
info "Phase 1: Setup"
46+
section "Phase 1: Setup"
3147
docker compose -f "${COMPOSE_FILE}" up -d
32-
info "Waiting 30s for ${MODULE} to initialize..."
33-
sleep 30
48+
info "Waiting 120s for Snipe-IT to initialize (MariaDB + Laravel seed)..."
49+
sleep 120
3450

3551
# ── PHASE 2: Health Checks ────────────────────────────────────────────────────
36-
info "Phase 2: Health Checks"
52+
section "Phase 2: Health Checks"
53+
54+
if docker compose -f "${COMPOSE_FILE}" ps snipeit-s01-db 2>/dev/null | grep -q 'Up\|running'; then
55+
pass "2.1 MariaDB (snipeit-s01-db) is up"
56+
else
57+
fail "2.1 MariaDB is not running"
58+
fi
3759

38-
if docker compose -f "${COMPOSE_FILE}" ps | grep -q "running\|Up"; then
39-
pass "Container is running"
60+
if docker compose -f "${COMPOSE_FILE}" ps snipeit-s01-app 2>/dev/null | grep -q 'Up\|running'; then
61+
pass "2.2 Snipe-IT app (snipeit-s01-app) is up"
4062
else
41-
fail "Container is not running"
63+
fail "2.2 Snipe-IT app is not running"
4264
fi
4365

4466
# ── PHASE 3: Functional Tests ─────────────────────────────────────────────────
45-
info "Phase 3: Functional Tests (Lab 01 — Standalone)"
46-
47-
# TODO: Add module-specific functional tests here
48-
# Example:
49-
# if curl -sf http://localhost:80/health > /dev/null 2>&1; then
50-
# pass "Health endpoint responds"
51-
# else
52-
# fail "Health endpoint not reachable"
53-
# fi
54-
55-
warn "Functional tests for Lab 16-01 pending implementation"
56-
57-
# ── PHASE 4: Cleanup ──────────────────────────────────────────────────────────
58-
info "Phase 4: Cleanup"
59-
docker compose -f "${COMPOSE_FILE}" down -v --remove-orphans
60-
info "Cleanup complete"
67+
section "Phase 3: Functional Tests"
68+
69+
# 3.1 Root URL responds
70+
HTTP_CODE=$(curl -o /dev/null -sw '%{http_code}' -L "${SNIPEIT_URL}/" 2>/dev/null || echo 000)
71+
if echo "${HTTP_CODE}" | grep -q '^[23]'; then
72+
pass "3.1 Snipe-IT web UI accessible (HTTP ${HTTP_CODE})"
73+
else
74+
fail "3.1 Snipe-IT web UI not accessible (HTTP ${HTTP_CODE})"
75+
fi
76+
77+
# 3.2 Response contains recognizable Snipe-IT content
78+
RESPONSE=$(curl -sfL "${SNIPEIT_URL}/" 2>/dev/null || echo '')
79+
if echo "${RESPONSE}" | grep -qi 'snipe\|laravel\|login\|asset'; then
80+
pass "3.2 Response contains Snipe-IT application content"
81+
else
82+
warn "3.2 Could not confirm Snipe-IT content in response (app may still be starting)"
83+
fi
84+
85+
# 3.3 Health endpoint
86+
HTTP_HEALTH=$(curl -o /dev/null -sw '%{http_code}' "${SNIPEIT_URL}/health" 2>/dev/null || echo 000)
87+
if echo "${HTTP_HEALTH}" | grep -q '^[23]'; then
88+
pass "3.3 Health endpoint responds (HTTP ${HTTP_HEALTH})"
89+
else
90+
warn "3.3 Health endpoint not available (HTTP ${HTTP_HEALTH}) — may not be implemented"
91+
fi
6192

6293
# ── Results ───────────────────────────────────────────────────────────────────
6394
echo ""

0 commit comments

Comments
 (0)