2011-10-05 23:49:54 +08:00
|
|
|
#!/bin/sh
|
2012-07-13 00:08:21 +08:00
|
|
|
|
|
|
|
# this script prepare database and redis instance to run acceptance test
|
|
|
|
#
|
|
|
|
# NOTE: assumes existance of a "template_postgis" loaded with
|
|
|
|
# compatible version of postgis (legacy.sql included)
|
|
|
|
|
2013-12-18 19:33:03 +08:00
|
|
|
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
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2012-07-13 00:08:21 +08:00
|
|
|
# This is where postgresql connection parameters are read from
|
|
|
|
TESTENV=../config/environments/test.js
|
|
|
|
|
|
|
|
# Extract postgres configuration
|
2013-11-18 20:31:11 +08:00
|
|
|
PGHOST=`node -e "console.log(require('${TESTENV}').db_host || '')"`
|
2012-07-13 00:08:21 +08:00
|
|
|
echo "PGHOST: [$PGHOST]"
|
2013-11-18 20:31:11 +08:00
|
|
|
PGPORT=`node -e "console.log(require('${TESTENV}').db_port || '')"`
|
2012-07-13 00:08:21 +08:00
|
|
|
echo "PGPORT: [$PGPORT]"
|
2013-11-18 20:31:11 +08:00
|
|
|
|
|
|
|
PUBLICUSER=`node -e "console.log(require('${TESTENV}').db_pubuser || 'xxx')"`
|
|
|
|
PUBLICPASS=`node -e "console.log(require('${TESTENV}').db_pubuser_pass || 'xxx')"`
|
|
|
|
echo "PUBLICUSER: [${PUBLICUSER}]"
|
|
|
|
echo "PUBLICPASS: [${PUBLICPASS}]"
|
2011-10-05 23:49:54 +08:00
|
|
|
|
2012-06-02 03:46:38 +08:00
|
|
|
|
2013-11-18 19:21:30 +08:00
|
|
|
TESTUSERID=1
|
2013-11-18 20:31:11 +08:00
|
|
|
|
|
|
|
TESTUSER=`node -e "console.log(require('${TESTENV}').db_user || '')"`
|
|
|
|
if test -z "$TESTUSER"; then
|
|
|
|
echo "Missing db_user from ${TESTENV}" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
TESTUSER=`echo ${TESTUSER} | sed "s/<%= user_id %>/${TESTUSERID}/"`
|
|
|
|
echo "TESTUSER: [${TESTUSER}]"
|
|
|
|
|
|
|
|
TESTPASS=`node -e "console.log(require('${TESTENV}').db_user_pass || '')"`
|
|
|
|
TESTPASS=`echo ${TESTPASS} | sed "s/<%= user_id %>/${TESTUSERID}/"`
|
|
|
|
echo "TESTPASS: [${TESTPASS}]"
|
|
|
|
|
|
|
|
TEST_DB=`node -e "console.log(require('${TESTENV}').db_base_name || '')"`
|
|
|
|
if test -z "$TEST_DB"; then
|
|
|
|
echo "Missing db_base_name from ${TESTENV}" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
TEST_DB=`echo ${TEST_DB} | sed "s/<%= user_id %>/${TESTUSERID}/"`
|
|
|
|
|
2012-07-13 00:08:21 +08:00
|
|
|
export PGHOST PGPORT
|
|
|
|
|
2013-12-18 19:33:03 +08:00
|
|
|
if test x"$PREPARE_PGSQL" = xyes; then
|
|
|
|
|
|
|
|
echo "preparing postgres..."
|
2014-06-04 00:33:40 +08:00
|
|
|
dropdb -U postgres ${TEST_DB} # 2> /dev/null # error expected if doesn't exist, but not otherwise
|
|
|
|
createdb -U postgres -Ttemplate_postgis -EUTF8 ${TEST_DB} || die "Could not create test database"
|
2013-12-18 19:33:03 +08:00
|
|
|
cat test.sql |
|
|
|
|
sed "s/:PUBLICUSER/${PUBLICUSER}/" |
|
|
|
|
sed "s/:PUBLICPASS/${PUBLICPASS}/" |
|
|
|
|
sed "s/:TESTUSER/${TESTUSER}/" |
|
|
|
|
sed "s/:TESTPASS/${TESTPASS}/" |
|
2014-06-04 00:49:29 +08:00
|
|
|
psql -U postgres -v ON_ERROR_STOP=1 ${TEST_DB} || exit 1
|
2012-06-02 03:46:38 +08:00
|
|
|
|
2013-12-18 19:33:03 +08:00
|
|
|
# TODO: send in a single run, togheter with test.sql
|
2014-06-04 00:49:29 +08:00
|
|
|
psql -U postgres -f support/CDB_QueryStatements.sql ${TEST_DB}
|
|
|
|
psql -U postgres -f support/CDB_QueryTables.sql ${TEST_DB}
|
2013-12-18 19:33:03 +08:00
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
if test x"$PREPARE_REDIS" = xyes; then
|
|
|
|
|
|
|
|
REDIS_PORT=`node -e "console.log(require('${TESTENV}').redis_port || '6336')"`
|
|
|
|
|
|
|
|
echo "preparing redis..."
|
|
|
|
|
2014-07-04 22:47:59 +08:00
|
|
|
# delete previous publicuser
|
|
|
|
cat <<EOF | redis-cli -p ${REDIS_PORT} -n 5
|
2014-07-04 23:01:58 +08:00
|
|
|
HDEL rails:users:vizzuality database_host
|
2014-07-04 22:47:59 +08:00
|
|
|
HDEL rails:users:vizzuality database_publicuser
|
|
|
|
EOF
|
|
|
|
|
2013-12-18 19:33:03 +08:00
|
|
|
cat <<EOF | redis-cli -p ${REDIS_PORT} -n 5
|
|
|
|
HMSET rails:users:vizzuality \
|
|
|
|
id 1 \
|
|
|
|
database_name ${TEST_DB} \
|
2014-07-04 23:01:58 +08:00
|
|
|
database_host localhost \
|
2013-12-18 19:33:03 +08:00
|
|
|
map_key 1234
|
|
|
|
SADD rails:users:vizzuality:map_key 1235
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# A user configured as with cartodb-2.5.0+
|
|
|
|
cat <<EOF | redis-cli -p ${REDIS_PORT} -n 5
|
|
|
|
HMSET rails:users:cartodb250user \
|
|
|
|
id ${TESTUSERID} \
|
|
|
|
database_name ${TEST_DB} \
|
|
|
|
database_host localhost \
|
|
|
|
database_password ${TESTPASS} \
|
|
|
|
map_key 1234
|
|
|
|
EOF
|
|
|
|
|
|
|
|
cat <<EOF | redis-cli -p ${REDIS_PORT} -n 3
|
|
|
|
HMSET rails:oauth_access_tokens:l0lPbtP68ao8NfStCiA3V3neqfM03JKhToxhUQTR \
|
|
|
|
consumer_key fZeNGv5iYayvItgDYHUbot1Ukb5rVyX6QAg8GaY2 \
|
|
|
|
consumer_secret IBLCvPEefxbIiGZhGlakYV4eM8AbVSwsHxwEYpzx \
|
|
|
|
access_token_token l0lPbtP68ao8NfStCiA3V3neqfM03JKhToxhUQTR \
|
|
|
|
access_token_secret 22zBIek567fMDEebzfnSdGe8peMFVFqAreOENaDK \
|
|
|
|
user_id 1 \
|
|
|
|
time sometime
|
|
|
|
EOF
|
|
|
|
|
|
|
|
fi
|
2012-07-13 00:08:21 +08:00
|
|
|
|
2011-10-05 23:49:54 +08:00
|
|
|
|
2012-06-02 04:00:45 +08:00
|
|
|
|
2011-10-05 23:49:54 +08:00
|
|
|
echo "ok, you can run test now"
|
|
|
|
|
|
|
|
|