summaryrefslogtreecommitdiff
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
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.
-rw-r--r--Gemfile.lock4
-rw-r--r--Readme.md11
-rw-r--r--tapicero.gemspec2
-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
7 files changed, 70 insertions, 15 deletions
diff --git a/Gemfile.lock b/Gemfile.lock
index 03a0af5..5841ead 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -24,7 +24,7 @@ GEM
json (1.8.1)
metaclass (0.0.1)
mime-types (1.25.1)
- minitest (3.2.0)
+ minitest (5.4.3)
mocha (0.14.0)
metaclass (~> 0.0.1)
multi_json (1.10.1)
@@ -42,7 +42,7 @@ PLATFORMS
DEPENDENCIES
highline
- minitest (~> 3.2.0)
+ minitest (~> 5.4.0)
mocha
rake
tapicero!
diff --git a/Readme.md b/Readme.md
index adc31d4..2df2818 100644
--- a/Readme.md
+++ b/Readme.md
@@ -51,6 +51,14 @@ Run once and then exit:
This will create per user databases for all users created since
the last run and then exit.
+Running tests
+---------------------
+
+To run the tests, tapicero must be running:
+
+ bin/tapicero run -- test/config.yaml
+ rake test
+
Flags
---------------------
@@ -77,7 +85,7 @@ Configuration
For development on a couch with admin party you can probably leave all other options at their default values. For production you will need to set the credentials to an admin user so tapicero can create databases.
-The default options and some explaination can be found in config/defaults.yaml
+The default options and some explanation can be found in `config/default.yaml`.
Rake Tasks
----------------------------
@@ -95,4 +103,3 @@ For development and debugging you might want to run the programm directly withou
the deamon wrapper. You can do this like this:
ruby -I lib lib/tapicero.rb
-
diff --git a/tapicero.gemspec b/tapicero.gemspec
index 78b8af4..843222f 100644
--- a/tapicero.gemspec
+++ b/tapicero.gemspec
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
s.add_dependency "daemons"
s.add_dependency "yajl-ruby", "~> 1.1.0"
s.add_dependency "syslog_logger", "~> 2.0.0"
- s.add_development_dependency "minitest", "~> 3.2.0"
+ s.add_development_dependency "minitest", "~> 5.4.0"
s.add_development_dependency "mocha"
s.add_development_dependency "rake"
s.add_development_dependency "highline"
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'