postgresqlUnitTests.sh 1.64 KB
Newer Older
1
2
3
4
#!/bin/bash

# Utility script to run postgresql tests like in CI.

5
6
if ! rpm -q --quiet rh-postgresql12-postgresql-server; then
  echo "Please install the package rh-postgresql12-postgresql-server to run this script."
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  exit 1
fi

if [[ !  ( -x ./catalogue/cta-catalogue-schema-create && -x ./tests/cta-rdbmsUnitTests ) ]]; then
  echo "Please run this script from a build tree of CTA."
  exit 1
fi

if [[ $(id -u) != "0" ]]; then
  echo "Please run this script as root (sudo)."
  exit 1;
fi

POSTGRESQL_DATA_DIR=/usr/local/cta_test_pgsql_data
POSTGRESQL_LOG_DIR=/var/log/postgres
echo POSTGRESQL_DATA_DIR=${POSTGRESQL_DATA_DIR}
echo POSTGRESQL_LOG_DIR=${POSTGRESQL_LOG_DIR}
mkdir -p ${POSTGRESQL_DATA_DIR}
chown -R postgres:postgres ${POSTGRESQL_DATA_DIR}
mkdir -p ${POSTGRESQL_LOG_DIR}
chown -R postgres:postgres ${POSTGRESQL_LOG_DIR}
28
29
export LD_LIBRARY_PATH=/opt/rh/rh-postgresql12/root/usr/lib64
POSTGRES_BIN=/opt/rh/rh-postgresql12/root/usr/bin
30
31
32
33
34
35
36
37
38
39
40
41
42
echo POSTGRES_BIN=${POSTGRES_BIN}
(cd / ; 
runuser -u postgres -- ${POSTGRES_BIN}/initdb -D ${POSTGRESQL_DATA_DIR}
runuser -u postgres -- ${POSTGRES_BIN}/pg_ctl start -w -t 10 -D ${POSTGRESQL_DATA_DIR} -l ${POSTGRESQL_LOG_DIR}/cta_test_postgres.log
runuser -u postgres -- ${POSTGRES_BIN}/createdb cta
runuser -u postgres -- ${POSTGRES_BIN}/createuser -E cta
)
CTA_CATALOGUE_CONF=`mktemp`
echo CTA_CATALOGUE_CONF=${CTA_CATALOGUE_CONF}
echo 'postgresql:postgresql://cta@localhost/cta' > ${CTA_CATALOGUE_CONF}
./catalogue/cta-catalogue-schema-create ${CTA_CATALOGUE_CONF}
./tests/cta-rdbmsUnitTests ${CTA_CATALOGUE_CONF}
(cd / ; runuser -u postgres -- ${POSTGRES_BIN}/pg_ctl stop -D ${POSTGRESQL_DATA_DIR})
43
rm -rf ${POSTGRESQL_DATA_DIR}