#!/bin/bash
TEST_DB_CONTAINER=rotini-test-ephemeral
FAILED=0
docker run \
--name $TEST_DB_CONTAINER \
-e POSTGRES_PASSWORD=test \
-p 5431:5432 \
-d \
postgres:15.4
until [ -n "$(docker exec $TEST_DB_CONTAINER pg_isready | grep accepting)" ]; do
echo "Waiting for DB to come alive..."
sleep 0.1;
done;
ROTINI_TEST=1 PYTHONPATH=rotini .venv/bin/python rotini/migrations/migrate.py up || (echo "Migrations failed." && FAILED=1)
ROTINI_TEST=1 .venv/bin/pytest . -vv -s || (echo "Test run failed." && FAILED=1)
docker rm $TEST_DB_CONTAINER -f > /dev/null || echo "Failed to clean up test database container."
if [ $FAILED -eq 1 ];
then
exit 1
fi