From 0d00d6a8f6eaf15d2a3e5125e599f9735c85d5d6 Mon Sep 17 00:00:00 2001 From: elijah Date: Tue, 17 Mar 2015 15:03:33 -0700 Subject: added support for tmp_users db. not backward compatible with prior config files (seq_file changed to seq_dir) --- test/badconfig.yaml | 4 +--- test/config.yaml | 7 ++++--- test/integration/tmp_user_test.rb | 37 +++++++++++++++++++++++++++++++++++++ test/support/integration_test.rb | 16 ++++++++-------- test/test_helper.rb | 9 +++++++++ 5 files changed, 59 insertions(+), 14 deletions(-) create mode 100644 test/integration/tmp_user_test.rb (limited to 'test') diff --git a/test/badconfig.yaml b/test/badconfig.yaml index 4941806..263185a 100644 --- a/test/badconfig.yaml +++ b/test/badconfig.yaml @@ -13,8 +13,6 @@ connection: prefix: "tapicero_test" suffix: "" -# file to store the last processed user record in so we can resume after -# a restart: -seq_file: "/tmp/tapicero_test.seq" +seq_dir: "/tmp/tapicero_test" log_file: "/tmp/tapicero_test.log" log_level: debug diff --git a/test/config.yaml b/test/config.yaml index 601c104..28da68c 100644 --- a/test/config.yaml +++ b/test/config.yaml @@ -12,8 +12,9 @@ connection: prefix: "tapicero_test" suffix: "" -# file to store the last processed user record in so we can resume after -# a restart: -seq_file: "/tmp/tapicero_test.seq" log_file: "/tmp/tapicero_test.log" log_level: debug + +# the directory to store the last processed user record in so +# we can resume after a restart: +seq_dir: "/tmp/tapicero" diff --git a/test/integration/tmp_user_test.rb b/test/integration/tmp_user_test.rb new file mode 100644 index 0000000..dff8f4e --- /dev/null +++ b/test/integration/tmp_user_test.rb @@ -0,0 +1,37 @@ +require_relative '../test_helper.rb' + +class TmpUserTest < Tapicero::IntegrationTest + + def setup + TapiceroProcess.run_with_config("test/config.yaml") + create_user(false, 'tmp_users') + sleep 0.1 + end + + def teardown + delete_user(true, 'tmp_users') + end + + def test_creates_user_db + assert_database_exists user_database + end + + def test_configures_security + assert_equal config.options[:security], user_database.get('_security') + end + + def test_stores_design_docs + assert_equal ['_design/docs', '_design/syncs', '_design/transactions'], + design_docs(user_database).map{|doc| doc["id"]}.sort + end + + def test_deletes_user_db + assert_database_exists user_database + delete_user(false, 'tmp_users') + assert !host.databases.include?(user_database.name), 'user db must not exist' + end + + def design_docs(db) + db.documents(startkey: '_design', endkey: '_design'.succ)["rows"] + end +end diff --git a/test/support/integration_test.rb b/test/support/integration_test.rb index 552b0a1..86553c2 100644 --- a/test/support/integration_test.rb +++ b/test/support/integration_test.rb @@ -5,16 +5,16 @@ module Tapicero # 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 + def create_user(fast = false, db_name = 'users') + result = database(db_name).save_doc :some => :content raise RuntimeError.new(result.inspect) unless result['ok'] sleep 1 unless fast # allow tapicero to do its job @user = {'_id' => result["id"], '_rev' => result["rev"]} end - def delete_user(fast = false) + def delete_user(fast = false, db_name = 'users') return if @user.nil? or @user['_deleted'] - result = database.delete_doc @user + result = database(db_name).delete_doc @user raise RuntimeError.new(result.inspect) unless result['ok'] @user['_deleted'] = true sleep 1 unless fast # allow tapicero to do its job @@ -26,12 +26,12 @@ module Tapicero puts 'failed to find per user db' end - def database - @database ||= host.database!(database_name) + def database(db_name='users') + @database ||= host.database!(database_name_with_prefix(db_name)) end - def database_name - config.complete_db_name('users') + def database_name_with_prefix(db_name) + config.complete_db_name(db_name) end def host diff --git a/test/test_helper.rb b/test/test_helper.rb index 31eaa2b..1442148 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -33,6 +33,15 @@ MiniTest.after_run { TapiceroProcess.kill! } +# delete prior user dbs so they don't fill up the local couchdb. +CouchRest::Server.new.tap do |server| + server.databases.each do |db_name| + if db_name =~ /^user-[a-f0-9]{32}$/ + server.database(db_name).delete! + end + end +end + puts puts " REMINDER: check /tmp/tapicero.log for errors" puts \ No newline at end of file -- cgit v1.2.3