From eee59abfa183d383d2de0abe81a32988f5c93702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Mon, 2 Dec 2019 12:43:59 +0100 Subject: [PATCH 1/3] Remove unused bash script --- test/support/prepare_db.sh | 192 ------------------------------------- 1 file changed, 192 deletions(-) delete mode 100755 test/support/prepare_db.sh diff --git a/test/support/prepare_db.sh b/test/support/prepare_db.sh deleted file mode 100755 index 3091870c..00000000 --- a/test/support/prepare_db.sh +++ /dev/null @@ -1,192 +0,0 @@ -#!/bin/sh - -# this script prepare database and redis instance to run accpetance test -# -# NOTE: assumes existance of a "template_postgis" -# NOTE2: use PG* environment variables to control who and where -# -# 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 -# - -PREPARE_REDIS=yes -PREPARE_PGSQL=yes - -while [ -n "$1" ]; do - OPTION=$(echo "$1" | tr -d '[:space:]') - if [[ "$OPTION" == "--skip-pg" ]]; then - PREPARE_PGSQL=no - shift; continue - elif [[ "$OPTION" == "--skip-redis" ]]; then - PREPARE_REDIS=no - shift; continue - else - shift; continue; - fi -done - -die() { - msg=$1 - echo "${msg}" >&2 - exit 1 -} - -# 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" - -# NOTE: will be set by caller trough environment -if test -z "$REDIS_PORT"; then REDIS_PORT=6333; fi - -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}" - -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" - psql -c "CREATE EXTENSION IF NOT EXISTS cartodb CASCADE;" ${TEST_DB} - - LOCAL_SQL_SCRIPTS='analysis_catalog windshaft.test gadm4 countries_null_values ported/populated_places_simple_reduced cdb_analysis_check cdb_invalidate_varnish' - for i in ${LOCAL_SQL_SCRIPTS} - do - cat sql/${i}.sql | - sed -e "s/:PUBLICUSER/${PUBLICUSER}/g" | - sed -e "s/:PUBLICPASS/${PUBLICPASS}/g" | - sed -e "s/:TESTUSER/${TESTUSER}/g" | - sed -e "s/:TESTPASS/${TESTPASS}/g" | - PGOPTIONS='--client-min-messages=WARNING' psql -q -v ON_ERROR_STOP=1 ${TEST_DB} > /dev/null || exit 1 - done -fi - -if test x"$PREPARE_REDIS" = xyes; then - - echo "preparing redis..." - - cat < Date: Mon, 2 Dec 2019 12:51:16 +0100 Subject: [PATCH 2/3] Avoid to overwrite env, just extend it with new env variables --- test/index.js | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/test/index.js b/test/index.js index f0e8c2c8..9261ad42 100644 --- a/test/index.js +++ b/test/index.js @@ -34,25 +34,19 @@ async function stopRedis () { async function dropDatabase () { await exec(`dropdb --if-exists ${TEST_DB}`, { - env: { - PGUSER: 'postgres' - } + env: Object.assign ({ PGUSER: 'postgres' }, process.env) }); } async function createDatabase () { await exec(`createdb -T template_postgis -EUTF8 "${TEST_DB}"`, { - env: { - PGUSER: 'postgres' - } + env: Object.assign ({ PGUSER: 'postgres' }, process.env) }); } async function createDatabaseExtension () { await exec(`psql -c "CREATE EXTENSION IF NOT EXISTS cartodb CASCADE;" ${TEST_DB}`, { - env: { - PGUSER: 'postgres' - } + env: Object.assign ({ PGUSER: 'postgres' }, process.env) }); } @@ -77,9 +71,7 @@ async function populateDatabase () { `; await exec(populateDatabaseCmd, { - env: { - PGUSER: 'postgres' - } + env: Object.assign ({ PGUSER: 'postgres' }, process.env) }); } From fb9dce0386ee43b2ba12e0409863396fb16fc4be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Mon, 2 Dec 2019 12:56:21 +0100 Subject: [PATCH 3/3] Lint --- test/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/index.js b/test/index.js index 9261ad42..84f43989 100644 --- a/test/index.js +++ b/test/index.js @@ -34,19 +34,19 @@ async function stopRedis () { async function dropDatabase () { await exec(`dropdb --if-exists ${TEST_DB}`, { - env: Object.assign ({ PGUSER: 'postgres' }, process.env) + env: Object.assign({ PGUSER: 'postgres' }, process.env) }); } async function createDatabase () { await exec(`createdb -T template_postgis -EUTF8 "${TEST_DB}"`, { - env: Object.assign ({ PGUSER: 'postgres' }, process.env) + env: Object.assign({ PGUSER: 'postgres' }, process.env) }); } async function createDatabaseExtension () { await exec(`psql -c "CREATE EXTENSION IF NOT EXISTS cartodb CASCADE;" ${TEST_DB}`, { - env: Object.assign ({ PGUSER: 'postgres' }, process.env) + env: Object.assign({ PGUSER: 'postgres' }, process.env) }); } @@ -71,7 +71,7 @@ async function populateDatabase () { `; await exec(populateDatabaseCmd, { - env: Object.assign ({ PGUSER: 'postgres' }, process.env) + env: Object.assign({ PGUSER: 'postgres' }, process.env) }); }