2023-07-24 15:14:13 +03:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2024-05-27 18:46:15 +03:00
|
|
|
# Determine available docker binary
|
|
|
|
_docker=$(command -v 'podman') || \
|
|
|
|
_docker=$(command -v 'docker') || \
|
|
|
|
{ echo 'docker not found'; exit 1; }
|
|
|
|
|
2023-08-08 14:26:34 +03:00
|
|
|
# Ensure test args are set.
|
|
|
|
ARGS=${@}; [ -z "$ARGS" ] && \
|
|
|
|
ARGS='./...'
|
|
|
|
|
|
|
|
# Database config.
|
2023-07-24 15:14:13 +03:00
|
|
|
DB_NAME='postgres'
|
|
|
|
DB_USER='postgres'
|
|
|
|
DB_PASS='postgres'
|
2024-05-27 18:46:15 +03:00
|
|
|
DB_IP='127.0.0.1'
|
2023-07-24 15:14:13 +03:00
|
|
|
DB_PORT=5432
|
|
|
|
|
|
|
|
# Start postgres container
|
2024-05-27 18:46:15 +03:00
|
|
|
CID=$($_docker run --detach \
|
|
|
|
--publish "${DB_IP}:${DB_PORT}:${DB_PORT}" \
|
2023-07-24 15:14:13 +03:00
|
|
|
--env "POSTGRES_DB=${DB_NAME}" \
|
|
|
|
--env "POSTGRES_USER=${DB_USER}" \
|
|
|
|
--env "POSTGRES_PASSWORD=${DB_PASS}" \
|
|
|
|
--env "POSTGRES_HOST_AUTH_METHOD=trust" \
|
|
|
|
--env "PGHOST=0.0.0.0" \
|
|
|
|
--env "PGPORT=${DB_PORT}" \
|
2024-05-27 18:46:15 +03:00
|
|
|
'docker.io/postgres:latest')
|
2023-07-24 15:14:13 +03:00
|
|
|
|
|
|
|
# On exit kill the container
|
2024-05-27 18:46:15 +03:00
|
|
|
trap "$_docker kill ${CID}" exit
|
2023-07-24 15:14:13 +03:00
|
|
|
|
|
|
|
sleep 5
|
|
|
|
#docker exec "$CID" psql --user "$DB_USER" --password "$DB_PASS" -c "CREATE DATABASE \"${DB_NAME}\" WITH LOCALE \"C.UTF-8\" TEMPLATE \"template0\";"
|
2024-05-27 18:46:15 +03:00
|
|
|
$_docker exec "$CID" psql --user "$DB_USER" --password "$DB_PASS" -c "GRANT ALL PRIVILEGES ON DATABASE \"${DB_NAME}\" TO \"${DB_USER}\";"
|
2023-07-24 15:14:13 +03:00
|
|
|
|
2024-05-27 18:46:15 +03:00
|
|
|
env \
|
2023-07-24 15:14:13 +03:00
|
|
|
GTS_DB_TYPE=postgres \
|
2024-05-27 18:46:15 +03:00
|
|
|
GTS_DB_ADDRESS=${DB_IP} \
|
2023-07-24 15:14:13 +03:00
|
|
|
GTS_DB_PORT=${DB_PORT} \
|
|
|
|
GTS_DB_USER=${DB_USER} \
|
|
|
|
GTS_DB_PASSWORD=${DB_PASS} \
|
|
|
|
GTS_DB_DATABASE=${DB_NAME} \
|
2024-05-27 18:46:15 +03:00
|
|
|
go test -p 1 ${ARGS}
|