diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..6ceb5327 --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +all: + npm install + +check: + ./run_tests.sh diff --git a/package.json b/package.json index a4a58861..d68b21e8 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,6 @@ "mocha": "1.2.1" }, "scripts": { - "test": "which expresso | sh" + "test": "make check" } } diff --git a/run_tests.sh b/run_tests.sh new file mode 100755 index 00000000..f2c28647 --- /dev/null +++ b/run_tests.sh @@ -0,0 +1,43 @@ +#!/bin/sh + +# Must match config.redis_pool.port in test/support/config.js +REDIS_PORT=6333 + +cleanup() { + echo "Cleaning up" + kill ${PID_REDIS} +} + +cleanup_and_exit() { + cleanup + exit +} + +die() { + msg=$1 + echo "${msg}" >&2 + cleanup + exit 1 +} + +trap 'cleanup_and_exit' 1 2 3 5 9 13 + +echo "Starting redis on port ${REDIS_PORT}" +echo "port ${REDIS_PORT}" | redis-server - > test.log & +PID_REDIS=$! + +echo "Preparing the database" +cd test; sh prepare_db.sh >> test.log || die "database preparation failure (see test.log)"; cd -; + +PATH=node_modules/.bin/:$PATH + +echo "Running unit test" +mocha -u tdd test/unit/cartodb/redis_pool.test.js + +echo "Running acceptance tests" +# NOTE: leaks detected ! TODO: fix them +mocha -u tdd --ignore-leaks test/acceptance/cache_validator.js +mocha -u tdd --ignore-leaks test/acceptance/server.js + + +cleanup diff --git a/test/prepare_db.sh b/test/prepare_db.sh index 6559fdab..56e38fdf 100755 --- a/test/prepare_db.sh +++ b/test/prepare_db.sh @@ -17,11 +17,7 @@ die() { } TEST_DB="cartodb_test_user_1_db" - -echo "preparing redis..." -echo "HSET rails:users:vizzuality id 1" | redis-cli -n 5 -echo "HSET rails:users:vizzuality database_name '${TEST_DB}'" | redis-cli -n 5 -echo 'HSET rails:${TEST_DB}:my_table infowindow "this, that, the other"' | redis-cli -n 0 +REDIS_PORT=6333 echo "preparing postgres..." dropdb "${TEST_DB}" @@ -29,4 +25,9 @@ createdb -Ttemplate_postgis -EUTF8 "${TEST_DB}" || die "Could not create test da psql "${TEST_DB}" < ./sql/windshaft.test.sql psql "${TEST_DB}" < ./sql/gadm4.sql +echo "preparing redis..." +echo "HSET rails:users:vizzuality id 1" | redis-cli -p ${REDIS_PORT} -n 5 +echo "HSET rails:users:vizzuality database_name '${TEST_DB}'" | 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 "Finished preparing data. Run tests with expresso." diff --git a/test/support/config.js b/test/support/config.js new file mode 100644 index 00000000..3581f896 --- /dev/null +++ b/test/support/config.js @@ -0,0 +1,18 @@ +var _ = require('underscore'); + +module.exports = function(opts) { + + var config = { + redis_pool: { + max: 10, + idleTimeoutMillis: 1, + reapIntervalMillis: 1, + port: 6333 // TODO: read from test env ? + } + } + + _.extend(config, opts || {}); + + return config; +}(); + diff --git a/test/unit/cartodb/redis_pool.test.js b/test/unit/cartodb/redis_pool.test.js index 0833db09..fe4b4e99 100644 --- a/test/unit/cartodb/redis_pool.test.js +++ b/test/unit/cartodb/redis_pool.test.js @@ -6,11 +6,7 @@ var assert = require('../../support/assert') suite('redis_pool', function() { // configure redis pool instance to use in tests - var test_opts = { - max: 10, - idleTimeoutMillis: 1, - reapIntervalMillis: 1 - }; + var test_opts = require('../../support/config').redis_pool; var redis_pool = new RedisPool(test_opts);