diff options
author | jessib <jessib@riseup.net> | 2014-02-04 10:33:27 -0800 |
---|---|---|
committer | jessib <jessib@riseup.net> | 2014-02-04 10:33:27 -0800 |
commit | c7f376cdc02fe10c7e2a51c7d52475ab34451577 (patch) | |
tree | 75c52cbbd43bb55d155c301855677fcba123a2c7 /test | |
parent | cda7ebacf35bcc0fcf233e5a23b958ed751fb108 (diff) | |
parent | c3cb71ca5e6d32960e4493d85799f3706ea91fe8 (diff) |
Merge pull request #9 from azul/test/integration-with-travis
Test/integration with travis
Diffstat (limited to 'test')
-rw-r--r-- | test/config.yaml | 19 | ||||
-rw-r--r-- | test/config/config.yaml | 5 | ||||
-rw-r--r-- | test/integration/tapicero_test.rb | 37 | ||||
-rw-r--r-- | test/integration/test_setup_test.rb | 15 | ||||
-rw-r--r-- | test/setup_couch.sh | 13 | ||||
-rw-r--r-- | test/support/integration_test.rb | 39 | ||||
-rw-r--r-- | test/test_helper.rb | 6 | ||||
-rw-r--r-- | test/unit/couch_changes_test.rb | 32 | ||||
-rw-r--r-- | test/unit/couch_stream_test.rb | 29 |
9 files changed, 128 insertions, 67 deletions
diff --git a/test/config.yaml b/test/config.yaml new file mode 100644 index 0000000..e59b4de --- /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: "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 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/integration/tapicero_test.rb b/test/integration/tapicero_test.rb new file mode 100644 index 0000000..88e3715 --- /dev/null +++ b/test/integration/tapicero_test.rb @@ -0,0 +1,37 @@ +require_relative '../test_helper.rb' + +class TapiceroTest < Tapicero::IntegrationTest + + 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 # ensure db exists in couch. + 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_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 +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/setup_couch.sh b/test/setup_couch.sh new file mode 100644 index 0000000..c11993d --- /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/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":[]}}' +echo "adding admin :" +curl -X PUT $HOST/_config/admins/anna -d '"secret"' diff --git a/test/support/integration_test.rb b/test/support/integration_test.rb new file mode 100644 index 0000000..b28c0e1 --- /dev/null +++ b/test/support/integration_test.rb @@ -0,0 +1,39 @@ +module Tapicero + class IntegrationTest < MiniTest::Unit::TestCase + + def create_user(fast = false) + result = database.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) + 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']) + 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 3857e2c..da8b88c 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -6,5 +6,9 @@ $:.unshift File.expand_path('lib', BASE_DIR) require 'mocha/setup' -TAPICERO_CONFIG = "test/config/config.yaml" +require 'tapicero/version' +Tapicero::CONFIGS << "test/config.yaml" require 'tapicero' + + +require_relative 'support/integration_test' 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 |