From bd0e7aeab9cb853439fa68d28332513157d54f73 Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 6 Jan 2014 07:32:06 +0100 Subject: initial test for running tapicero on travis ci --- .travis.yml | 6 ++++++ test/config.yaml | 19 +++++++++++++++++++ test/setup_couch.sh | 13 +++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 test/config.yaml create mode 100644 test/setup_couch.sh diff --git a/.travis.yml b/.travis.yml index 984e24a..69f79e6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,2 +1,8 @@ services: - couchdb +notifications: + email: false +before_script: + - "/bin/bash test/setup_couch.sh" + - "bin/tapicero start test/config.yaml" + - "cat /tmp/test-tapicero.log" diff --git a/test/config.yaml b/test/config.yaml new file mode 100644 index 0000000..6719eb4 --- /dev/null +++ b/test/config.yaml @@ -0,0 +1,19 @@ +# +# Default configuration options for Tapicero +# + +# couch connection configuration +connection: + protocol: "http" + host: "localhost" + port: 5984 + username: anna + password: secret + prefix: "test" + suffix: "" + +# file to store the last processed user record in so we can resume after +# a restart: +seq_file: "/tmp/test-tapicero.seq" +log_file: "/tmp/test-tapicero.log" +log_level: debug diff --git a/test/setup_couch.sh b/test/setup_couch.sh new file mode 100644 index 0000000..026c15c --- /dev/null +++ b/test/setup_couch.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +HOST="http://localhost:5984" +echo "couch version :" +curl -X GET $HOST +echo "creating unprivileged user :" +curl -HContent-Type:application/json -XPUT $HOST/_users/org.couchdb.user:me --data-binary '{"_id": "org.couchdb.user:me","name": "me","roles": [],"type": "user","password": "pwd"}' +echo "creating database to watch:" +curl -X PUT $HOST/test-users +echo "restricting database access :" +curl -X PUT $HOST/test-users/_security -Hcontent-type:application/json --data-binary '{"admins":{"names":[],"roles":[]},"members":{"names":["me"],"roles":[]}}' +echo "adding admin :" +curl -X PUT $HOST/_config/admins/anna -d '"secret"' -- cgit v1.2.3 From 41b99f4aec6ac6431531a380c65d4933c740fa67 Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 6 Jan 2014 07:38:14 +0100 Subject: updated Gemfile.lock --- Gemfile.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index afbb265..917a4f7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,9 +1,9 @@ PATH remote: . specs: - tapicero (0.3.1) + tapicero (0.3.2) couchrest (~> 1.1.3) - couchrest_changes (~> 0.0.4) + couchrest_changes (~> 0.0.5) daemons syslog_logger (~> 2.0.0) yajl-ruby (~> 1.1.0) @@ -15,7 +15,7 @@ GEM mime-types (~> 1.15) multi_json (~> 1.0) rest-client (~> 1.6.1) - couchrest_changes (0.0.4) + couchrest_changes (0.0.5) couchrest (~> 1.1.3) syslog_logger (~> 2.0.0) yajl-ruby -- cgit v1.2.3 From 53b2a1f1f750a48939e69278297d69dbc6b213ad Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 6 Jan 2014 07:47:28 +0100 Subject: try to get require rubygems to work on travis --- .travis.yml | 4 +++- bin/tapicero | 4 ++-- test/config.yaml | 2 +- test/config/config.yaml | 5 ----- test/setup_couch.sh | 4 ++-- 5 files changed, 8 insertions(+), 11 deletions(-) delete mode 100644 test/config/config.yaml diff --git a/.travis.yml b/.travis.yml index 69f79e6..ecbf265 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,10 @@ +rvm: + - "1.9.3" services: - couchdb notifications: email: false before_script: - "/bin/bash test/setup_couch.sh" - - "bin/tapicero start test/config.yaml" + - "bundle exec bin/tapicero start test/config.yaml" - "cat /tmp/test-tapicero.log" diff --git a/bin/tapicero b/bin/tapicero index c20a114..f72b0db 100755 --- a/bin/tapicero +++ b/bin/tapicero @@ -1,10 +1,10 @@ -#!/usr/bin/ruby +#!/usr/bin/env ruby -require 'pathname' # # Tapicero Daemon # +require 'pathname' BASE_DIR = Pathname.new(__FILE__).realpath + '../..' begin diff --git a/test/config.yaml b/test/config.yaml index 6719eb4..599df4a 100644 --- a/test/config.yaml +++ b/test/config.yaml @@ -9,7 +9,7 @@ connection: port: 5984 username: anna password: secret - prefix: "test" + prefix: "tapicero-test" suffix: "" # file to store the last processed user record in so we can resume after diff --git a/test/config/config.yaml b/test/config/config.yaml deleted file mode 100644 index ee10fe6..0000000 --- a/test/config/config.yaml +++ /dev/null @@ -1,5 +0,0 @@ -# -# testing configuration options -# - -db_prefix: "tapicero_test-" diff --git a/test/setup_couch.sh b/test/setup_couch.sh index 026c15c..ae28758 100644 --- a/test/setup_couch.sh +++ b/test/setup_couch.sh @@ -6,8 +6,8 @@ curl -X GET $HOST echo "creating unprivileged user :" curl -HContent-Type:application/json -XPUT $HOST/_users/org.couchdb.user:me --data-binary '{"_id": "org.couchdb.user:me","name": "me","roles": [],"type": "user","password": "pwd"}' echo "creating database to watch:" -curl -X PUT $HOST/test-users +curl -X PUT $HOST/tapicero-test-users echo "restricting database access :" -curl -X PUT $HOST/test-users/_security -Hcontent-type:application/json --data-binary '{"admins":{"names":[],"roles":[]},"members":{"names":["me"],"roles":[]}}' +curl -X PUT $HOST/tapicero-test-users/_security -Hcontent-type:application/json --data-binary '{"admins":{"names":[],"roles":[]},"members":{"names":["me"],"roles":[]}}' echo "adding admin :" curl -X PUT $HOST/_config/admins/anna -d '"secret"' -- cgit v1.2.3 From 88083a47eb042fd5b3f6cfd9cae1e087bc9fa072 Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 6 Jan 2014 10:05:47 +0100 Subject: add dummy integration test --- Rakefile | 2 +- test/integration/tapicero_test.rb | 4 ++++ test/unit/couch_changes_test.rb | 32 -------------------------------- test/unit/couch_stream_test.rb | 29 ----------------------------- 4 files changed, 5 insertions(+), 62 deletions(-) create mode 100644 test/integration/tapicero_test.rb delete mode 100644 test/unit/couch_changes_test.rb delete mode 100644 test/unit/couch_stream_test.rb diff --git a/Rakefile b/Rakefile index 7293cb2..6137fc1 100644 --- a/Rakefile +++ b/Rakefile @@ -76,7 +76,7 @@ end ## Rake::TestTask.new do |t| - t.pattern = "test/unit/*_test.rb" + t.pattern = "test/*/*_test.rb" end task :default => :test diff --git a/test/integration/tapicero_test.rb b/test/integration/tapicero_test.rb new file mode 100644 index 0000000..b83263a --- /dev/null +++ b/test/integration/tapicero_test.rb @@ -0,0 +1,4 @@ +require File.expand_path('../../test_helper.rb', __FILE__) + +class TapiceroTest < MiniTest::Unit::TestCase +end diff --git a/test/unit/couch_changes_test.rb b/test/unit/couch_changes_test.rb deleted file mode 100644 index 043caf1..0000000 --- a/test/unit/couch_changes_test.rb +++ /dev/null @@ -1,32 +0,0 @@ -require File.expand_path('../../test_helper.rb', __FILE__) -require 'tapicero/couch_changes' - -class CouchChangesTest < MiniTest::Unit::TestCase - - LAST_SEQ = 12 - - def setup - @stream = mock() - @changes = Tapicero::CouchChanges.new(@stream) - end - - def test_last_seq - @stream.expects(:get). - with('_changes', {:limit => 1, :descending => true}). - yields(:last_seq => LAST_SEQ) - assert_equal LAST_SEQ, @changes.last_seq - end - - def test_follow - stub_entry = {:new => :result} - @stream.expects(:get). - with('_changes', {:limit => 1, :descending => true}). - yields(:last_seq => LAST_SEQ) - @stream.expects(:get). - with('_changes', {:feed => :continuous, :since => LAST_SEQ}). - yields(stub_entry) - @changes.follow do |hash| - assert_equal stub_entry, hash - end - end -end diff --git a/test/unit/couch_stream_test.rb b/test/unit/couch_stream_test.rb deleted file mode 100644 index a9de21f..0000000 --- a/test/unit/couch_stream_test.rb +++ /dev/null @@ -1,29 +0,0 @@ -require File.expand_path('../../test_helper.rb', __FILE__) -require 'tapicero/couch_stream' - -class CouchStreamTest < MiniTest::Unit::TestCase - - def setup - @root = "http://server/database" - @stream = Tapicero::CouchStream.new(@root) - @url = @root + "/_changes?a=b&c=d" - @path = "_changes" - @options = {:a => :b, :c => :d} - end - - def test_get - Tapicero::JsonStream.expects(:get). - with(@url, :symbolize_keys => true). - yields(stub_hash = stub) - @stream.get(@path, @options) do |hash| - assert_equal stub_hash, hash - end - end - - # internal - def test_url_creation - assert_equal "http://server/database/", @stream.send(:url_for, "") - assert_equal @url, @stream.send(:url_for, @path, @options) - end - -end -- cgit v1.2.3 From 87d76281eb374f4c4538fe5bf5b774b73dd5d7e3 Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 6 Jan 2014 10:24:43 +0100 Subject: first interesting tests --- .travis.yml | 5 ++++ bin/tapicero | 6 ++--- test/integration/tapicero_test.rb | 51 +++++++++++++++++++++++++++++++++++++++ test/test_helper.rb | 2 +- 4 files changed, 59 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index ecbf265..163f92b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,5 +6,10 @@ notifications: email: false before_script: - "/bin/bash test/setup_couch.sh" + - "touch /tmp/test-tapicero.log" - "bundle exec bin/tapicero start test/config.yaml" + - "bundle exec bin/tapicero status" - "cat /tmp/test-tapicero.log" +after_script: + - "cat /tmp/test-tapicero.log" + - "cat /tmp/test-tapicero.seq" diff --git a/bin/tapicero b/bin/tapicero index f72b0db..32cc228 100755 --- a/bin/tapicero +++ b/bin/tapicero @@ -59,7 +59,6 @@ end # # Start the daemon # -require 'tapicero' # so we can use Tapicero.logger below. require 'daemons' if ENV["USER"] == "root" options = {:app_name => 'tapicero', :dir_mode => :system} # this will put the pid file in /var/run @@ -70,7 +69,6 @@ begin Daemons.run("#{BASE_DIR}/lib/tapicero_daemon.rb", options) rescue SystemExit rescue Exception => exc - Tapicero.logger.error "Uncaught exception. Daemon will die." - Tapicero.logger.error exc.class.name + ": " + exc.to_s - Tapicero.logger.error exc.backtrace.join("\n") + puts exc.class.name + exc.to_s + puts exc.backtrace.join("\n") end diff --git a/test/integration/tapicero_test.rb b/test/integration/tapicero_test.rb index b83263a..d436e6d 100644 --- a/test/integration/tapicero_test.rb +++ b/test/integration/tapicero_test.rb @@ -1,4 +1,55 @@ require File.expand_path('../../test_helper.rb', __FILE__) class TapiceroTest < MiniTest::Unit::TestCase + + def test_loads_config + assert_equal "tapicero-test", config.connection[:prefix] + assert_equal "debug", config.send(:log_level) + end + + def test_database_exists + assert database + end + + def test_creates_user_db_fast + user_id = create_user['id'] + database.save_doc :id => user_id + assert user_database(user_id) + end + + def test_creates_user_db_slow + user_id = create_user['id'] + sleep 1 + assert user_database(user_id) + end + + def test_configures_security + user_id = create_user['id'] + sleep 1 + assert_equal config.options[:security], user_database(user_id).get(_security) + end + + def create_user + database.save_doc :some => :content + end + + def user_database(name) + host.database(config.options[:db_prefix] + name) + end + + def database + @database ||= host.database(database_name) + end + + def database_name + config.complete_db_name('users') + end + + def host + @host ||= CouchRest.new(config.couch_host) + end + + def config + Tapicero.config + end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 3857e2c..227cde5 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -6,5 +6,5 @@ $:.unshift File.expand_path('lib', BASE_DIR) require 'mocha/setup' -TAPICERO_CONFIG = "test/config/config.yaml" +TAPICERO_CONFIG = "test/config.yaml" require 'tapicero' -- cgit v1.2.3 From cbf35664160a57da4c96796e99911b982afacba2 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 4 Feb 2014 09:11:00 +0100 Subject: only set flags if they are defined --- lib/tapicero.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/tapicero.rb b/lib/tapicero.rb index e2a8f38..0c7007f 100644 --- a/lib/tapicero.rb +++ b/lib/tapicero.rb @@ -23,8 +23,10 @@ module Tapicero self.logger = CouchRest::Changes::Config.logger # hand flags over to CouchRest::Changes - config.flags = FLAGS - puts "flags: #{FLAGS}" if FLAGS.any? + if defined? FLAGS + config.flags = FLAGS + puts "flags: #{FLAGS}" if FLAGS.any? + end # # Load Tapicero Parts -- cgit v1.2.3 From ee4f24abf2a7848a015cfb02bfbdebf7b0874d8e Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 4 Feb 2014 09:16:19 +0100 Subject: hand config files on the command line to the daemon --- bin/tapicero | 3 ++- lib/tapicero.rb | 6 +----- lib/tapicero/version.rb | 1 + 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/bin/tapicero b/bin/tapicero index 32cc228..72f974b 100755 --- a/bin/tapicero +++ b/bin/tapicero @@ -46,7 +46,8 @@ end # --overwrite-security overwrite existing couch security settings # TODO: not implemented yet: # --overwrite-designs overwrite existing design documents -Tapicero::FLAGS.concat ARGV.grep(/--.*/) +Tapicero::FLAGS.concat ARGV.grep(/--.*/) +Tapicero::CONFIGS.concat ARGV.grep(/\.ya?ml$/) # if flags have been set but an action is missing we assume # tapicero should run in foreground. diff --git a/lib/tapicero.rb b/lib/tapicero.rb index 0c7007f..390257d 100644 --- a/lib/tapicero.rb +++ b/lib/tapicero.rb @@ -1,9 +1,6 @@ unless defined? BASE_DIR BASE_DIR = Pathname.new(__FILE__) + '../..' end -unless defined? TAPICERO_CONFIG - TAPICERO_CONFIG = '/etc/leap/tapicero.yaml' -end module Tapicero class < Date: Tue, 4 Feb 2014 09:43:24 +0100 Subject: unify naming scheme - tapicero_test prefix --- .travis.yml | 8 ++++---- test/config.yaml | 6 +++--- test/setup_couch.sh | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 163f92b..3fd27a7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,10 +6,10 @@ notifications: email: false before_script: - "/bin/bash test/setup_couch.sh" - - "touch /tmp/test-tapicero.log" + - "touch /tmp/tapicero_test.log" - "bundle exec bin/tapicero start test/config.yaml" - "bundle exec bin/tapicero status" - - "cat /tmp/test-tapicero.log" + - "cat /tmp/tapicero_test.log" after_script: - - "cat /tmp/test-tapicero.log" - - "cat /tmp/test-tapicero.seq" + - "cat /tmp/tapicero_test.log" + - "cat /tmp/tapicero_test.seq" diff --git a/test/config.yaml b/test/config.yaml index 599df4a..e59b4de 100644 --- a/test/config.yaml +++ b/test/config.yaml @@ -9,11 +9,11 @@ connection: port: 5984 username: anna password: secret - prefix: "tapicero-test" + prefix: "tapicero_test" suffix: "" # file to store the last processed user record in so we can resume after # a restart: -seq_file: "/tmp/test-tapicero.seq" -log_file: "/tmp/test-tapicero.log" +seq_file: "/tmp/tapicero_test.seq" +log_file: "/tmp/tapicero_test.log" log_level: debug diff --git a/test/setup_couch.sh b/test/setup_couch.sh index ae28758..c11993d 100644 --- a/test/setup_couch.sh +++ b/test/setup_couch.sh @@ -6,8 +6,8 @@ curl -X GET $HOST echo "creating unprivileged user :" curl -HContent-Type:application/json -XPUT $HOST/_users/org.couchdb.user:me --data-binary '{"_id": "org.couchdb.user:me","name": "me","roles": [],"type": "user","password": "pwd"}' echo "creating database to watch:" -curl -X PUT $HOST/tapicero-test-users +curl -X PUT $HOST/tapicero_test_users echo "restricting database access :" -curl -X PUT $HOST/tapicero-test-users/_security -Hcontent-type:application/json --data-binary '{"admins":{"names":[],"roles":[]},"members":{"names":["me"],"roles":[]}}' +curl -X PUT $HOST/tapicero_test_users/_security -Hcontent-type:application/json --data-binary '{"admins":{"names":[],"roles":[]},"members":{"names":["me"],"roles":[]}}' echo "adding admin :" curl -X PUT $HOST/_config/admins/anna -d '"secret"' -- cgit v1.2.3 From 890346ab671b679fb214f0ae78ca897cf54b9a74 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 4 Feb 2014 09:49:05 +0100 Subject: set db name correctly in tests and test it --- test/integration/tapicero_test.rb | 1 + test/test_helper.rb | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/test/integration/tapicero_test.rb b/test/integration/tapicero_test.rb index d436e6d..d32415c 100644 --- a/test/integration/tapicero_test.rb +++ b/test/integration/tapicero_test.rb @@ -9,6 +9,7 @@ class TapiceroTest < MiniTest::Unit::TestCase def test_database_exists assert database + assert_equal "tapicero_test_users", database.name end def test_creates_user_db_fast diff --git a/test/test_helper.rb b/test/test_helper.rb index 227cde5..4a9ca6b 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -6,5 +6,6 @@ $:.unshift File.expand_path('lib', BASE_DIR) require 'mocha/setup' -TAPICERO_CONFIG = "test/config.yaml" +require 'tapicero/version' +Tapicero::CONFIGS << "test/config.yaml" require 'tapicero' -- cgit v1.2.3 From 1765981c8c0c3f2eddfd326e83505910be97e01c Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 4 Feb 2014 09:56:37 +0100 Subject: fix tests --- test/integration/tapicero_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration/tapicero_test.rb b/test/integration/tapicero_test.rb index d32415c..bda05d3 100644 --- a/test/integration/tapicero_test.rb +++ b/test/integration/tapicero_test.rb @@ -3,7 +3,7 @@ require File.expand_path('../../test_helper.rb', __FILE__) class TapiceroTest < MiniTest::Unit::TestCase def test_loads_config - assert_equal "tapicero-test", config.connection[:prefix] + assert_equal "tapicero_test", config.connection[:prefix] assert_equal "debug", config.send(:log_level) end @@ -27,7 +27,7 @@ class TapiceroTest < MiniTest::Unit::TestCase def test_configures_security user_id = create_user['id'] sleep 1 - assert_equal config.options[:security], user_database(user_id).get(_security) + assert_equal config.options[:security], user_database(user_id).get('_security') end def create_user -- cgit v1.2.3 From 2836e9453618d9cc7dc64cb99651c4e5a40fb11c Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 4 Feb 2014 10:09:40 +0100 Subject: separate test setup test from actual test --- test/integration/tapicero_test.rb | 59 ++++++++++--------------------------- test/integration/test_setup_test.rb | 15 ++++++++++ test/support/integration_test.rb | 30 +++++++++++++++++++ test/test_helper.rb | 3 ++ 4 files changed, 64 insertions(+), 43 deletions(-) create mode 100644 test/integration/test_setup_test.rb create mode 100644 test/support/integration_test.rb diff --git a/test/integration/tapicero_test.rb b/test/integration/tapicero_test.rb index bda05d3..4c00ee2 100644 --- a/test/integration/tapicero_test.rb +++ b/test/integration/tapicero_test.rb @@ -1,56 +1,29 @@ -require File.expand_path('../../test_helper.rb', __FILE__) +require_relative '../test_helper.rb' -class TapiceroTest < MiniTest::Unit::TestCase +class TapiceroTest < Tapicero::IntegrationTest - def test_loads_config - assert_equal "tapicero_test", config.connection[:prefix] - assert_equal "debug", config.send(:log_level) - end - - def test_database_exists - assert database - assert_equal "tapicero_test_users", database.name - end - - def test_creates_user_db_fast - user_id = create_user['id'] - database.save_doc :id => user_id - assert user_database(user_id) - end - - def test_creates_user_db_slow - user_id = create_user['id'] + def test_creates_user_db + create_user sleep 1 - assert user_database(user_id) + assert user_database + assert user_database.name.start_with?(config.options[:db_prefix]) + assert user_database.info end def test_configures_security - user_id = create_user['id'] + create_user sleep 1 - assert_equal config.options[:security], user_database(user_id).get('_security') - end - - def create_user - database.save_doc :some => :content + assert_equal config.options[:security], user_database.get('_security') end - def user_database(name) - host.database(config.options[:db_prefix] + name) - end - - def database - @database ||= host.database(database_name) - end - - def database_name - config.complete_db_name('users') - end - - def host - @host ||= CouchRest.new(config.couch_host) + def test_stores_design_docs + create_user + sleep 1 + assert_equal ['_design/docs', '_design/syncs', '_design/transactions'], + design_docs(user_database).map{|doc| doc["id"]}.sort end - def config - Tapicero.config + def design_docs(db) + db.documents(startkey: '_design', endkey: '_design'.succ)["rows"] end end diff --git a/test/integration/test_setup_test.rb b/test/integration/test_setup_test.rb new file mode 100644 index 0000000..525c14d --- /dev/null +++ b/test/integration/test_setup_test.rb @@ -0,0 +1,15 @@ +require_relative '../test_helper.rb' + +class TestSetupTest < Tapicero::IntegrationTest + + def test_loads_config + assert_equal "tapicero_test", config.connection[:prefix] + assert_equal "debug", config.send(:log_level) + end + + def test_database_exists + assert database + assert_equal "tapicero_test_users", database.name + end + +end diff --git a/test/support/integration_test.rb b/test/support/integration_test.rb new file mode 100644 index 0000000..58469b9 --- /dev/null +++ b/test/support/integration_test.rb @@ -0,0 +1,30 @@ +module Tapicero + class IntegrationTest < MiniTest::Unit::TestCase + + def create_user + result = database.save_doc :some => :content + raise RuntimeError.new(result.inspect) unless result['ok'] + @user_id = result['id'] + end + + def user_database + host.database(config.options[:db_prefix] + @user_id) + end + + def database + @database ||= host.database(database_name) + end + + def database_name + config.complete_db_name('users') + end + + def host + @host ||= CouchRest.new(config.couch_host) + end + + def config + Tapicero.config + end + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 4a9ca6b..da8b88c 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -9,3 +9,6 @@ require 'mocha/setup' require 'tapicero/version' Tapicero::CONFIGS << "test/config.yaml" require 'tapicero' + + +require_relative 'support/integration_test' -- cgit v1.2.3 From 630c38a0bcf4ca39ede98d354d8d43e6f735317c Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 4 Feb 2014 11:09:02 +0100 Subject: include sleep in the create_user part of the tests the changes feed and tapicero take some time to process the new user. Let's prevent timing issues by sleeping a second. --- test/integration/tapicero_test.rb | 3 --- test/support/integration_test.rb | 1 + 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/test/integration/tapicero_test.rb b/test/integration/tapicero_test.rb index 4c00ee2..b7a3dd4 100644 --- a/test/integration/tapicero_test.rb +++ b/test/integration/tapicero_test.rb @@ -4,7 +4,6 @@ class TapiceroTest < Tapicero::IntegrationTest def test_creates_user_db create_user - sleep 1 assert user_database assert user_database.name.start_with?(config.options[:db_prefix]) assert user_database.info @@ -12,13 +11,11 @@ class TapiceroTest < Tapicero::IntegrationTest def test_configures_security create_user - sleep 1 assert_equal config.options[:security], user_database.get('_security') end def test_stores_design_docs create_user - sleep 1 assert_equal ['_design/docs', '_design/syncs', '_design/transactions'], design_docs(user_database).map{|doc| doc["id"]}.sort end diff --git a/test/support/integration_test.rb b/test/support/integration_test.rb index 58469b9..44f0546 100644 --- a/test/support/integration_test.rb +++ b/test/support/integration_test.rb @@ -4,6 +4,7 @@ module Tapicero def create_user result = database.save_doc :some => :content raise RuntimeError.new(result.inspect) unless result['ok'] + sleep 1 # allow tapicero to do its job @user_id = result['id'] end -- cgit v1.2.3 From c3cb71ca5e6d32960e4493d85799f3706ea91fe8 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 4 Feb 2014 11:25:43 +0100 Subject: test user deletion --- test/integration/tapicero_test.rb | 19 +++++++++++++++---- test/support/integration_test.rb | 16 ++++++++++++---- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/test/integration/tapicero_test.rb b/test/integration/tapicero_test.rb index b7a3dd4..88e3715 100644 --- a/test/integration/tapicero_test.rb +++ b/test/integration/tapicero_test.rb @@ -2,24 +2,35 @@ require_relative '../test_helper.rb' class TapiceroTest < Tapicero::IntegrationTest - def test_creates_user_db + def setup create_user + end + + def teardown + delete_user(true) + end + + def test_creates_user_db assert user_database assert user_database.name.start_with?(config.options[:db_prefix]) - assert user_database.info + assert user_database.info # ensure db exists in couch. end def test_configures_security - create_user assert_equal config.options[:security], user_database.get('_security') end def test_stores_design_docs - create_user assert_equal ['_design/docs', '_design/syncs', '_design/transactions'], design_docs(user_database).map{|doc| doc["id"]}.sort end + def test_cleares_user_db + assert user_database.info # ensure db exists in couch. + delete_user + assert !host.databases.include?(user_database.name) + end + def design_docs(db) db.documents(startkey: '_design', endkey: '_design'.succ)["rows"] end diff --git a/test/support/integration_test.rb b/test/support/integration_test.rb index 44f0546..b28c0e1 100644 --- a/test/support/integration_test.rb +++ b/test/support/integration_test.rb @@ -1,15 +1,23 @@ module Tapicero class IntegrationTest < MiniTest::Unit::TestCase - def create_user + def create_user(fast = false) result = database.save_doc :some => :content raise RuntimeError.new(result.inspect) unless result['ok'] - sleep 1 # allow tapicero to do its job - @user_id = result['id'] + sleep 1 unless fast # allow tapicero to do its job + @user = {'_id' => result["id"], '_rev' => result["rev"]} + end + + def delete_user(fast = false) + return if @user.nil? or @user['_deleted'] + result = database.delete_doc @user + raise RuntimeError.new(result.inspect) unless result['ok'] + @user['_deleted'] = true + sleep 1 unless fast # allow tapicero to do its job end def user_database - host.database(config.options[:db_prefix] + @user_id) + host.database(config.options[:db_prefix] + @user['_id']) end def database -- cgit v1.2.3