2012-07-10 00:56:09 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
2013-12-05 18:07:12 +08:00
|
|
|
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
|
2015-03-23 21:05:29 +08:00
|
|
|
OPT_COVERAGE=no # run tests with coverage
|
2016-05-31 22:57:28 +08:00
|
|
|
OPT_DOWNLOAD_SQL=yes # download a fresh copy of sql files
|
2012-12-19 15:39:19 +08:00
|
|
|
|
2014-05-07 22:19:22 +08:00
|
|
|
export PGAPPNAME=cartodb_tiler_tester
|
|
|
|
|
2012-12-19 15:39:19 +08:00
|
|
|
cd $(dirname $0)
|
|
|
|
BASEDIR=$(pwd)
|
|
|
|
cd -
|
|
|
|
|
2013-09-12 16:17:02 +08:00
|
|
|
REDIS_PORT=`node -e "console.log(require('${BASEDIR}/config/environments/test.js').redis.port)"`
|
|
|
|
export REDIS_PORT
|
|
|
|
|
2012-07-10 00:56:09 +08:00
|
|
|
cleanup() {
|
2013-12-05 18:07:12 +08:00
|
|
|
if test x"$OPT_DROP_REDIS" = xyes; then
|
2012-12-19 15:39:19 +08:00
|
|
|
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
|
2015-09-23 23:18:58 +08:00
|
|
|
redis-cli -p ${REDIS_PORT} info stats
|
|
|
|
redis-cli -p ${REDIS_PORT} info keyspace
|
2013-12-05 18:07:12 +08:00
|
|
|
echo "Killing test redis pid ${PID_REDIS}"
|
2015-09-23 23:18:58 +08:00
|
|
|
#kill ${PID_REDIS_MONITOR}
|
2012-12-19 15:39:19 +08:00
|
|
|
kill ${PID_REDIS}
|
|
|
|
fi
|
2013-12-05 18:07:12 +08:00
|
|
|
if test x"$OPT_DROP_PGSQL" = xyes; then
|
|
|
|
# TODO: drop postgresql ?
|
|
|
|
echo "Dropping PostgreSQL test database isn't implemented yet"
|
|
|
|
fi
|
2012-07-10 00:56:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cleanup_and_exit() {
|
|
|
|
cleanup
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
|
|
|
die() {
|
|
|
|
msg=$1
|
|
|
|
echo "${msg}" >&2
|
|
|
|
cleanup
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
trap 'cleanup_and_exit' 1 2 3 5 9 13
|
|
|
|
|
2012-12-19 15:39:19 +08:00
|
|
|
while [ -n "$1" ]; do
|
2013-12-05 18:07:12 +08:00
|
|
|
# This is kept for backward compatibility
|
2012-12-19 15:39:19 +08:00
|
|
|
if test "$1" = "--nodrop"; then
|
2013-12-05 18:07:12 +08:00
|
|
|
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
|
2012-12-19 15:39:19 +08:00
|
|
|
shift
|
|
|
|
continue
|
2013-12-05 18:07:12 +08:00
|
|
|
elif test "$1" = "--nocreate-redis"; then
|
|
|
|
OPT_CREATE_REDIS=no
|
|
|
|
shift
|
|
|
|
continue
|
2016-05-31 22:57:28 +08:00
|
|
|
elif test "$1" = "--no-sql-download"; then
|
|
|
|
OPT_DOWNLOAD_SQL=no
|
|
|
|
shift
|
|
|
|
continue
|
2015-03-23 21:05:29 +08:00
|
|
|
elif test "$1" = "--with-coverage"; then
|
|
|
|
OPT_COVERAGE=yes
|
|
|
|
shift
|
|
|
|
continue
|
2013-12-05 18:07:12 +08:00
|
|
|
# This is kept for backward compatibility
|
2012-12-19 15:39:19 +08:00
|
|
|
elif test "$1" = "--nocreate"; then
|
2013-12-05 18:07:12 +08:00
|
|
|
OPT_CREATE_REDIS=no
|
|
|
|
OPT_CREATE_PGSQL=no
|
2012-12-19 15:39:19 +08:00
|
|
|
shift
|
|
|
|
continue
|
|
|
|
else
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
echo "Usage: $0 [<options>] <test> [<test>]" >&2
|
|
|
|
echo "Options:" >&2
|
|
|
|
echo " --nocreate do not create the test environment on start" >&2
|
|
|
|
echo " --nodrop do not drop the test environment on exit" >&2
|
2015-03-23 21:05:29 +08:00
|
|
|
echo " --with-coverage use istanbul to determine code coverage" >&2
|
2012-12-19 15:39:19 +08:00
|
|
|
exit 1
|
|
|
|
fi
|
2012-07-10 00:56:09 +08:00
|
|
|
|
2012-12-19 15:39:19 +08:00
|
|
|
TESTS=$@
|
|
|
|
|
2013-12-05 18:07:12 +08:00
|
|
|
if test x"$OPT_CREATE_REDIS" = xyes; then
|
2012-12-19 15:39:19 +08:00
|
|
|
echo "Starting redis on port ${REDIS_PORT}"
|
|
|
|
echo "port ${REDIS_PORT}" | redis-server - > ${BASEDIR}/test.log &
|
|
|
|
PID_REDIS=$!
|
|
|
|
echo ${PID_REDIS} > ${BASEDIR}/redis.pid
|
2013-12-05 18:07:12 +08:00
|
|
|
fi
|
2012-12-19 15:39:19 +08:00
|
|
|
|
2013-12-05 18:07:12 +08:00
|
|
|
PREPARE_DB_OPTS=
|
|
|
|
if test x"$OPT_CREATE_PGSQL" != xyes; then
|
|
|
|
PREPARE_DB_OPTS="$PREPARE_DB_OPTS --skip-pg"
|
2012-12-19 15:39:19 +08:00
|
|
|
fi
|
2013-12-05 18:07:12 +08:00
|
|
|
if test x"$OPT_CREATE_REDIS" != xyes; then
|
|
|
|
PREPARE_DB_OPTS="$PREPARE_DB_OPTS --skip-redis"
|
|
|
|
fi
|
2016-05-31 22:57:28 +08:00
|
|
|
if test x"$OPT_DOWNLOAD_SQL" != xyes; then
|
|
|
|
PREPARE_DB_OPTS="$PREPARE_DB_OPTS --no-sql-download"
|
|
|
|
fi
|
2013-12-05 18:07:12 +08:00
|
|
|
|
|
|
|
echo "Preparing the environment"
|
|
|
|
cd ${BASEDIR}/test/support
|
|
|
|
sh prepare_db.sh ${PREPARE_DB_OPTS} || die "database preparation failure"
|
|
|
|
cd -
|
2012-07-10 00:56:09 +08:00
|
|
|
|
|
|
|
PATH=node_modules/.bin/:$PATH
|
|
|
|
|
2015-09-23 23:18:58 +08:00
|
|
|
#redis-cli -p ${REDIS_PORT} monitor > /tmp/windshaft-cartodb.redis.log &
|
|
|
|
#PID_REDIS_MONITOR=$!
|
|
|
|
|
2015-03-23 21:05:29 +08:00
|
|
|
if test x"$OPT_COVERAGE" = xyes; then
|
|
|
|
echo "Running tests with coverage"
|
|
|
|
./node_modules/.bin/istanbul cover node_modules/.bin/_mocha -- -u tdd -t 5000 ${TESTS}
|
|
|
|
else
|
|
|
|
echo "Running tests"
|
|
|
|
mocha -u tdd -t 5000 ${TESTS}
|
|
|
|
fi
|
2013-04-12 00:31:01 +08:00
|
|
|
ret=$?
|
2012-07-10 00:56:09 +08:00
|
|
|
|
|
|
|
cleanup
|
2013-04-12 00:31:01 +08:00
|
|
|
|
|
|
|
exit $ret
|