summaryrefslogtreecommitdiff
path: root/tests/helpers/couchdb_helper.rb
diff options
context:
space:
mode:
authorMicah <micah@leap.se>2016-05-10 14:48:26 -0400
committerMicah <micah@leap.se>2016-05-10 14:48:26 -0400
commit86c85582065c391aa13c0b9b397dfd1aa2e2ac7b (patch)
tree7c027409a517d862864bf3650f4a8a66f615162d /tests/helpers/couchdb_helper.rb
parent70b1c648b94e6c007b9241a4661f33881e74485f (diff)
parent66b4c6b5ec6fe2f242020845fe92715ae2cdcc1e (diff)
Merge tag '0.8.0'
Release 0.8.0
Diffstat (limited to 'tests/helpers/couchdb_helper.rb')
-rw-r--r--tests/helpers/couchdb_helper.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/helpers/couchdb_helper.rb b/tests/helpers/couchdb_helper.rb
index d4d3c0e0..b9085c1e 100644
--- a/tests/helpers/couchdb_helper.rb
+++ b/tests/helpers/couchdb_helper.rb
@@ -15,6 +15,7 @@ class LeapTest
# connect_port: 15984
#
def couchdb_urls_via_stunnel(path="", options=nil)
+ path = path.gsub('"', '%22')
if options && options[:username] && options[:password]
userpart = "%{username}:%{password}@" % options
else
@@ -46,6 +47,7 @@ class LeapTest
# writable: true
#
def couchdb_url_via_haproxy(path="", options=nil)
+ path = path.gsub('"', '%22')
if options && options[:username] && options[:password]
userpart = "%{username}:%{password}@" % options
else
@@ -66,6 +68,7 @@ class LeapTest
# port: 5984
#
def couchdb_url_via_localhost(path="", options=nil)
+ path = path.gsub('"', '%22')
port = (options && options[:port]) || assert_property('couch.port')
if options && options[:username]
password = property("couch.users.%{username}.password" % options)
@@ -100,4 +103,40 @@ class LeapTest
end
end
+ def assert_destroy_user_db(user_id, options=nil)
+ db_name = "user-#{user_id}"
+ url = couchdb_url("/#{db_name}", options)
+ http_options = {:ok_codes => [200, 404]} # ignore missing dbs
+ assert_delete(url, nil, http_options)
+ end
+
+ def assert_create_user_db(user_id, options=nil)
+ db_name = "user-#{user_id}"
+ url = couchdb_url("/#{db_name}", options)
+ http_options = {:ok_codes => [200, 404]} # ignore missing dbs
+ assert_put(url, nil, :format => :json) do |body|
+ assert response = JSON.parse(body), "PUT response should be JSON"
+ assert response["ok"], "PUT response should be OK"
+ end
+ end
+
+ #
+ # returns true if the per-user db created by soledad-server exists.
+ #
+ def user_db_exists?(user_id, options=nil)
+ db_name = "user-#{user_id}"
+ url = couchdb_url("/#{db_name}", options)
+ get(url) do |body, response, error|
+ if response.nil?
+ fail "could not query couchdb #{url}: #{error}\n#{body}"
+ elsif response.code.to_i == 200
+ return true
+ elsif response.code.to_i == 404
+ return false
+ else
+ fail ["could not query couchdb #{url}: expected response code 200 or 404, but got #{response.code}.", error, body].compact.join("\n")
+ end
+ end
+ end
+
end \ No newline at end of file