fix tests and properly intgrate sqlx
Some checks failed
Backend Actions / check (push) Failing after 3m26s
Frontend Actions / check (push) Failing after 3m17s
Backend Actions / test (push) Failing after 3m20s
Frontend Actions / test (push) Successful in 51s
Frontend Actions / build (push) Successful in 56s
Backend Actions / build (push) Failing after 10m57s

This commit is contained in:
2025-08-01 15:21:39 +01:00
parent 6ec6aa2aa7
commit c96b2adada
23 changed files with 963 additions and 25 deletions

View File

@ -8,13 +8,26 @@ if ! command -v cargo-nextest > /dev/null 2>&1; then
exit 1
fi
psql "$POSTGRES_URL" -f ./scripts/create_test_db.sql
if [ "$?" -ne "0" ]; then
echo "Unable to connect to database, make sure it is started"
if ! command -v sqlx > /dev/null 2>&1; then
echo "Command not found sqlx"
echo "Try installing with cargo install sqlx-cli"
exit 1
fi
export DATABASE_URL="$POSTGRES_URL/nuchat_dev"
if [ -z "$SKIP_DOCKER" ]; then
# force restart database so no connections
# prevent database from being dropped
docker compose -f ../docker-compose.yml down
docker compose -f ../docker-compose.yml up -d db
sleep 1
fi
# recreate database and tables
sqlx database drop -y
sqlx database create
sqlx migrate run
if [ ! -d logs ]; then
mkdir logs
@ -24,7 +37,8 @@ fi
curl -s -X POST localhost:7001/admin/shutdown 2>&1 > /dev/null
# start server
cargo run -- --port 7001 --postgres-url "$POSTGRES_URL" 2>&1 > logs/nuchat.log &
cargo run -- --port 7001 --postgres-url "$POSTGRES_URL" --database "nuchat_dev" 2>&1 > logs/nuchat.log &
sleep 1
# run tests
cargo nextest run --color=always 2>&1 | tee logs/test-output.log
cargo nextest run --color=always --no-fail-fast 2>&1 | tee logs/test-output.log