summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriilyak <iilyak@users.noreply.github.com>2018-12-27 13:04:12 -0800
committerGitHub <noreply@github.com>2018-12-27 13:04:12 -0800
commitea20abc656c099734dcfea17d07a6747103a4fc9 (patch)
treec24ff12ef90d8193caab4c93fb332afe3aaabaee
parente97f0297234b03b9b4a9904c7403b703a2a9a735 (diff)
parentadd9fae9336c0fa84eaafb3f5ed43ea1294ad16f (diff)
downloadcouchdb-ea20abc656c099734dcfea17d07a6747103a4fc9.tar.gz
Merge pull request #1829 from cloudant/elixir-test-improvements
Elixir test improvements
-rw-r--r--test/elixir/lib/couch/db_test.ex6
-rw-r--r--test/elixir/test/all_docs_test.exs40
-rw-r--r--test/elixir/test/cluster_with_quorum_test.exs18
-rw-r--r--test/elixir/test/cluster_without_quorum_test.exs18
-rw-r--r--test/elixir/test/rewrite_test.exs6
-rw-r--r--test/elixir/test/security_validation_test.exs6
6 files changed, 61 insertions, 33 deletions
diff --git a/test/elixir/lib/couch/db_test.ex b/test/elixir/lib/couch/db_test.ex
index efd02f129..899237635 100644
--- a/test/elixir/lib/couch/db_test.ex
+++ b/test/elixir/lib/couch/db_test.ex
@@ -156,21 +156,21 @@ defmodule Couch.DBTest do
def create_db(db_name) do
resp = Couch.put("/#{db_name}")
- assert resp.status_code == 201
+ assert resp.status_code in [201, 202]
assert resp.body == %{"ok" => true}
{:ok, resp}
end
def delete_db(db_name) do
resp = Couch.delete("/#{db_name}")
- assert resp.status_code == 200
+ assert resp.status_code in [200, 202]
assert resp.body == %{"ok" => true}
{:ok, resp}
end
def create_doc(db_name, body) do
resp = Couch.post("/#{db_name}", body: body)
- assert resp.status_code == 201
+ assert resp.status_code in [201, 202]
assert resp.body["ok"]
{:ok, resp}
end
diff --git a/test/elixir/test/all_docs_test.exs b/test/elixir/test/all_docs_test.exs
index 21dcb616b..b8f21e7c0 100644
--- a/test/elixir/test/all_docs_test.exs
+++ b/test/elixir/test/all_docs_test.exs
@@ -46,7 +46,8 @@ defmodule AllDocsTest do
# Confirm that queries may assume raw collation
resp =
- Couch.get("/#{db_name}/_all_docs",
+ Couch.get(
+ "/#{db_name}/_all_docs",
query: %{
:startkey => "\"org.couchdb.user:\"",
:endkey => "\"org.couchdb.user;\""
@@ -68,9 +69,12 @@ defmodule AllDocsTest do
assert Couch.delete("/#{db_name}/1", query: %{:rev => doc1["_rev"]}).body["ok"]
changes = Couch.get("/#{db_name}/_changes").body["results"]
assert length(changes) == 4
- deleted = Enum.filter(changes, fn row -> row["deleted"] end)
- assert length(deleted) == 1
- assert hd(deleted)["id"] == "1"
+
+ retry_until(fn ->
+ deleted = Enum.filter(changes, fn row -> row["deleted"] end)
+ assert length(deleted) == 1
+ assert hd(deleted)["id"] == "1"
+ end)
# (remember old seq)
orig_doc = Enum.find(changes, fn row -> row["id"] == "3" end)
@@ -99,7 +103,8 @@ defmodule AllDocsTest do
# Test _all_docs with keys
rows =
- Couch.post("/#{db_name}/_all_docs",
+ Couch.post(
+ "/#{db_name}/_all_docs",
query: %{:include_docs => true},
body: %{:keys => ["1"]}
).body["rows"]
@@ -124,18 +129,23 @@ defmodule AllDocsTest do
:value => "Z"
}
- assert Couch.put("/#{db_name}/3", query: %{:new_edits => false}, body: conflicted_doc1).body[
- "ok"
- ]
+ assert Couch.put(
+ "/#{db_name}/3",
+ query: %{:new_edits => false},
+ body: conflicted_doc1
+ ).body["ok"]
- assert Couch.put("/#{db_name}/3", query: %{:new_edits => false}, body: conflicted_doc2).body[
- "ok"
- ]
+ assert Couch.put(
+ "/#{db_name}/3",
+ query: %{:new_edits => false},
+ body: conflicted_doc2
+ ).body["ok"]
win_rev = Couch.get("/#{db_name}/3").body
changes =
- Couch.get("/#{db_name}/_changes",
+ Couch.get(
+ "/#{db_name}/_changes",
query: %{:include_docs => true, :conflicts => true, :style => "all_docs"}
).body["results"]
@@ -147,7 +157,8 @@ defmodule AllDocsTest do
assert length(doc3["doc"]["_conflicts"]) == 2
rows =
- Couch.get("/#{db_name}/_all_docs",
+ Couch.get(
+ "/#{db_name}/_all_docs",
query: %{:include_docs => true, :conflicts => true}
).body["rows"]
@@ -166,7 +177,8 @@ defmodule AllDocsTest do
assert Couch.post("/#{db_name}", body: %{:_id => "a", :foo => "a"}).body["ok"]
rows =
- Couch.get("/#{db_name}/_all_docs",
+ Couch.get(
+ "/#{db_name}/_all_docs",
query: %{:startkey => "\"Z\"", :endkey => "\"Z\""}
).body["rows"]
diff --git a/test/elixir/test/cluster_with_quorum_test.exs b/test/elixir/test/cluster_with_quorum_test.exs
index 76fc9b449..d07b18fea 100644
--- a/test/elixir/test/cluster_with_quorum_test.exs
+++ b/test/elixir/test/cluster_with_quorum_test.exs
@@ -51,7 +51,8 @@ defmodule WithQuorumTest do
Couch.put("/#{db_name}")
resp =
- Couch.post("/#{context[:db_name]}",
+ Couch.post(
+ "/#{context[:db_name]}",
query: %{:w => 3},
body: %{:_id => "0", :a => 1}
)
@@ -63,7 +64,8 @@ defmodule WithQuorumTest do
rev = resp.body["_rev"]
resp =
- Couch.put("/#{context[:db_name]}/0",
+ Couch.put(
+ "/#{context[:db_name]}/0",
query: %{:w => 3},
body: %{:_id => "0", :_rev => rev, :a => 2}
)
@@ -85,7 +87,8 @@ defmodule WithQuorumTest do
db_name = context[:db_name]
Couch.put("/#{db_name}")
- Couch.post("/#{context[:db_name]}",
+ Couch.post(
+ "/#{context[:db_name]}",
body: %{:_id => "0", :a => 1}
)
@@ -130,7 +133,8 @@ defmodule WithQuorumTest do
rev = resp.body["rev"]
resp =
- Couch.put("/#{context[:db_name]}/0/foo.txt",
+ Couch.put(
+ "/#{context[:db_name]}/0/foo.txt",
query: %{:rev => rev},
body: "This is a no bas64 encoded text",
headers: ["Content-Type": "text/plain;charset=utf-8"]
@@ -155,7 +159,8 @@ defmodule WithQuorumTest do
rev = resp.body["rev"]
resp =
- Couch.put("/#{context[:db_name]}/0/foo.txt",
+ Couch.put(
+ "/#{context[:db_name]}/0/foo.txt",
query: %{:rev => rev, :w => 3},
body: "This is a no bas64 encoded text",
headers: ["Content-Type": "text/plain;charset=utf-8"]
@@ -167,7 +172,8 @@ defmodule WithQuorumTest do
rev = resp.body["rev"]
resp =
- Couch.delete("/#{context[:db_name]}/0/foo.txt",
+ Couch.delete(
+ "/#{context[:db_name]}/0/foo.txt",
query: %{:rev => rev, :w => 3}
)
diff --git a/test/elixir/test/cluster_without_quorum_test.exs b/test/elixir/test/cluster_without_quorum_test.exs
index a0bdcc37a..4eee1e05a 100644
--- a/test/elixir/test/cluster_without_quorum_test.exs
+++ b/test/elixir/test/cluster_without_quorum_test.exs
@@ -50,7 +50,8 @@ defmodule WithoutQuorumTest do
Couch.put("/#{db_name}")
resp =
- Couch.post("/#{context[:db_name]}",
+ Couch.post(
+ "/#{context[:db_name]}",
query: %{:w => 1},
body: %{:_id => "0", :a => 1}
)
@@ -62,7 +63,8 @@ defmodule WithoutQuorumTest do
rev = resp.body["_rev"]
resp =
- Couch.put("/#{context[:db_name]}/0",
+ Couch.put(
+ "/#{context[:db_name]}/0",
query: %{:w => 1},
body: %{:_id => "0", :_rev => rev, :a => 2}
)
@@ -84,7 +86,8 @@ defmodule WithoutQuorumTest do
db_name = context[:db_name]
Couch.put("/#{db_name}")
- Couch.post("/#{context[:db_name]}",
+ Couch.post(
+ "/#{context[:db_name]}",
body: %{:_id => "0", :a => 1}
)
@@ -129,7 +132,8 @@ defmodule WithoutQuorumTest do
rev = resp.body["rev"]
resp =
- Couch.put("/#{context[:db_name]}/0/foo.txt",
+ Couch.put(
+ "/#{context[:db_name]}/0/foo.txt",
query: %{:rev => rev},
body: "This is a no bas64 encoded text",
headers: ["Content-Type": "text/plain;charset=utf-8"]
@@ -154,7 +158,8 @@ defmodule WithoutQuorumTest do
rev = resp.body["rev"]
resp =
- Couch.put("/#{context[:db_name]}/0/foo.txt",
+ Couch.put(
+ "/#{context[:db_name]}/0/foo.txt",
query: %{:rev => rev, :w => 1},
body: "This is a no bas64 encoded text",
headers: ["Content-Type": "text/plain;charset=utf-8"]
@@ -166,7 +171,8 @@ defmodule WithoutQuorumTest do
rev = resp.body["rev"]
resp =
- Couch.delete("/#{context[:db_name]}/0/foo.txt",
+ Couch.delete(
+ "/#{context[:db_name]}/0/foo.txt",
query: %{:rev => rev, :w => 1}
)
diff --git a/test/elixir/test/rewrite_test.exs b/test/elixir/test/rewrite_test.exs
index 250eb53d7..51acc8bba 100644
--- a/test/elixir/test/rewrite_test.exs
+++ b/test/elixir/test/rewrite_test.exs
@@ -285,12 +285,14 @@ defmodule RewriteTest do
assert Couch.put("/#{db_name}/_design/test", body: ddoc).body["ok"]
- assert Couch.post("/#{db_name}/_bulk_docs",
+ assert Couch.post(
+ "/#{db_name}/_bulk_docs",
body: %{:docs => docs1},
query: %{w: 3}
).status_code == 201
- assert Couch.post("/#{db_name}/_bulk_docs",
+ assert Couch.post(
+ "/#{db_name}/_bulk_docs",
body: %{:docs => docs2},
query: %{w: 3}
).status_code == 201
diff --git a/test/elixir/test/security_validation_test.exs b/test/elixir/test/security_validation_test.exs
index 5f4ddba8c..56c4ec31b 100644
--- a/test/elixir/test/security_validation_test.exs
+++ b/test/elixir/test/security_validation_test.exs
@@ -130,7 +130,8 @@ defmodule SecurityValidationTest do
headers = @auth_headers[:tom]
# attempt to save doc in replication context, eg ?new_edits=false
resp =
- Couch.put("/#{db_name}/#{ddoc[:_id]}",
+ Couch.put(
+ "/#{db_name}/#{ddoc[:_id]}",
body: ddoc,
headers: headers,
query: %{new_edits: false}
@@ -164,7 +165,8 @@ defmodule SecurityValidationTest do
assert resp.body["reason"] == "Documents must have an author field"
# Jerry can write the document
- assert Couch.put("/#{db_name}/test_doc",
+ assert Couch.put(
+ "/#{db_name}/test_doc",
body: %{foo: 1, author: "jerry"},
headers: jerry
).body["ok"]