summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2014-12-12 19:00:37 -0800
committerelijah <elijah@riseup.net>2014-12-12 19:00:37 -0800
commit0eedbfa5ce7a8ed4799408b591e655070336f0cc (patch)
treed5f227f77bd1f91f048513b448523ad724bfe18c /test
parenta2b100a5232a58fc082265ebfee96697f4d3f9e9 (diff)
test cleanup: correct default test config, ensure tapicero is running, create db if doesn't exist, pin to current minitest to avoid deprecation warnings.
Diffstat (limited to 'test')
-rw-r--r--test/config.yaml4
-rw-r--r--test/integration/actions_test.rb10
-rw-r--r--test/support/integration_test.rb47
-rw-r--r--test/test_helper.rb7
4 files changed, 58 insertions, 10 deletions
diff --git a/test/config.yaml b/test/config.yaml
index e59b4de..c1502db 100644
--- a/test/config.yaml
+++ b/test/config.yaml
@@ -7,8 +7,8 @@ connection:
protocol: "http"
host: "localhost"
port: 5984
- username: anna
- password: secret
+ username: ~
+ password: ~
prefix: "tapicero_test"
suffix: ""
diff --git a/test/integration/actions_test.rb b/test/integration/actions_test.rb
index 6576b87..52c1083 100644
--- a/test/integration/actions_test.rb
+++ b/test/integration/actions_test.rb
@@ -3,6 +3,7 @@ require_relative '../test_helper.rb'
class ActionsTest < Tapicero::IntegrationTest
def setup
+ assert_tapicero_running
create_user
end
@@ -11,9 +12,8 @@ class ActionsTest < Tapicero::IntegrationTest
end
def test_creates_user_db
- assert user_database
+ assert_database_exists user_database
assert user_database.name.start_with?(config.options[:db_prefix])
- assert user_database.info # ensure db exists in couch.
end
def test_configures_security
@@ -25,10 +25,10 @@ class ActionsTest < Tapicero::IntegrationTest
design_docs(user_database).map{|doc| doc["id"]}.sort
end
- def test_cleares_user_db
- assert user_database.info # ensure db exists in couch.
+ def test_deletes_user_db
+ assert_database_exists user_database
delete_user
- assert !host.databases.include?(user_database.name)
+ assert !host.databases.include?(user_database.name), 'user db must not exist'
end
def design_docs(db)
diff --git a/test/support/integration_test.rb b/test/support/integration_test.rb
index b28c0e1..117fc3f 100644
--- a/test/support/integration_test.rb
+++ b/test/support/integration_test.rb
@@ -1,6 +1,10 @@
module Tapicero
- class IntegrationTest < MiniTest::Unit::TestCase
+ class IntegrationTest < MiniTest::Test
+ #
+ # create a dummy record for the user
+ # so that tapicero will get a new user event
+ #
def create_user(fast = false)
result = database.save_doc :some => :content
raise RuntimeError.new(result.inspect) unless result['ok']
@@ -18,10 +22,12 @@ module Tapicero
def user_database
host.database(config.options[:db_prefix] + @user['_id'])
+ rescue RestClient::ResourceNotFound
+ puts 'failed to find per user db'
end
def database
- @database ||= host.database(database_name)
+ @database ||= host.database!(database_name)
end
def database_name
@@ -35,5 +41,42 @@ module Tapicero
def config
Tapicero.config
end
+
+ def assert_database_exists(db)
+ db.info
+ rescue RestClient::ResourceNotFound
+ assert false, "Database #{db} should exist."
+ end
+
+ def assert_tapicero_running
+ return if $tapicero_running
+ pid_file = '/tmp/tapicero.pid'
+ unless File.exists?(pid_file)
+ puts 'Tapicero must be running. Run `bin/tapicero run -- test/config.yaml`'
+ exit(1)
+ end
+ pid = File.read(pid_file).strip
+ if pid !~ /^\d+/
+ puts "Bad #{pid_file}: Remove the file and try again.";
+ exit(1)
+ else
+ pid = pid.to_i
+ end
+ begin
+ Process.kill(0, pid)
+ puts "OK, tapicero is running with process id #{pid}."
+ $tapicero_running = true
+ rescue Errno::EPERM
+ puts "Failed to test tapicero pid: No permission to query #{pid}!"
+ exit(1)
+ rescue Errno::ESRCH
+ puts "Bad #{pid_file}: #{pid} is NOT running. Remove the file and try again.";
+ exit(1)
+ rescue
+ puts "Unable to determine status for tapicero process #{pid} : #{$!}"
+ exit(1)
+ end
+ end
+
end
end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 5a3b509..4fe81df 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -1,4 +1,5 @@
require 'rubygems'
+gem 'minitest'
require 'minitest/autorun'
require 'pathname'
@@ -6,6 +7,11 @@ unless defined? BASE_DIR
BASE_DIR = Pathname.new(__FILE__) + '../..'
end
+begin
+ require 'debugger'
+rescue LoadError
+end
+
$:.unshift BASE_DIR + 'lib'
require 'mocha/setup'
@@ -15,5 +21,4 @@ Tapicero::CONFIGS << "test/config.yaml"
Tapicero::RERAISE = true
require 'tapicero'
-
require_relative 'support/integration_test'