|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# End-to-end test for both JustRails8 flavors. |
| 4 | +# Builds from scratch and verifies each flavor serves a browsable website. |
| 5 | +# |
| 6 | +# Usage: |
| 7 | +# ./just-rails-8/test.sh # test both flavors |
| 8 | +# ./just-rails-8/test.sh vanilla # test vanilla only |
| 9 | +# ./just-rails-8/test.sh maglev # test maglev only |
| 10 | +# |
| 11 | + |
| 12 | +set -euo pipefail |
| 13 | + |
| 14 | +FLAVORS="${*:-vanilla maglev}" |
| 15 | +TIMEOUT=480 # 8 minutes for initial build + boot |
| 16 | + |
| 17 | +pass() { echo " ✓ $1"; } |
| 18 | +fail() { echo " ✗ $1"; docker compose logs; exit 1; } |
| 19 | + |
| 20 | +wait_for_http() { |
| 21 | + local deadline=$((SECONDS + TIMEOUT)) |
| 22 | + while [ $SECONDS -lt $deadline ]; do |
| 23 | + if curl -sf http://localhost:3008 -o /dev/null 2>/dev/null; then |
| 24 | + return 0 |
| 25 | + fi |
| 26 | + sleep 5 |
| 27 | + done |
| 28 | + return 1 |
| 29 | +} |
| 30 | + |
| 31 | +test_flavor() { |
| 32 | + local flavor=$1 |
| 33 | + echo "" |
| 34 | + echo "=== Testing $flavor flavor ===" |
| 35 | + |
| 36 | + ./just-rails-8/reset.sh --clean-untracked |
| 37 | + |
| 38 | + JR8_FLAVOR=$flavor docker compose up -d |
| 39 | + |
| 40 | + echo " Waiting for app (up to ${TIMEOUT}s)..." |
| 41 | + if wait_for_http; then |
| 42 | + pass "localhost:3008 is up" |
| 43 | + else |
| 44 | + fail "app never became available after ${TIMEOUT}s" |
| 45 | + fi |
| 46 | + |
| 47 | + STATUS=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:3008) |
| 48 | + [ "$STATUS" = "200" ] && pass "root page returns HTTP 200" || fail "root page returned HTTP $STATUS" |
| 49 | + |
| 50 | + if [ "$flavor" = "maglev" ]; then |
| 51 | + STATUS=$(curl -s -o /dev/null -w "%{http_code}" -L http://localhost:3008/maglev) |
| 52 | + { [ "$STATUS" = "200" ] || [ "$STATUS" = "302" ]; } \ |
| 53 | + && pass "Maglev editor accessible (HTTP $STATUS)" \ |
| 54 | + || fail "Maglev editor returned HTTP $STATUS" |
| 55 | + fi |
| 56 | + |
| 57 | + docker compose down -v |
| 58 | + ./just-rails-8/reset.sh --clean-untracked |
| 59 | + echo "=== $flavor: PASS ===" |
| 60 | +} |
| 61 | + |
| 62 | +for flavor in $FLAVORS; do |
| 63 | + test_flavor "$flavor" |
| 64 | +done |
| 65 | + |
| 66 | +echo "" |
| 67 | +echo "All flavor tests passed." |
0 commit comments