97 lines
2.9 KiB
Bash
Executable File
97 lines
2.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
cd "${repo_root}"
|
|
|
|
readonly source_files=(
|
|
backend/app/frontend/miner_detail_view.py
|
|
backend/app/frontend/monitoring_trends_view.py
|
|
backend/app/frontend/static/app.css
|
|
backend/app/frontend/static/miner-detail.js
|
|
backend/app/frontend/static/monitoring-trends.css
|
|
backend/app/frontend/static/monitoring-trends.js
|
|
backend/app/frontend/views.py
|
|
backend/app/identity.py
|
|
backend/app/main.py
|
|
backend/app/monitoring/__init__.py
|
|
backend/app/monitoring/dependencies.py
|
|
backend/app/monitoring/exceptions.py
|
|
backend/app/monitoring/frontend.py
|
|
backend/app/monitoring/models.py
|
|
backend/app/monitoring/repository.py
|
|
backend/app/monitoring/router.py
|
|
backend/app/monitoring/service.py
|
|
backend/tests/test_monitoring_trends.py
|
|
)
|
|
|
|
for file in "${source_files[@]}"; do
|
|
if [[ ! -r "${file}" ]]; then
|
|
echo "Monitoring Trends test input is not readable: ${file}" >&2
|
|
exit 1
|
|
fi
|
|
if [[ "$(stat -c '%a' "${file}")" != "644" ]]; then
|
|
echo "Monitoring Trends source/test mode must be 0644: ${file}" >&2
|
|
exit 1
|
|
fi
|
|
done
|
|
if [[ ! -x scripts/test-monitoring-trends.sh ]] \
|
|
|| [[ "$(stat -c '%a' scripts/test-monitoring-trends.sh)" != "755" ]]; then
|
|
echo "scripts/test-monitoring-trends.sh must be executable with mode 0755." >&2
|
|
exit 1
|
|
fi
|
|
echo "Monitoring Trends file-mode preflight passed."
|
|
|
|
if [[ ! -f .env.dev ]]; then
|
|
echo "Missing .env.dev. Run ./scripts/dev-env-init.sh first." >&2
|
|
exit 1
|
|
fi
|
|
|
|
project_name="${MINEROPS_MONITORING_TEST_PROJECT:-minerops-monitoring-$$}"
|
|
compose=(
|
|
docker compose
|
|
--project-name "${project_name}"
|
|
--env-file .env.dev
|
|
-f compose.dev.yaml
|
|
)
|
|
|
|
cleanup() {
|
|
status=$?
|
|
if (( status != 0 )); then
|
|
echo
|
|
echo "Monitoring Trends tests failed. Recent PostgreSQL logs:"
|
|
"${compose[@]}" logs --no-color --tail 120 postgres || true
|
|
fi
|
|
"${compose[@]}" down --volumes --remove-orphans >/dev/null 2>&1 || true
|
|
exit "${status}"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
echo "Starting disposable Monitoring Trends database..."
|
|
"${compose[@]}" up --detach postgres
|
|
for attempt in $(seq 1 60); do
|
|
if "${compose[@]}" exec -T postgres sh -ec \
|
|
'pg_isready -U "$POSTGRES_USER" -d "$POSTGRES_DB"' >/dev/null 2>&1; then
|
|
break
|
|
fi
|
|
if (( attempt == 60 )); then
|
|
echo "PostgreSQL did not become ready." >&2
|
|
exit 1
|
|
fi
|
|
sleep 1
|
|
done
|
|
|
|
echo "Building Monitoring Trends test image..."
|
|
"${compose[@]}" build backend
|
|
"${compose[@]}" run --rm --no-deps backend alembic upgrade head
|
|
|
|
echo "Running Monitoring Trends focused tests..."
|
|
"${compose[@]}" run --rm --no-deps \
|
|
-v "${repo_root}/backend/tests:/app/tests:ro" \
|
|
backend python -m unittest -v \
|
|
tests.test_monitoring_trends \
|
|
tests.test_miner_detail \
|
|
tests.test_frontend_shell
|
|
|
|
echo "Monitoring Trends focused tests passed."
|