refactor(backend): standardize errors and simplify configuration and test setup

This commit is contained in:
TakuyaYagam1 committed 2026-10-05 16:15:30 +03:00
1 parent 1535c19b8c
commit 138666a7bb
92 files changed
+3994 -210

No files matched your search

+52 -11
View File
@@ -7,7 +7,6 @@ env_file="$root/.env.example"
project=lincodex-smoke
app_network="${project}_default"
port=18080
volume="${project}_postgres_data"
network="${project}_default"
started=0
@@ -19,10 +18,12 @@ compose() {
"$@"
}
if docker volume inspect "$volume" >/dev/null 2>&1; then
printf 'Refusing to use existing smoke volume %s.\n' "$volume" >&2
exit 2
fi
for volume in "${project}_postgres_data" "${project}_seaweedfs_data"; do
if docker volume inspect "$volume" >/dev/null 2>&1; then
printf 'Refusing to use existing smoke volume %s.\n' "$volume" >&2
exit 2
fi
done
if docker network inspect "$network" >/dev/null 2>&1; then
printf 'Refusing to use existing smoke network %s.\n' "$network" >&2
exit 2
@@ -68,17 +69,57 @@ wait_for() {
return 1
}
wait_for_readiness() {
local attempt response
for attempt in {1..30}; do
response=$(compose exec -T frontend wget -q -O - http://backend:8080/readyz 2>/dev/null || true)
if [[ "$response" == '{"status":"ready"}' ]]; then
return 0
fi
sleep 1
done
printf '%s\n' 'Timed out waiting for PostgreSQL, Redis, and SeaweedFS readiness.' >&2
return 1
}
wait_for "http://127.0.0.1:$port/healthz"
wait_for "http://127.0.0.1:$port/api/v1/healthz"
readiness=$(compose exec -T frontend wget -q -O - http://backend:8080/readyz)
if [[ "$readiness" != '{"status":"ready"}' ]]; then
printf 'Backend did not confirm database readiness: %s\n' "$readiness" >&2
exit 1
fi
wait_for_readiness
status=$(curl --silent --show-error --output /dev/null --write-out '%{http_code}' \
"http://127.0.0.1:$port/api/v1/missing")
if [[ "$status" != 404 ]]; then
printf 'Unknown API route returned %s instead of 404.\n' "$status" >&2
exit 1
fi
printf '%s\n' 'Technical smoke passed: frontend, API routing, and PostgreSQL readiness.'
compose exec -T redis sh -ec '
test "$(redis-cli ping)" = "NOAUTH Authentication required."
export REDISCLI_AUTH="$REDIS_PASSWORD"
test "$(redis-cli ping)" = PONG
test "$(redis-cli --raw CONFIG GET maxmemory-policy | tail -n 1)" = allkeys-lru
test "$(redis-cli --raw CONFIG GET appendonly | tail -n 1)" = no
test -z "$(redis-cli --raw CONFIG GET save | tail -n 1)"
'
compose stop redis
readiness=$(compose exec -T frontend wget -S -O /dev/null http://backend:8080/readyz 2>&1 || true)
if [[ "$readiness" != *"503 Service Unavailable"* ]]; then
printf 'Backend did not return 503 when Redis stopped: %s\n' "$readiness" >&2
exit 1
fi
curl --fail --silent --show-error "http://127.0.0.1:$port/api/v1/healthz" >/dev/null
compose up -d --wait --wait-timeout 60 redis
wait_for_readiness
anonymous=$(compose exec -T seaweedfs sh -c 'wget -S -O /dev/null "http://127.0.0.1:8333/$S3_BUCKET"' 2>&1 || true)
if [[ "$anonymous" != *"403 Forbidden"* ]]; then
printf 'SeaweedFS did not reject anonymous bucket access: %s\n' "$anonymous" >&2
exit 1
fi
compose stop seaweedfs
readiness=$(compose exec -T frontend wget -S -O /dev/null http://backend:8080/readyz 2>&1 || true)
if [[ "$readiness" != *"503 Service Unavailable"* ]]; then
printf 'Backend did not return 503 when SeaweedFS stopped: %s\n' "$readiness" >&2
exit 1
fi
curl --fail --silent --show-error "http://127.0.0.1:$port/api/v1/healthz" >/dev/null
compose up -d --wait --wait-timeout 90 seaweedfs
wait_for_readiness
printf '%s\n' 'Technical smoke passed: frontend, API routing, PostgreSQL, Redis, SeaweedFS, dependency recovery, and storage authentication.'