Permalink
Browse files

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
  • Loading branch information...
1 parent 58af35f commit e6b55ac034a595f97bdd988ab1ab03ded942ccb6 Sandro Santilli committed Dec 5, 2013
Showing with 93 additions and 35 deletions.
  1. +45 −9 run_tests.sh
  2. +48 −26 test/support/prepare_db.sh
View
@@ -1,7 +1,9 @@
#!/bin/sh
-OPT_CREATE=yes # create the test environment
-OPT_DROP=yes # drop the test environment
+OPT_CREATE_REDIS=yes # create the redis 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)
BASEDIR=$(pwd)
@@ -11,17 +13,21 @@ REDIS_PORT=`node -e "console.log(require('${BASEDIR}/config/environments/test.js
export REDIS_PORT
cleanup() {
- if test x"$OPT_DROP" = xyes; then
+ if test x"$OPT_DROP_REDIS" = xyes; then
if test x"$PID_REDIS" = x; then
PID_REDIS=$(cat ${BASEDIR}/redis.pid)
if test x"$PID_REDIS" = x; then
echo "Could not find a test redis pid to kill it"
return;
fi
fi
- echo "Cleaning up"
+ echo "Killing test redis pid ${PID_REDIS}"
kill ${PID_REDIS}
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() {
@@ -39,12 +45,32 @@ die() {
trap 'cleanup_and_exit' 1 2 3 5 9 13
while [ -n "$1" ]; do
+ # This is kept for backward compatibility
if test "$1" = "--nodrop"; then
- OPT_DROP=no
+ OPT_DROP_REDIS=no
+ OPT_DROP_PGSQL=no
+ shift
+ 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
- OPT_CREATE=no
+ OPT_CREATE_REDIS=no
+ OPT_CREATE_PGSQL=no
shift
continue
else
@@ -62,15 +88,25 @@ fi
TESTS=$@
-if test x"$OPT_CREATE" = xyes; then
+if test x"$OPT_CREATE_REDIS" = xyes; then
echo "Starting redis on port ${REDIS_PORT}"
echo "port ${REDIS_PORT}" | redis-server - > ${BASEDIR}/test.log &
PID_REDIS=$!
echo ${PID_REDIS} > ${BASEDIR}/redis.pid
+fi
- echo "Preparing the environment"
- cd ${BASEDIR}/test/support; sh prepare_db.sh || die "database preparation failure"; cd -
+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
View
@@ -10,6 +10,19 @@
# 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() {
msg=$1
echo "${msg}" >&2
@@ -42,41 +55,50 @@ TESTPASS=`echo ${TESTPASS} | sed "s/<%= user_id %>/${TESTUSERID}/"`
TEST_DB="${TESTUSER}_db"
+# NOTE: will be set by caller trough environment
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')"`
PUBLICPASS=`node -e "console.log(require('${TESTENV}').postgres.password || 'xxx')"`
echo "PUBLICUSER: ${PUBLICUSER}"
echo "PUBLICPASS: ${PUBLICPASS}"
echo "TESTUSER: ${TESTUSER}"
echo "TESTPASS: ${TESTPASS}"
-cat sql/windshaft.test.sql sql/gadm4.sql |
- sed "s/:PUBLICUSER/${PUBLICUSER}/" |
- sed "s/:PUBLICPASS/${PUBLICPASS}/" |
- sed "s/:TESTUSER/${TESTUSER}/" |
- sed "s/:TESTPASS/${TESTPASS}/" |
- psql ${TEST_DB}
-
-echo "preparing redis..."
-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
+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/:PUBLICPASS/${PUBLICPASS}/" |
+ sed "s/:TESTUSER/${TESTUSER}/" |
+ sed "s/:TESTPASS/${TESTPASS}/" |
+ psql ${TEST_DB}
+
+fi
+
+if test x"$PREPARE_REDIS" = xyes; then
+
+ echo "preparing redis..."
+ 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"

0 comments on commit e6b55ac

Please sign in to comment.