Allow requesting run_test.sh to prepare redis but not postgresql

Adds --nocreate-pg, --nocreate-redis, --nodrop-pg, --nodrop-redis
NOTE that dropping pg is still unimplemented
This commit is contained in:
Sandro Santilli 2013-12-05 11:07:12 +01:00
parent 58af35fdea
commit e6b55ac034
2 changed files with 91 additions and 33 deletions

View File

@ -1,7 +1,9 @@
#!/bin/sh #!/bin/sh
OPT_CREATE=yes # create the test environment OPT_CREATE_REDIS=yes # create the redis test environment
OPT_DROP=yes # drop the test environment OPT_CREATE_PGSQL=yes # create the PostgreSQL test environment
OPT_DROP_REDIS=yes # drop the redis test environment
OPT_DROP_PGSQL=yes # drop the PostgreSQL test environment
cd $(dirname $0) cd $(dirname $0)
BASEDIR=$(pwd) BASEDIR=$(pwd)
@ -11,7 +13,7 @@ REDIS_PORT=`node -e "console.log(require('${BASEDIR}/config/environments/test.js
export REDIS_PORT export REDIS_PORT
cleanup() { cleanup() {
if test x"$OPT_DROP" = xyes; then if test x"$OPT_DROP_REDIS" = xyes; then
if test x"$PID_REDIS" = x; then if test x"$PID_REDIS" = x; then
PID_REDIS=$(cat ${BASEDIR}/redis.pid) PID_REDIS=$(cat ${BASEDIR}/redis.pid)
if test x"$PID_REDIS" = x; then if test x"$PID_REDIS" = x; then
@ -19,9 +21,13 @@ cleanup() {
return; return;
fi fi
fi fi
echo "Cleaning up" echo "Killing test redis pid ${PID_REDIS}"
kill ${PID_REDIS} kill ${PID_REDIS}
fi fi
if test x"$OPT_DROP_PGSQL" = xyes; then
# TODO: drop postgresql ?
echo "Dropping PostgreSQL test database isn't implemented yet"
fi
} }
cleanup_and_exit() { cleanup_and_exit() {
@ -39,12 +45,32 @@ die() {
trap 'cleanup_and_exit' 1 2 3 5 9 13 trap 'cleanup_and_exit' 1 2 3 5 9 13
while [ -n "$1" ]; do while [ -n "$1" ]; do
# This is kept for backward compatibility
if test "$1" = "--nodrop"; then if test "$1" = "--nodrop"; then
OPT_DROP=no OPT_DROP_REDIS=no
OPT_DROP_PGSQL=no
shift shift
continue continue
elif test "$1" = "--nodrop-pg"; then
OPT_DROP_PGSQL=no
shift
continue
elif test "$1" = "--nodrop-redis"; then
OPT_DROP_REDIS=no
shift
continue
elif test "$1" = "--nocreate-pg"; then
OPT_CREATE_PGSQL=no
shift
continue
elif test "$1" = "--nocreate-redis"; then
OPT_CREATE_REDIS=no
shift
continue
# This is kept for backward compatibility
elif test "$1" = "--nocreate"; then elif test "$1" = "--nocreate"; then
OPT_CREATE=no OPT_CREATE_REDIS=no
OPT_CREATE_PGSQL=no
shift shift
continue continue
else else
@ -62,16 +88,26 @@ fi
TESTS=$@ TESTS=$@
if test x"$OPT_CREATE" = xyes; then if test x"$OPT_CREATE_REDIS" = xyes; then
echo "Starting redis on port ${REDIS_PORT}" echo "Starting redis on port ${REDIS_PORT}"
echo "port ${REDIS_PORT}" | redis-server - > ${BASEDIR}/test.log & echo "port ${REDIS_PORT}" | redis-server - > ${BASEDIR}/test.log &
PID_REDIS=$! PID_REDIS=$!
echo ${PID_REDIS} > ${BASEDIR}/redis.pid echo ${PID_REDIS} > ${BASEDIR}/redis.pid
echo "Preparing the environment"
cd ${BASEDIR}/test/support; sh prepare_db.sh || die "database preparation failure"; cd -
fi fi
PREPARE_DB_OPTS=
if test x"$OPT_CREATE_PGSQL" != xyes; then
PREPARE_DB_OPTS="$PREPARE_DB_OPTS --skip-pg"
fi
if test x"$OPT_CREATE_REDIS" != xyes; then
PREPARE_DB_OPTS="$PREPARE_DB_OPTS --skip-redis"
fi
echo "Preparing the environment"
cd ${BASEDIR}/test/support
sh prepare_db.sh ${PREPARE_DB_OPTS} || die "database preparation failure"
cd -
PATH=node_modules/.bin/:$PATH PATH=node_modules/.bin/:$PATH
echo "Running tests" echo "Running tests"

View File

@ -10,6 +10,19 @@
# TODO: fix that # TODO: fix that
# #
PREPARE_REDIS=yes
PREPARE_PGSQL=yes
while [ -n "$1" ]; do
if test "$1" = "--skip-pg"; then
PREPARE_PGSQL=no
shift; continue
elif test "$1" = "--skip-redis"; then
PREPARE_REDIS=no
shift; continue
fi
done
die() { die() {
msg=$1 msg=$1
echo "${msg}" >&2 echo "${msg}" >&2
@ -42,12 +55,9 @@ TESTPASS=`echo ${TESTPASS} | sed "s/<%= user_id %>/${TESTUSERID}/"`
TEST_DB="${TESTUSER}_db" TEST_DB="${TESTUSER}_db"
# NOTE: will be set by caller trough environment
if test -z "$REDIS_PORT"; then REDIS_PORT=6333; fi if test -z "$REDIS_PORT"; then REDIS_PORT=6333; fi
echo "preparing postgres..."
dropdb "${TEST_DB}"
createdb -Ttemplate_postgis -EUTF8 "${TEST_DB}" || die "Could not create test database"
PUBLICUSER=`node -e "console.log(require('${TESTENV}').postgres.user || 'xxx')"` PUBLICUSER=`node -e "console.log(require('${TESTENV}').postgres.user || 'xxx')"`
PUBLICPASS=`node -e "console.log(require('${TESTENV}').postgres.password || 'xxx')"` PUBLICPASS=`node -e "console.log(require('${TESTENV}').postgres.password || 'xxx')"`
echo "PUBLICUSER: ${PUBLICUSER}" echo "PUBLICUSER: ${PUBLICUSER}"
@ -55,28 +65,40 @@ echo "PUBLICPASS: ${PUBLICPASS}"
echo "TESTUSER: ${TESTUSER}" echo "TESTUSER: ${TESTUSER}"
echo "TESTPASS: ${TESTPASS}" echo "TESTPASS: ${TESTPASS}"
cat sql/windshaft.test.sql sql/gadm4.sql | if test x"$PREPARE_PGSQL" = xyes; then
echo "preparing postgres..."
dropdb "${TEST_DB}"
createdb -Ttemplate_postgis -EUTF8 "${TEST_DB}" || die "Could not create test database"
cat sql/windshaft.test.sql sql/gadm4.sql |
sed "s/:PUBLICUSER/${PUBLICUSER}/" | sed "s/:PUBLICUSER/${PUBLICUSER}/" |
sed "s/:PUBLICPASS/${PUBLICPASS}/" | sed "s/:PUBLICPASS/${PUBLICPASS}/" |
sed "s/:TESTUSER/${TESTUSER}/" | sed "s/:TESTUSER/${TESTUSER}/" |
sed "s/:TESTPASS/${TESTPASS}/" | sed "s/:TESTPASS/${TESTPASS}/" |
psql ${TEST_DB} psql ${TEST_DB}
echo "preparing redis..." fi
echo "HSET rails:users:localhost id ${TESTUSERID}" | redis-cli -p ${REDIS_PORT} -n 5
echo 'HSET rails:users:localhost database_name "'"${TEST_DB}"'"' | redis-cli -p ${REDIS_PORT} -n 5
echo "HSET rails:users:localhost map_key 1234" | redis-cli -p ${REDIS_PORT} -n 5
echo "SADD rails:users:localhost:map_key 1235" | redis-cli -p ${REDIS_PORT} -n 5
# A user configured as with cartodb-2.5.0+ if test x"$PREPARE_REDIS" = xyes; then
echo "HSET rails:users:cartodb250user id ${TESTUSERID}" | redis-cli -p ${REDIS_PORT} -n 5
echo 'HSET rails:users:cartodb250user database_name "'${TEST_DB}'"' | redis-cli -p ${REDIS_PORT} -n 5
echo 'HSET rails:users:cartodb250user database_host "localhost"' | redis-cli -p ${REDIS_PORT} -n 5
echo 'HSET rails:users:cartodb250user database_password "'${TESTPASS}'"' | redis-cli -p ${REDIS_PORT} -n 5
echo "HSET rails:users:cartodb250user map_key 4321" | redis-cli -p ${REDIS_PORT} -n 5
echo 'HSET rails:'"${TEST_DB}"':my_table infowindow "this, that, the other"' | redis-cli -p ${REDIS_PORT} -n 0 echo "preparing redis..."
echo 'HSET rails:'"${TEST_DB}"':test_table_private_1 privacy "0"' | redis-cli -p ${REDIS_PORT} -n 0 echo "HSET rails:users:localhost id ${TESTUSERID}" | redis-cli -p ${REDIS_PORT} -n 5
echo 'HSET rails:users:localhost database_name "'"${TEST_DB}"'"' | redis-cli -p ${REDIS_PORT} -n 5
echo "HSET rails:users:localhost map_key 1234" | redis-cli -p ${REDIS_PORT} -n 5
echo "SADD rails:users:localhost:map_key 1235" | redis-cli -p ${REDIS_PORT} -n 5
# A user configured as with cartodb-2.5.0+
echo "HSET rails:users:cartodb250user id ${TESTUSERID}" | redis-cli -p ${REDIS_PORT} -n 5
echo 'HSET rails:users:cartodb250user database_name "'${TEST_DB}'"' | redis-cli -p ${REDIS_PORT} -n 5
echo 'HSET rails:users:cartodb250user database_host "localhost"' | redis-cli -p ${REDIS_PORT} -n 5
echo 'HSET rails:users:cartodb250user database_password "'${TESTPASS}'"' | redis-cli -p ${REDIS_PORT} -n 5
echo "HSET rails:users:cartodb250user map_key 4321" | redis-cli -p ${REDIS_PORT} -n 5
echo 'HSET rails:'"${TEST_DB}"':my_table infowindow "this, that, the other"' | redis-cli -p ${REDIS_PORT} -n 0
echo 'HSET rails:'"${TEST_DB}"':test_table_private_1 privacy "0"' | redis-cli -p ${REDIS_PORT} -n 0
fi
echo "Finished preparing data. Ready to run tests" echo "Finished preparing data. Ready to run tests"