deckhand/tools/unit-tests.sh
Felipe Monteiro 2f0d5796e3 Revert fix pifpaf run postgresql failing
This reverts https://review.gerrithub.io/#/c/393980/ which was
a temporary workaround to unblock the Deckhand gate. pifpaf should
be used to run unit tests as having to install Docker just to kick
off unit tests is excessive.

However, the unit-tests.sh script is maintained in tools/ directory
as a fallback.

Change-Id: I24a10d4b3ea00006004f27d0086719fb0bf86dd9
2018-01-12 11:57:44 -04:00

41 lines
897 B
Bash
Executable File

#!/usr/bin/env bash
# Script for setting up temporary PostgreSQL database for testing unit tests
# against. Requires Docker CE (at least) to be executed. Fallback in case
# `pifpaf` fails.
function cleanup {
sudo docker stop $POSTGRES_ID
}
trap cleanup EXIT
POSTGRES_ID=$(
sudo docker run \
--detach \
--publish :5432 \
-e POSTGRES_DB=deckhand \
-e POSTGRES_USER=$(whoami) \
-e POSTGRES_PASSWORD=password \
postgres:9.5
)
POSTGRES_IP=$(
sudo docker inspect \
--format='{{ .NetworkSettings.Networks.bridge.IPAddress }}' \
$POSTGRES_ID
)
# Used by unit tests to interact with DB.
export DATABASE_URL=postgresql+psycopg2://$(whoami):password@$POSTGRES_IP:5432/deckhand
set -e
posargs=$@
if [ ${#posargs} -ge 1 ]; then
ostestr --concurrency 1 --regex ${posargs}
else
ostestr --concurrency 1
fi
set +e