2011-10-20 22:44:37 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# this script prepare database and redis instance to run accpetance test
|
2012-07-04 01:31:30 +08:00
|
|
|
#
|
|
|
|
# NOTE: assumes existance of a "template_postgis"
|
|
|
|
# NOTE2: use PG* environment variables to control who and where
|
2012-07-09 21:50:23 +08:00
|
|
|
#
|
|
|
|
# NOTE3: a side effect of the db preparation is the persistent creation
|
|
|
|
# of two database roles which will be valid for the whole cluster
|
|
|
|
# TODO: fix that
|
|
|
|
#
|
2012-07-04 01:31:30 +08:00
|
|
|
|
|
|
|
die() {
|
|
|
|
msg=$1
|
|
|
|
echo "${msg}" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
2011-10-20 22:44:37 +08:00
|
|
|
|
2013-11-11 07:50:03 +08:00
|
|
|
# This is where postgresql connection parameters are read from
|
|
|
|
TESTENV=../../config/environments/test.js
|
|
|
|
if [ \! -r ${TESTENV} ]; then
|
|
|
|
echo "Cannot read ${TESTENV}" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
TESTUSERID=1
|
|
|
|
|
|
|
|
TESTUSER=`node -e "console.log(require('${TESTENV}').postgres_auth_user || '')"`
|
|
|
|
if test -z "$TESTUSER"; then
|
|
|
|
echo "Missing postgres_auth_user from ${TESTENV}" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
TESTUSER=`echo ${TESTUSER} | sed "s/<%= user_id %>/${TESTUSERID}/"`
|
|
|
|
|
|
|
|
TESTPASS=`node -e "console.log(require('${TESTENV}').postgres_auth_pass || 'test')"`
|
|
|
|
# TODO: should postgres_auth_pass be optional ?
|
|
|
|
if test -z "$TESTPASS"; then
|
|
|
|
echo "Missing postgres_auth_pass from ${TESTENV}" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
TESTPASS=`echo ${TESTPASS} | sed "s/<%= user_id %>/${TESTUSERID}/"`
|
|
|
|
|
|
|
|
TEST_DB="${TESTUSER}_db"
|
|
|
|
|
2013-09-12 16:17:02 +08:00
|
|
|
if test -z "$REDIS_PORT"; then REDIS_PORT=6333; fi
|
2011-10-20 22:44:37 +08:00
|
|
|
|
|
|
|
echo "preparing postgres..."
|
2012-07-09 21:44:01 +08:00
|
|
|
dropdb "${TEST_DB}"
|
|
|
|
createdb -Ttemplate_postgis -EUTF8 "${TEST_DB}" || die "Could not create test database"
|
2013-11-11 07:50:03 +08:00
|
|
|
|
|
|
|
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}"
|
2013-11-13 00:29:57 +08:00
|
|
|
echo "TESTUSER: ${TESTUSER}"
|
|
|
|
echo "TESTPASS: ${TESTPASS}"
|
2013-11-11 07:50:03 +08:00
|
|
|
|
|
|
|
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}
|
2011-10-20 22:44:37 +08:00
|
|
|
|
2012-07-10 00:56:09 +08:00
|
|
|
echo "preparing redis..."
|
2013-11-11 07:50:03 +08:00
|
|
|
echo "HSET rails:users:localhost id ${TESTUSERID}" | redis-cli -p ${REDIS_PORT} -n 5
|
2012-10-05 21:44:04 +08:00
|
|
|
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
|
2013-11-12 00:49:05 +08:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2012-07-11 01:37:24 +08:00
|
|
|
echo 'HSET rails:'"${TEST_DB}"':my_table infowindow "this, that, the other"' | redis-cli -p ${REDIS_PORT} -n 0
|
2012-08-15 01:26:40 +08:00
|
|
|
echo 'HSET rails:'"${TEST_DB}"':test_table_private_1 privacy "0"' | redis-cli -p ${REDIS_PORT} -n 0
|
2012-07-10 00:56:09 +08:00
|
|
|
|
2012-12-22 00:32:00 +08:00
|
|
|
echo "Finished preparing data. Ready to run tests"
|
|
|
|
|