From 91d21e6ff01275bdec87d41ca3940de4e6c469d8 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 18 Jun 2014 17:31:25 +1000 Subject: [PATCH] Work in progress, standalone docker test --- lib/tasks/docker.rake | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 lib/tasks/docker.rake diff --git a/lib/tasks/docker.rake b/lib/tasks/docker.rake new file mode 100644 index 00000000000..2109a9a51f8 --- /dev/null +++ b/lib/tasks/docker.rake @@ -0,0 +1,43 @@ + +def run_or_fail(command) + pid = Process.spawn(command) + Process.wait(pid) + $?.exitstatus == 0 +end + +desc 'Run all tests (JS and code in a standalone environment)' +task 'docker:test' do + begin + puts "Cleaning up old test tmp data in tmp/test_data" + `rm -fr tmp/test_data && mkdir -p tmp/test_data/redis && mkdir tmp/test_data/pg` + + puts "Starting background redis" + @redis_pid = Process.spawn('redis-server --dir tmp/test_data/redis') + + @postgres_bin = "/usr/lib/postgresql/9.3/bin/" + `#{@postgres_bin}initdb -D tmp/test_data/pg` + + puts "Starting postgres" + @pg_pid = Process.spawn("#{@postgres_bin}postmaster -D tmp/test_data/pg") + + + ENV["RAILS_ENV"] = "test" + + @good = run_or_fail("bundle exec rake db:create db:migrate") + @good &&= run_or_fail("bundle exec rspec") + @good &&= run_or_fail("bundle exec rake qunit:test") + + ensure + puts "Terminating" + + Process.kill("TERM", @redis_pid) + Process.kill("TERM", @pg_pid) + Process.wait @redis_pid + Process.wait @pg_pid + end + + if !@good + exit 1 + end + +end