This is an automated email from the ASF dual-hosted git repository.
jiahuili430 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/couchdb.git
The following commit(s) were added to refs/heads/main by this push:
new d9c059e12 Update Elixir tests and config files (#5822)
d9c059e12 is described below
commit d9c059e128549cdac397817aeaa91cf3e4582f0e
Author: Jiahui Li <[email protected]>
AuthorDate: Mon Dec 15 11:22:05 2025 -0600
Update Elixir tests and config files (#5822)
* Update Elixir tests
- Elixir unit tests need to end with `_test.exs` to run.
- large_docs_test.exs
- reshard_changes_feed_test.exs
- disk_monitor_test.exs
- 04_key_test.exs
- 25_beginswith_test.exs
- The `Enum.each()` method cannot run tests because it iterates
through the data at runtime, while the test macro is defined at
compile time. Therefore, replace it with a for loop.
- rewrite_js_test.exs
- rewrite_test.exs
- Update outdated tests.
- cluster_with_quorum_test.exs
- cluster_without_quorum_test.exs
- cookie_auth_test.exs
* Fix Elixir test compile-time warnings
- warning: variable "db" is unused (if the variable is not meant
to be used, prefix it with an underscore).
- friend_docs.ex
- limit_docs.ex
- warning: using single-quoted strings to represent charlists is
deprecated.
- user_docs.ex
- warning: trailing commas are not allowed inside function/macro
call arguments.
- 02_basic_find_test.exs
* Update Elixir test config files
- config/search.elixir
- config/skip.elixir
- config/suite.elixir
---
test/elixir/test/cluster_with_quorum_test.exs | 20 +-
test/elixir/test/cluster_without_quorum_test.exs | 47 +-
test/elixir/test/config/search.elixir | 3 +-
test/elixir/test/config/skip.elixir | 21 +-
test/elixir/test/config/suite.elixir | 54 +-
test/elixir/test/cookie_auth_test.exs | 41 +-
.../{disk_monitor.exs => disk_monitor_test.exs} | 0
.../{large_docs_text.exs => large_docs_test.exs} | 0
test/elixir/test/mango/02_basic_find_test.exs | 6 +-
.../mango/{04-key-tests.exs => 04_key_test.exs} | 0
...-beginswith-test.exs => 25_beginswith_test.exs} | 0
...nges_feed.exs => reshard_changes_feed_test.exs} | 0
test/elixir/test/rewrite_js_test.exs | 361 ++++----
test/elixir/test/rewrite_test.exs | 937 +++++++++++----------
test/elixir/test/support/friend_docs.ex | 2 +-
test/elixir/test/support/limit_docs.ex | 2 +-
test/elixir/test/support/user_docs.ex | 2 +-
17 files changed, 725 insertions(+), 771 deletions(-)
diff --git a/test/elixir/test/cluster_with_quorum_test.exs
b/test/elixir/test/cluster_with_quorum_test.exs
index fc3b28a0b..718e3f41b 100644
--- a/test/elixir/test/cluster_with_quorum_test.exs
+++ b/test/elixir/test/cluster_with_quorum_test.exs
@@ -7,14 +7,14 @@ defmodule WithQuorumTest do
Test CouchDB API in a cluster without quorum.
"""
@tag :with_db_name
- test "Creating/Deleting DB should return 201-Created/202-Acepted", context do
+ test "Creating/Deleting DB should return 201-Created/200-OK", context do
db_name = context[:db_name]
resp = Couch.put("/#{db_name}")
msg = "Should return 201-Created"
assert resp.status_code in [201, 202], msg
resp = Couch.delete("/#{db_name}")
- msg = "Should return 202-Acepted"
- assert resp.status_code == 202, msg
+ msg = "Should return 200-OK"
+ assert resp.status_code == 200, msg
end
@tag :with_db_name
@@ -45,7 +45,7 @@ defmodule WithQuorumTest do
end
@tag :with_db_name
- test "Creating-Updating/Deleting doc with overriden quorum should return
202-Acepted/200-OK",
+ test "Creating-Updating/Deleting doc with overridden quorum should return
202-Accepted/200-OK",
context do
db_name = context[:db_name]
Couch.put("/#{db_name}")
@@ -57,7 +57,7 @@ defmodule WithQuorumTest do
body: %{:_id => "0", :a => 1}
)
- msg = "Should return 202-Acepted"
+ msg = "Should return 202-Accepted"
assert resp.status_code == 202, msg
resp = Couch.get("/#{context[:db_name]}/0")
@@ -70,7 +70,7 @@ defmodule WithQuorumTest do
body: %{:_id => "0", :_rev => rev, :a => 2}
)
- msg = "Should return 202-Acepted"
+ msg = "Should return 202-Accepted"
assert resp.status_code == 202, msg
resp = Couch.get("/#{context[:db_name]}/0")
@@ -114,12 +114,12 @@ defmodule WithQuorumTest do
end
@tag :with_db_name
- test "Bulk docs overriden quorum should return 202-Acepted", context do
+ test "Bulk docs overridden quorum should return 202-Accepted", context do
db_name = context[:db_name]
Couch.put("/#{db_name}")
docs = create_docs(@doc_range)
resp = Couch.post("/#{db_name}/_bulk_docs", query: %{:w => 3}, body:
%{docs: docs})
- msg = "Should return 202-Acepted"
+ msg = "Should return 202-Accepted"
assert resp.status_code == 202, msg
Couch.delete("/#{db_name}")
@@ -152,7 +152,7 @@ defmodule WithQuorumTest do
end
@tag :with_db_name
- test "Attachments overriden quorum should return 202-Acepted", context do
+ test "Attachments overridden quorum should return 202-Accepted", context do
db_name = context[:db_name]
Couch.put("/#{db_name}")
resp = Couch.post("/#{context[:db_name]}", body: %{:_id => "0"})
@@ -166,7 +166,7 @@ defmodule WithQuorumTest do
headers: ["Content-Type": "text/plain;charset=utf-8"]
)
- msg = "Should return 202-Acepted"
+ msg = "Should return 202-Accepted"
assert resp.status_code == 202, msg
rev = resp.body["rev"]
diff --git a/test/elixir/test/cluster_without_quorum_test.exs
b/test/elixir/test/cluster_without_quorum_test.exs
index e0095c351..16341c6ec 100644
--- a/test/elixir/test/cluster_without_quorum_test.exs
+++ b/test/elixir/test/cluster_without_quorum_test.exs
@@ -7,23 +7,24 @@ defmodule WithoutQuorumTest do
Test CouchDB API in a cluster without quorum.
"""
@tag :with_db_name
- test "Creating/Deleting DB should return 202-Acepted", context do
+ test "Creating/Deleting DB should return 201-Created/200-OK", context do
db_name = context[:db_name]
resp = Couch.put("/#{db_name}")
- msg = "Should return 202-Acepted"
- assert resp.status_code == 202, msg
+ msg = "Should return 201-Created"
+ assert resp.status_code == 201, msg
resp = Couch.delete("/#{db_name}")
- assert resp.status_code == 202, msg
+ msg = "Should return 200-OK"
+ assert resp.status_code == 200, msg
end
@tag :with_db_name
- test "Creating/Updating/Deleting doc should return 202-Acepted", context do
+ test "Creating/Updating/Deleting doc should return 201-Created/200-OK",
context do
db_name = context[:db_name]
Couch.put("/#{db_name}")
resp = Couch.post("/#{context[:db_name]}", body: %{:_id => "0", :a => 1})
- msg = "Should return 202-Acepted"
- assert resp.status_code == 202, msg
+ msg = "Should return 201-Created"
+ assert resp.status_code == 201, msg
resp = Couch.get("/#{context[:db_name]}/0")
rev = resp.body["_rev"]
@@ -31,20 +32,20 @@ defmodule WithoutQuorumTest do
resp =
Couch.put("/#{context[:db_name]}/0", body: %{:_id => "0", :_rev => rev,
:a => 2})
- msg = "Should return 202-Acepted"
- assert resp.status_code == 202, msg
+ msg = "Should return 201-Created"
+ assert resp.status_code == 201, msg
resp = Couch.get("/#{context[:db_name]}/0")
rev = resp.body["_rev"]
resp = Couch.delete("/#{context[:db_name]}/0", query: %{:rev => rev})
- msg = "Should return 202-Acepted"
- assert resp.status_code == 202, msg
+ msg = "Should return 200-OK"
+ assert resp.status_code == 200, msg
Couch.delete("/#{db_name}")
end
@tag :with_db_name
- test "Creating-Updating/Deleting doc with overriden quorum should return
201-Created/200-OK",
+ test "Creating-Updating/Deleting doc with overridden quorum should return
201-Created/200-OK",
context do
db_name = context[:db_name]
Couch.put("/#{db_name}")
@@ -82,7 +83,7 @@ defmodule WithoutQuorumTest do
end
@tag :with_db_name
- test "Copy doc should return 202-Acepted", context do
+ test "Copy doc should return 201-Created", context do
db_name = context[:db_name]
Couch.put("/#{db_name}")
@@ -93,27 +94,27 @@ defmodule WithoutQuorumTest do
headers = [Destination: "1"]
resp = Couch.request(:copy, "/#{context[:db_name]}/0", headers: headers)
- msg = "Should return 202-Acepted"
- assert resp.status_code == 202, msg
+ msg = "Should return 201-Created"
+ assert resp.status_code == 201, msg
Couch.delete("/#{db_name}")
end
@doc_range 1..5
@tag :with_db_name
- test "Bulk docs should return 202-Acepted", context do
+ test "Bulk docs should return 201-Created", context do
db_name = context[:db_name]
Couch.put("/#{db_name}")
docs = create_docs(@doc_range)
resp = Couch.post("/#{db_name}/_bulk_docs", body: %{docs: docs})
- msg = "Should return 202-Acepted"
- assert resp.status_code == 202, msg
+ msg = "Should return 201-Created"
+ assert resp.status_code == 201, msg
Couch.delete("/#{db_name}")
end
@tag :with_db_name
- test "Bulk docs overriden quorum should return 201-Created", context do
+ test "Bulk docs overridden quorum should return 201-Created", context do
db_name = context[:db_name]
Couch.put("/#{db_name}")
docs = create_docs(@doc_range)
@@ -125,7 +126,7 @@ defmodule WithoutQuorumTest do
end
@tag :with_db_name
- test "Attachments should return 202-Acepted", context do
+ test "Attachments should return 201-Created", context do
db_name = context[:db_name]
Couch.put("/#{db_name}")
resp = Couch.post("/#{context[:db_name]}", body: %{:_id => "0"})
@@ -139,8 +140,8 @@ defmodule WithoutQuorumTest do
headers: ["Content-Type": "text/plain;charset=utf-8"]
)
- msg = "Should return 202-Acepted"
- assert resp.status_code == 202, msg
+ msg = "Should return 201-Created"
+ assert resp.status_code == 201, msg
rev = resp.body["rev"]
resp = Couch.delete("/#{context[:db_name]}/0/foo.txt", query: %{:rev =>
rev})
@@ -151,7 +152,7 @@ defmodule WithoutQuorumTest do
end
@tag :with_db_name
- test "Attachments overriden quorum should return 201-Created", context do
+ test "Attachments overridden quorum should return 201-Created", context do
db_name = context[:db_name]
Couch.put("/#{db_name}")
resp = Couch.post("/#{context[:db_name]}", body: %{:_id => "0"})
diff --git a/test/elixir/test/config/search.elixir
b/test/elixir/test/config/search.elixir
index f59980d74..3ac84cef1 100644
--- a/test/elixir/test/config/search.elixir
+++ b/test/elixir/test/config/search.elixir
@@ -31,7 +31,8 @@
"facet counts, non-empty",
"facet counts, empty",
"facet ranges, empty",
- "facet ranges, non-empty"
+ "facet ranges, non-empty",
+ "timeouts do not expose internal state"
],
"ElemMatchTests": [
"elem match non object"
diff --git a/test/elixir/test/config/skip.elixir
b/test/elixir/test/config/skip.elixir
index be427a740..7d39ee2ee 100644
--- a/test/elixir/test/config/skip.elixir
+++ b/test/elixir/test/config/skip.elixir
@@ -1,26 +1,7 @@
%{
- "CookieAuthTest": [
- "cookie auth"
- ],
- "ReaderACLTest": [
- "unrestricted db can be read"
- ],
"ReplicationTest": [
- "non-admin user on target - remote-to-remote",
"non-admin or reader user on source - remote-to-remote",
+ "non-admin user on target - remote-to-remote",
"unauthorized replication cancellation"
- ],
- "SecurityValidationTest": [
- "Author presence and user security when replicated"
- ],
- "WithQuorumTest": [
- "Creating/Deleting DB should return 201-Created/202-Acepted"
- ],
- "WithoutQuorumTest": [
- "Attachments should return 202-Acepted",
- "Bulk docs should return 202-Acepted",
- "Copy doc should return 202-Acepted",
- "Creating/Deleting DB should return 202-Acepted",
- "Creating/Updating/Deleting doc should return 202-Acepted"
]
}
diff --git a/test/elixir/test/config/suite.elixir
b/test/elixir/test/config/suite.elixir
index bf95f5dce..520b40a7f 100644
--- a/test/elixir/test/config/suite.elixir
+++ b/test/elixir/test/config/suite.elixir
@@ -36,7 +36,6 @@
"etags for attachments",
"implicit doc creation allows creating docs with a reserved id.
COUCHDB-565",
"large attachments COUCHDB-366",
- "md5 header for attachments",
"reads attachment successfully",
"saves attachment successfully",
"saves binary",
@@ -48,7 +47,7 @@
],
"AuthLockoutTest": [
"lockout after multiple failed authentications",
- "lockout warning after multiple failed authentications"
+ "do not lockout after multiple failed authentications"
],
"BasicsTest": [
"'+' in document name should encode to '+'",
@@ -156,7 +155,8 @@
"Only JSON strings are accepted"
],
"CookieAuthTest": [
- "cookie auth"
+ "cookie auth",
+ "header doesn't contain set-cookie"
],
"CopyDocTest": [
"Copy doc tests"
@@ -257,6 +257,9 @@
"jwt auth with required iss claim",
"jwt auth without secret"
],
+ "LargeDocsTest": [
+ "Large docs"
+ ],
"ListViewsTest": [
"COUCHDB-1113",
"HTTP header response set after getRow() called in _list function",
@@ -413,7 +416,7 @@
"view updates properly remove old keys"
],
"PasswordCacheTest": [
- "password cache"
+ "password hash cache"
],
"ProxyAuthTest": [
"proxy auth with secret",
@@ -458,8 +461,6 @@
"default headers returned for _scheduler/docs ",
"default headers returned for _scheduler/jobs",
"filtered replications - remote-to-remote",
- "non-admin or reader user on source - remote-to-remote",
- "non-admin user on target - remote-to-remote",
"replicate with since_seq - remote-to-remote",
"replicating attachment without conflict - COUCHDB-885",
"replication by doc ids - remote-to-remote",
@@ -467,7 +468,6 @@
"replication restarts after filter change - COUCHDB-892 -
remote-to-remote",
"simple remote-to-remote replication - remote-to-remote",
"source database not found with host",
- "unauthorized replication cancellation",
"validate_doc_update failure replications - remote-to-remote"
],
"ReshardAllDocsTest": [
@@ -481,6 +481,9 @@
"split q=2 shards on node1 (2 jobs)",
"toggle global state"
],
+ "ReshardChangesFeedTest": [
+ "all_docs after splitting all shards on node1"
+ ],
"RevStemmingTest": [
"revs limit is kept after compaction",
"revs limit produces replication conflict ",
@@ -493,8 +496,8 @@
"multiple updates with same _rev raise conflict errors"
],
"RewriteJSTest": [
- "Test basic js rewrites on test_rewrite_suite_db",
- "Test basic js rewrites on test_rewrite_suite_db%2Fwith_slashes",
+ "basic js rewrites on test_rewrite_suite_db",
+ "basic js rewrites on test_rewrite_suite_db%2Fwith_slashes",
"early response on test_rewrite_suite_db",
"early response on test_rewrite_suite_db%2Fwith_slashes",
"loop on test_rewrite_suite_db",
@@ -505,8 +508,8 @@
"requests with body preserve the query string rewrite on
test_rewrite_suite_db%2Fwith_slashes"
],
"RewriteTest": [
- "Test basic rewrites on test_rewrite_suite_db",
- "Test basic rewrites on test_rewrite_suite_db%2Fwith_slashes",
+ "basic rewrites on test_rewrite_suite_db",
+ "basic rewrites on test_rewrite_suite_db%2Fwith_slashes",
"loop detection on test_rewrite_suite_db",
"loop detection on test_rewrite_suite_db%2Fwith_slashes",
"path relative to server on test_rewrite_suite_db",
@@ -643,7 +646,8 @@
"GET - invalid parameter combinations get rejected ",
"POST - invalid parameter combinations get rejected ",
"argument combinations",
- "dir works",
+ "dir ascending works",
+ "dir descending works",
"empty keys",
"keys in GET body (group)",
"keys in GET parameters",
@@ -711,24 +715,24 @@
"view update seq"
],
"WithQuorumTest": [
- "Attachments overriden quorum should return 202-Acepted",
+ "Attachments overridden quorum should return 202-Accepted",
"Attachments should return 201-Created",
- "Bulk docs overriden quorum should return 202-Acepted",
+ "Bulk docs overridden quorum should return 202-Accepted",
"Bulk docs should return 201-Created",
"Copy doc should return 201-Created",
"Creating-Updating/Deleting doc should return 201-Created/200-OK",
- "Creating-Updating/Deleting doc with overriden quorum should return
202-Acepted/200-OK",
- "Creating/Deleting DB should return 201-Created/202-Acepted"
+ "Creating-Updating/Deleting doc with overridden quorum should return
202-Accepted/200-OK",
+ "Creating/Deleting DB should return 201-Created/200-OK"
],
"WithoutQuorumTest": [
- "Attachments overriden quorum should return 201-Created",
- "Attachments should return 202-Acepted",
- "Bulk docs overriden quorum should return 201-Created",
- "Bulk docs should return 202-Acepted",
- "Copy doc should return 202-Acepted",
- "Creating-Updating/Deleting doc with overriden quorum should return
201-Created/200-OK",
- "Creating/Deleting DB should return 202-Acepted",
- "Creating/Updating/Deleting doc should return 202-Acepted"
+ "Attachments overridden quorum should return 201-Created",
+ "Attachments should return 201-Created",
+ "Bulk docs overridden quorum should return 201-Created",
+ "Bulk docs should return 201-Created",
+ "Copy doc should return 201-Created",
+ "Creating-Updating/Deleting doc with overridden quorum should return
201-Created/200-OK",
+ "Creating/Deleting DB should return 201-Created/200-OK",
+ "Creating/Updating/Deleting doc should return 201-Created/200-OK"
],
"BasicFindTest": [
"simple find",
@@ -801,8 +805,6 @@
"json range",
"compound key",
"sort",
- "sort fwd",
- "sort rev",
"all docs range",
"no index",
"invalid operand",
diff --git a/test/elixir/test/cookie_auth_test.exs
b/test/elixir/test/cookie_auth_test.exs
index cf9b36c7f..7cbac699f 100644
--- a/test/elixir/test/cookie_auth_test.exs
+++ b/test/elixir/test/cookie_auth_test.exs
@@ -374,45 +374,14 @@ defmodule CookieAuthTest do
login("jan", "apple")
end
- test "basic+cookie auth interaction" do
+ test "header doesn't contain set-cookie" do
# performing a successful basic authentication will create a session cookie
resp = Couch.get(
- "/_all_dbs",
- no_auth: true,
- headers: [authorization: "Basic #{:base64.encode("jan:apple")}"])
- assert resp.status_code == 200
-
- # extract cookie value
- cookie = resp.headers[:"set-cookie"]
- [token | _] = String.split(cookie, ";")
-
- # Cookie is usable on its own
- resp = Couch.get(
- "/_session",
- no_auth: true,
- headers: [cookie: token])
- assert resp.status_code == 200
- assert resp.body["userCtx"]["name"] == "jan"
- assert resp.body["info"]["authenticated"] == "cookie"
+ "/_all_dbs",
+ no_auth: true,
+ headers: [authorization: "Basic #{:base64.encode("jan:apple")}"])
- # Cookie is usable with basic auth if usernames match
- resp = Couch.get(
- "/_session",
- no_auth: true,
- headers: [
- authorization: "Basic #{:base64.encode("jan:apple")}",
- cookie: token])
assert resp.status_code == 200
- assert resp.body["userCtx"]["name"] == "jan"
- assert resp.body["info"]["authenticated"] == "cookie"
-
- # Cookie is not usable with basic auth if usernames don't match
- resp = Couch.get(
- "/_session",
- no_auth: true,
- headers: [
- authorization: "Basic #{:base64.encode("notjan:banana")}",
- cookie: token])
- assert resp.status_code == 401
+ assert resp.headers["set-cookie"] == nil
end
end
diff --git a/test/elixir/test/disk_monitor.exs
b/test/elixir/test/disk_monitor_test.exs
similarity index 100%
rename from test/elixir/test/disk_monitor.exs
rename to test/elixir/test/disk_monitor_test.exs
diff --git a/test/elixir/test/large_docs_text.exs
b/test/elixir/test/large_docs_test.exs
similarity index 100%
rename from test/elixir/test/large_docs_text.exs
rename to test/elixir/test/large_docs_test.exs
diff --git a/test/elixir/test/mango/02_basic_find_test.exs
b/test/elixir/test/mango/02_basic_find_test.exs
index e92e57258..ab7c6897e 100644
--- a/test/elixir/test/mango/02_basic_find_test.exs
+++ b/test/elixir/test/mango/02_basic_find_test.exs
@@ -210,7 +210,7 @@ defmodule BasicFindTest do
"company" => %{"$lt" => "M"},
"$or" => [%{"company" => "Dreamia"}, %{"manager" => true}],
},
- sort: [%{"company" => "desc"}, %{"manager" => "desc"}],
+ sort: [%{"company" => "desc"}, %{"manager" => "desc"}]
)
companies_returned = Enum.map(docs, fn doc -> doc["company"] end)
desc_companies = Enum.sort(companies_returned, :desc)
@@ -241,7 +241,7 @@ defmodule BasicFindTest do
"company" => %{"$lt" => "M"},
"$or": [%{"company" => "Dreamia"}, %{"manager" => true}],
},
- sort: [%{"company" => "desc"}],
+ sort: [%{"company" => "desc"}]
)
assert resp.status_code == 400
assert resp.body["error"] == "no_usable_index"
@@ -275,7 +275,7 @@ defmodule BasicFindTest do
end
test "empty subsel match" do
- resp = MangoDatabase.save_docs(@db_name, [%{"user_id" => "eo", "empty_obj"
=> %{}}])
+ _resp = MangoDatabase.save_docs(@db_name, [%{"user_id" => "eo",
"empty_obj" => %{}}])
{:ok, docs} = MangoDatabase.find(@db_name, %{"_id" => %{"$gt" => nil},
"empty_obj" => %{}})
assert length(docs) == 1
assert Enum.at(docs, 0)["user_id"] == "eo"
diff --git a/test/elixir/test/mango/04-key-tests.exs
b/test/elixir/test/mango/04_key_test.exs
similarity index 100%
rename from test/elixir/test/mango/04-key-tests.exs
rename to test/elixir/test/mango/04_key_test.exs
diff --git a/test/elixir/test/mango/25-beginswith-test.exs
b/test/elixir/test/mango/25_beginswith_test.exs
similarity index 100%
rename from test/elixir/test/mango/25-beginswith-test.exs
rename to test/elixir/test/mango/25_beginswith_test.exs
diff --git a/test/elixir/test/reshard_changes_feed.exs
b/test/elixir/test/reshard_changes_feed_test.exs
similarity index 100%
rename from test/elixir/test/reshard_changes_feed.exs
rename to test/elixir/test/reshard_changes_feed_test.exs
diff --git a/test/elixir/test/rewrite_js_test.exs
b/test/elixir/test/rewrite_js_test.exs
index a3adb3e7d..d793e616a 100644
--- a/test/elixir/test/rewrite_js_test.exs
+++ b/test/elixir/test/rewrite_js_test.exs
@@ -209,203 +209,200 @@ defmodule RewriteJSTest do
}
}
- Enum.each(
- ["test_rewrite_suite_db", "test_rewrite_suite_db%2Fwith_slashes"],
- fn db_name ->
- @tag with_random_db: db_name
- test "Test basic js rewrites on #{db_name}", context do
- db_name = context[:db_name]
-
- create_doc(db_name, @ddoc)
-
- docs1 = make_docs(0..9)
- bulk_save(db_name, docs1)
-
- docs2 = [
- %{"a" => 1, "b" => 1, "string" => "doc 1", "type" => "complex"},
- %{"a" => 1, "b" => 2, "string" => "doc 2", "type" => "complex"},
- %{"a" => "test", "b" => %{}, "string" => "doc 3", "type" =>
"complex"},
- %{
- "a" => "test",
- "b" => ["test", "essai"],
- "string" => "doc 4",
- "type" => "complex"
- },
- %{"a" => %{"c" => 1}, "b" => "", "string" => "doc 5", "type" =>
"complex"}
- ]
-
- bulk_save(db_name, docs2)
-
- # Test simple rewriting
- resp = Couch.get("/#{db_name}/_design/test/_rewrite/foo")
- assert resp.body == "This is a base64 encoded text"
- assert resp.headers["Content-Type"] == "text/plain"
-
- resp = Couch.get("/#{db_name}/_design/test/_rewrite/foo2")
- assert resp.body == "This is a base64 encoded text"
- assert resp.headers["Content-Type"] == "text/plain"
-
- # Test POST, hello update world
- resp =
- Couch.post("/#{db_name}", body: %{"word" => "plankton", "name" =>
"Rusty"}).body
-
- assert resp["ok"]
- doc_id = resp["id"]
- assert doc_id
-
- resp = Couch.put("/#{db_name}/_design/test/_rewrite/hello/#{doc_id}")
- assert resp.status_code in [201, 202]
- assert resp.body == "hello doc"
- assert String.match?(resp.headers["Content-Type"], ~r/charset=utf-8/)
-
- assert Couch.get("/#{db_name}/#{doc_id}").body["world"] == "hello"
-
- resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome?name=user")
- assert resp.body == "Welcome user"
-
- resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome/user")
- assert resp.body == "Welcome user"
-
- resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome2")
- assert resp.body == "Welcome user"
-
- resp = Couch.put("/#{db_name}/_design/test/_rewrite/welcome3/test")
- assert resp.status_code in [201, 202]
- assert resp.body == "New World"
- assert String.match?(resp.headers["Content-Type"], ~r/charset=utf-8/)
-
- resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome3/test")
- assert resp.body == "Welcome test"
-
- resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome4/user")
- assert resp.body == "Welcome user"
-
- resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome5/welcome3")
- assert resp.body == "Welcome welcome3"
-
- resp = Couch.get("/#{db_name}/_design/test/_rewrite/basicView")
- assert resp.status_code == 200
- assert resp.body["total_rows"] == 9
-
- resp =
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/complexView")
- assert resp.status_code == 200
- assert String.match?(resp.body, ~r/FirstKey: [1, 2]/)
-
- resp =
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/complexView2")
- assert resp.status_code == 200
- assert String.match?(resp.body, ~r/Value: doc 3/)
-
- resp =
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/complexView3")
- assert resp.status_code == 200
- assert String.match?(resp.body, ~r/Value: doc 4/)
-
- resp =
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/complexView4")
- assert resp.status_code == 200
- assert String.match?(resp.body, ~r/Value: doc 5/)
-
- # COUCHDB-1612 - send body rewriting get to post
- resp =
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/sendBody1")
- assert resp.status_code == 200
- assert String.match?(resp.body, ~r/Value: doc 5 LineNo: 1/)
-
- resp =
Couch.get("/#{db_name}/_design/test/_rewrite/db/_design/test?meta=true")
- assert resp.status_code == 200
- assert resp.body["_id"] == "_design/test"
- assert Map.has_key?(resp.body, "_revs_info")
- end
-
- @tag with_random_db: db_name
- test "early response on #{db_name}", context do
- db_name = context[:db_name]
-
- ddoc = %{
- _id: "_design/response",
- rewrites: """
- function(req){
- status = parseInt(req.query.status);
- return {code: status,
- body: JSON.stringify({"status": status}),
- headers: {'x-foo': 'bar', 'Content-Type':
'application/json'}};
- }
- """
+ for db_name <- ["test_rewrite_suite_db",
"test_rewrite_suite_db%2Fwith_slashes"] do
+ @tag with_random_db: db_name
+ test "basic js rewrites on #{db_name}", context do
+ db_name = context[:db_name]
+
+ create_doc(db_name, @ddoc)
+
+ docs1 = make_docs(0..9)
+ bulk_save(db_name, docs1)
+
+ docs2 = [
+ %{"a" => 1, "b" => 1, "string" => "doc 1", "type" => "complex"},
+ %{"a" => 1, "b" => 2, "string" => "doc 2", "type" => "complex"},
+ %{"a" => "test", "b" => %{}, "string" => "doc 3", "type" => "complex"},
+ %{
+ "a" => "test",
+ "b" => ["test", "essai"],
+ "string" => "doc 4",
+ "type" => "complex"
+ },
+ %{"a" => %{"c" => 1}, "b" => "", "string" => "doc 5", "type" =>
"complex"}
+ ]
+
+ bulk_save(db_name, docs2)
+
+ # Test simple rewriting
+ resp = Couch.get("/#{db_name}/_design/test/_rewrite/foo")
+ assert resp.body == "This is a base64 encoded text"
+ assert resp.headers["Content-Type"] == "text/plain"
+
+ resp = Couch.get("/#{db_name}/_design/test/_rewrite/foo2")
+ assert resp.body == "This is a base64 encoded text"
+ assert resp.headers["Content-Type"] == "text/plain"
+
+ # Test POST, hello update world
+ resp =
+ Couch.post("/#{db_name}", body: %{"word" => "plankton", "name" =>
"Rusty"}).body
+
+ assert resp["ok"]
+ doc_id = resp["id"]
+ assert doc_id
+
+ resp = Couch.put("/#{db_name}/_design/test/_rewrite/hello/#{doc_id}")
+ assert resp.status_code in [201, 202]
+ assert resp.body == "hello doc"
+ assert String.match?(resp.headers["Content-Type"], ~r/charset=utf-8/)
+
+ assert Couch.get("/#{db_name}/#{doc_id}").body["world"] == "hello"
+
+ resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome?name=user")
+ assert resp.body == "Welcome user"
+
+ resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome/user")
+ assert resp.body == "Welcome user"
+
+ resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome2")
+ assert resp.body == "Welcome user"
+
+ resp = Couch.put("/#{db_name}/_design/test/_rewrite/welcome3/test")
+ assert resp.status_code in [201, 202]
+ assert resp.body == "New World"
+ assert String.match?(resp.headers["Content-Type"], ~r/charset=utf-8/)
+
+ resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome3/test")
+ assert resp.body == "Welcome test"
+
+ resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome4/user")
+ assert resp.body == "Welcome user"
+
+ resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome5/welcome3")
+ assert resp.body == "Welcome welcome3"
+
+ resp = Couch.get("/#{db_name}/_design/test/_rewrite/basicView")
+ assert resp.status_code == 200
+ assert resp.body["total_rows"] == 9
+
+ resp =
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/complexView")
+ assert resp.status_code == 200
+ assert String.match?(resp.body, ~r/FirstKey: [1, 2]/)
+
+ resp =
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/complexView2")
+ assert resp.status_code == 200
+ assert String.match?(resp.body, ~r/Value: doc 3/)
+
+ resp =
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/complexView3")
+ assert resp.status_code == 200
+ assert String.match?(resp.body, ~r/Value: doc 4/)
+
+ resp =
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/complexView4")
+ assert resp.status_code == 200
+ assert String.match?(resp.body, ~r/Value: doc 5/)
+
+ # COUCHDB-1612 - send body rewriting get to post
+ resp =
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/sendBody1")
+ assert resp.status_code == 200
+ assert String.match?(resp.body, ~r/Value: doc 5 LineNo: 1/)
+
+ resp =
Couch.get("/#{db_name}/_design/test/_rewrite/db/_design/test?meta=true")
+ assert resp.status_code == 200
+ assert resp.body["_id"] == "_design/test"
+ assert Map.has_key?(resp.body, "_revs_info")
+ end
+
+ @tag with_random_db: db_name
+ test "early response on #{db_name}", context do
+ db_name = context[:db_name]
+
+ ddoc = %{
+ _id: "_design/response",
+ rewrites: """
+ function(req){
+ status = parseInt(req.query.status);
+ return {code: status,
+ body: JSON.stringify({"status": status}),
+ headers: {'x-foo': 'bar', 'Content-Type':
'application/json'}};
}
+ """
+ }
- create_doc(db_name, ddoc)
+ create_doc(db_name, ddoc)
- resp = Couch.get("/#{db_name}/_design/response/_rewrite?status=200")
- assert resp.status_code == 200
- assert resp.headers["x-foo"] == "bar"
- assert resp.body["status"] == 200
+ resp = Couch.get("/#{db_name}/_design/response/_rewrite?status=200")
+ assert resp.status_code == 200
+ assert resp.headers["x-foo"] == "bar"
+ assert resp.body["status"] == 200
- resp = Couch.get("/#{db_name}/_design/response/_rewrite?status=451")
- assert resp.status_code == 451
- assert resp.headers["Content-Type"] == "application/json"
+ resp = Couch.get("/#{db_name}/_design/response/_rewrite?status=451")
+ assert resp.status_code == 451
+ assert resp.headers["Content-Type"] == "application/json"
- resp = Couch.get("/#{db_name}/_design/response/_rewrite?status=500")
- assert resp.status_code == 500
- end
+ resp = Couch.get("/#{db_name}/_design/response/_rewrite?status=500")
+ assert resp.status_code == 500
+ end
- @tag with_random_db: db_name
- test "path relative to server on #{db_name}", context do
- db_name = context[:db_name]
+ @tag with_random_db: db_name
+ test "path relative to server on #{db_name}", context do
+ db_name = context[:db_name]
- ddoc = %{
- _id: "_design/relative",
- rewrites: """
- function(req){
- return '../../../_uuids'
- }
- """
+ ddoc = %{
+ _id: "_design/relative",
+ rewrites: """
+ function(req){
+ return '../../../_uuids'
}
+ """
+ }
- create_doc(db_name, ddoc)
- resp = Couch.get("/#{db_name}/_design/relative/_rewrite/uuids")
- assert resp.status_code == 200
- assert length(resp.body["uuids"]) == 1
- end
-
- @tag with_random_db: db_name
- test "loop on #{db_name}", context do
- db_name = context[:db_name]
-
- ddoc_loop = %{
- _id: "_design/loop",
- rewrites: """
- function(req) {
- return '_rewrite/loop';
- }
- """
+ create_doc(db_name, ddoc)
+ resp = Couch.get("/#{db_name}/_design/relative/_rewrite/uuids")
+ assert resp.status_code == 200
+ assert length(resp.body["uuids"]) == 1
+ end
+
+ @tag with_random_db: db_name
+ test "loop on #{db_name}", context do
+ db_name = context[:db_name]
+
+ ddoc_loop = %{
+ _id: "_design/loop",
+ rewrites: """
+ function(req) {
+ return '_rewrite/loop';
}
+ """
+ }
- create_doc(db_name, ddoc_loop)
- resp = Couch.get("/#{db_name}/_design/loop/_rewrite/loop")
- assert resp.status_code == 400
- end
+ create_doc(db_name, ddoc_loop)
+ resp = Couch.get("/#{db_name}/_design/loop/_rewrite/loop")
+ assert resp.status_code == 400
+ end
- @tag with_random_db: db_name
- test "requests with body preserve the query string rewrite on
#{db_name}",
- context do
- db_name = context[:db_name]
+ @tag with_random_db: db_name
+ test "requests with body preserve the query string rewrite on #{db_name}",
+ context do
+ db_name = context[:db_name]
- ddoc_qs = %{
- _id: "_design/qs",
- rewrites:
- "function (r) { return {path: '../../_changes', query: {'filter':
'_doc_ids'}};};"
- }
+ ddoc_qs = %{
+ _id: "_design/qs",
+ rewrites:
+ "function (r) { return {path: '../../_changes', query: {'filter':
'_doc_ids'}};};"
+ }
- create_doc(db_name, ddoc_qs)
- create_doc(db_name, %{_id: "qs1"})
- create_doc(db_name, %{_id: "qs2"})
+ create_doc(db_name, ddoc_qs)
+ create_doc(db_name, %{_id: "qs1"})
+ create_doc(db_name, %{_id: "qs2"})
- resp =
- Couch.post("/#{db_name}/_design/qs/_rewrite",
- body: %{doc_ids: ["qs2"]}
- )
+ resp =
+ Couch.post("/#{db_name}/_design/qs/_rewrite",
+ body: %{doc_ids: ["qs2"]}
+ )
- assert resp.status_code == 200
- assert length(resp.body["results"]) == 1
- assert Enum.at(resp.body["results"], 0)["id"] == "qs2"
- end
+ assert resp.status_code == 200
+ assert length(resp.body["results"]) == 1
+ assert Enum.at(resp.body["results"], 0)["id"] == "qs2"
end
- )
+ end
end
diff --git a/test/elixir/test/rewrite_test.exs
b/test/elixir/test/rewrite_test.exs
index 34fe3b7f5..4a13803c6 100644
--- a/test/elixir/test/rewrite_test.exs
+++ b/test/elixir/test/rewrite_test.exs
@@ -8,519 +8,522 @@ defmodule RewriteTest do
This is a port of the rewrite.js suite
"""
- Enum.each(
- ["test_rewrite_suite_db", "test_rewrite_suite_db%2Fwith_slashes"],
- fn db_name ->
- @tag with_random_db: db_name
- @tag config: [
- {"httpd", "authentication_handlers",
- "{couch_httpd_auth, special_test_authentication_handler}"},
- {"chttpd", "WWW-Authenticate", "X-Couch-Test-Auth"}
- ]
- test "Test basic rewrites on #{db_name}", context do
- db_name = context[:db_name]
-
- ddoc = ~S"""
- {
- "_id": "_design/test",
- "language": "javascript",
- "_attachments": {
- "foo.txt": {
- "content_type":"text/plain",
- "data": "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ="
+ for db_name <- ["test_rewrite_suite_db",
"test_rewrite_suite_db%2Fwith_slashes"] do
+ @tag with_random_db: db_name
+ @tag config: [
+ {"httpd", "authentication_handlers",
+ "{couch_httpd_auth, special_test_authentication_handler}"},
+ {"chttpd", "WWW-Authenticate", "X-Couch-Test-Auth"}
+ ]
+ test "basic rewrites on #{db_name}", context do
+ db_name = context[:db_name]
+
+ ddoc = ~S"""
+ {
+ "_id": "_design/test",
+ "language": "javascript",
+ "_attachments": {
+ "foo.txt": {
+ "content_type":"text/plain",
+ "data": "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ="
+ }
+ },
+ "rewrites": [
+ {
+ "from": "foo",
+ "to": "foo.txt"
+ },
+ {
+ "from": "foo2",
+ "to": "foo.txt",
+ "method": "GET"
+ },
+ {
+ "from": "hello/:id",
+ "to": "_update/hello/:id",
+ "method": "PUT"
+ },
+ {
+ "from": "/welcome",
+ "to": "_show/welcome"
+ },
+ {
+ "from": "/welcome/:name",
+ "to": "_show/welcome",
+ "query": {
+ "name": ":name"
}
},
- "rewrites": [
- {
- "from": "foo",
- "to": "foo.txt"
- },
- {
- "from": "foo2",
- "to": "foo.txt",
- "method": "GET"
- },
- {
- "from": "hello/:id",
- "to": "_update/hello/:id",
- "method": "PUT"
- },
- {
- "from": "/welcome",
- "to": "_show/welcome"
- },
- {
- "from": "/welcome/:name",
- "to": "_show/welcome",
- "query": {
- "name": ":name"
- }
- },
- {
- "from": "/welcome2",
- "to": "_show/welcome",
- "query": {
- "name": "user"
- }
- },
- {
- "from": "/welcome3/:name",
- "to": "_update/welcome2/:name",
- "method": "PUT"
- },
- {
- "from": "/welcome3/:name",
- "to": "_show/welcome2/:name",
- "method": "GET"
- },
- {
- "from": "/welcome4/*",
- "to" : "_show/welcome3",
- "query": {
- "name": "*"
- }
- },
- {
- "from": "/welcome5/*",
- "to" : "_show/*",
- "query": {
- "name": "*"
- }
- },
- {
- "from": "basicView",
- "to": "_view/basicView"
- },
- {
- "from": "simpleForm/basicView",
- "to": "_list/simpleForm/basicView"
- },
- {
- "from": "simpleForm/basicViewFixed",
- "to": "_list/simpleForm/basicView",
- "query": {
- "startkey": 3,
- "endkey": 8
- }
- },
- {
- "from": "simpleForm/basicViewPath/:start/:end",
- "to": "_list/simpleForm/basicView",
- "query": {
- "startkey": ":start",
- "endkey": ":end"
- },
- "formats": {
- "start": "int",
- "end": "int"
- }
- },
- {
- "from": "simpleForm/complexView",
- "to": "_list/simpleForm/complexView",
- "query": {
- "key": [1, 2]
- }
- },
- {
- "from": "simpleForm/complexView2",
- "to": "_list/simpleForm/complexView",
- "query": {
- "key": ["test", {}]
- }
- },
- {
- "from": "simpleForm/complexView3",
- "to": "_list/simpleForm/complexView",
- "query": {
- "key": ["test", ["test", "essai"]]
- }
- },
- {
- "from": "simpleForm/complexView4",
- "to": "_list/simpleForm/complexView2",
- "query": {
- "key": {"c": 1}
- }
+ {
+ "from": "/welcome2",
+ "to": "_show/welcome",
+ "query": {
+ "name": "user"
+ }
+ },
+ {
+ "from": "/welcome3/:name",
+ "to": "_update/welcome2/:name",
+ "method": "PUT"
+ },
+ {
+ "from": "/welcome3/:name",
+ "to": "_show/welcome2/:name",
+ "method": "GET"
+ },
+ {
+ "from": "/welcome4/*",
+ "to" : "_show/welcome3",
+ "query": {
+ "name": "*"
+ }
+ },
+ {
+ "from": "/welcome5/*",
+ "to" : "_show/*",
+ "query": {
+ "name": "*"
+ }
+ },
+ {
+ "from": "basicView",
+ "to": "_view/basicView"
+ },
+ {
+ "from": "simpleForm/basicView",
+ "to": "_list/simpleForm/basicView"
+ },
+ {
+ "from": "simpleForm/basicViewFixed",
+ "to": "_list/simpleForm/basicView",
+ "query": {
+ "startkey": 3,
+ "endkey": 8
+ }
+ },
+ {
+ "from": "simpleForm/basicViewPath/:start/:end",
+ "to": "_list/simpleForm/basicView",
+ "query": {
+ "startkey": ":start",
+ "endkey": ":end"
},
- {
- "from": "simpleForm/complexView5/:a/:b",
- "to": "_list/simpleForm/complexView3",
- "query": {
- "key": [":a", ":b"]
- }
+ "formats": {
+ "start": "int",
+ "end": "int"
+ }
+ },
+ {
+ "from": "simpleForm/complexView",
+ "to": "_list/simpleForm/complexView",
+ "query": {
+ "key": [1, 2]
+ }
+ },
+ {
+ "from": "simpleForm/complexView2",
+ "to": "_list/simpleForm/complexView",
+ "query": {
+ "key": ["test", {}]
+ }
+ },
+ {
+ "from": "simpleForm/complexView3",
+ "to": "_list/simpleForm/complexView",
+ "query": {
+ "key": ["test", ["test", "essai"]]
+ }
+ },
+ {
+ "from": "simpleForm/complexView4",
+ "to": "_list/simpleForm/complexView2",
+ "query": {
+ "key": {"c": 1}
+ }
+ },
+ {
+ "from": "simpleForm/complexView5/:a/:b",
+ "to": "_list/simpleForm/complexView3",
+ "query": {
+ "key": [":a", ":b"]
+ }
+ },
+ {
+ "from": "simpleForm/complexView6",
+ "to": "_list/simpleForm/complexView3",
+ "query": {
+ "key": [":a", ":b"]
+ }
+ },
+ {
+ "from": "simpleForm/complexView7/:a/:b",
+ "to": "_view/complexView3",
+ "query": {
+ "key": [":a", ":b"],
+ "include_docs": ":doc"
},
- {
- "from": "simpleForm/complexView6",
- "to": "_list/simpleForm/complexView3",
- "query": {
- "key": [":a", ":b"]
+ "format": {
+ "doc": "bool"
+ }
+
+ },
+ {
+ "from": "/",
+ "to": "_view/basicView"
+ },
+ {
+ "from": "/db/*",
+ "to": "../../*"
+ }
+ ],
+ "lists": {
+ "simpleForm": "function(head, req) {
+ log(\"simpleForm\");
+ send(\"<ul>\");
+ var row, row_number = 0, prevKey, firstKey = null;
+ while (row = getRow()) {
+ row_number += 1;
+ if (!firstKey) firstKey = row.key;
+ prevKey = row.key;
+ send(\"\\n<li>Key: \"+row.key
+ +\" Value: \"+row.value
+ +\" LineNo: \"+row_number+\"</li>\");
+ }
+ return \"</ul><p>FirstKey: \"+ firstKey + \" LastKey: \"+
prevKey+\"</p>\";
+ }"
+ },
+ "shows": {
+ "welcome": "(function(doc,req) {
+ return \"Welcome \" + req.query[\"name\"];
+ })",
+ "welcome2": "(function(doc, req) {
+ return \"Welcome \" + doc.name;
+ })",
+ "welcome3": "(function(doc,req) {
+ return \"Welcome \" + req.query[\"name\"];
+ })"
+ },
+ "updates": {
+ "hello" : "(function(doc, req) {
+ if (!doc) {
+ if (req.id) {
+ return [{
+ _id : req.id
+ }, \"New World\"]
}
- },
- {
- "from": "simpleForm/complexView7/:a/:b",
- "to": "_view/complexView3",
- "query": {
- "key": [":a", ":b"],
- "include_docs": ":doc"
- },
- "format": {
- "doc": "bool"
+ return [null, \"Empty World\"];
+ }
+ doc.world = \"hello\";
+ doc.edited_by = req.userCtx;
+ return [doc, \"hello doc\"];
+ })",
+ "welcome2": "(function(doc, req) {
+ if (!doc) {
+ if (req.id) {
+ return [{
+ _id: req.id,
+ name: req.id
+ }, \"New World\"]
}
-
- },
- {
- "from": "/",
- "to": "_view/basicView"
- },
- {
- "from": "/db/*",
- "to": "../../*"
+ return [null, \"Empty World\"];
}
- ],
- "lists": {
- "simpleForm": "function(head, req) {
- log(\"simpleForm\");
- send(\"<ul>\");
- var row, row_number = 0, prevKey, firstKey = null;
- while (row = getRow()) {
- row_number += 1;
- if (!firstKey) firstKey = row.key;
- prevKey = row.key;
- send(\"\\n<li>Key: \"+row.key
- +\" Value: \"+row.value
- +\" LineNo: \"+row_number+\"</li>\");
+ return [doc, \"hello doc\"];
+ })"
+ },
+ "views" : {
+ "basicView" : {
+ "map" : "(function(doc) {
+ if (doc.integer) {
+ emit(doc.integer, doc.string);
}
- return \"</ul><p>FirstKey: \"+ firstKey + \" LastKey: \"+
prevKey+\"</p>\";
- }"
- },
- "shows": {
- "welcome": "(function(doc,req) {
- return \"Welcome \" + req.query[\"name\"];
- })",
- "welcome2": "(function(doc, req) {
- return \"Welcome \" + doc.name;
- })",
- "welcome3": "(function(doc,req) {
- return \"Welcome \" + req.query[\"name\"];
+
})"
},
- "updates": {
- "hello" : "(function(doc, req) {
- if (!doc) {
- if (req.id) {
- return [{
- _id : req.id
- }, \"New World\"]
- }
- return [null, \"Empty World\"];
+ "complexView": {
+ "map": "(function(doc) {
+ if (doc.type == \"complex\") {
+ emit([doc.a, doc.b], doc.string);
}
- doc.world = \"hello\";
- doc.edited_by = req.userCtx;
- return [doc, \"hello doc\"];
- })",
- "welcome2": "(function(doc, req) {
- if (!doc) {
- if (req.id) {
- return [{
- _id: req.id,
- name: req.id
- }, \"New World\"]
- }
- return [null, \"Empty World\"];
+ })"
+ },
+ "complexView2": {
+ "map": "(function(doc) {
+ if (doc.type == \"complex\") {
+ emit(doc.a, doc.string);
}
- return [doc, \"hello doc\"];
})"
},
- "views" : {
- "basicView" : {
- "map" : "(function(doc) {
- if (doc.integer) {
- emit(doc.integer, doc.string);
- }
-
- })"
- },
- "complexView": {
- "map": "(function(doc) {
- if (doc.type == \"complex\") {
- emit([doc.a, doc.b], doc.string);
- }
- })"
- },
- "complexView2": {
- "map": "(function(doc) {
- if (doc.type == \"complex\") {
- emit(doc.a, doc.string);
- }
- })"
- },
- "complexView3": {
- "map": "(function(doc) {
- if (doc.type == \"complex\") {
- emit(doc.b, doc.string);
- }
- })"
- }
+ "complexView3": {
+ "map": "(function(doc) {
+ if (doc.type == \"complex\") {
+ emit(doc.b, doc.string);
+ }
+ })"
}
}
- """
-
- ddoc = String.replace(ddoc, ~r/[\r\n]+/, "")
-
- docs1 = make_docs(0..9)
-
- docs2 = [
- %{"a" => 1, "b" => 1, "string" => "doc 1", "type" => "complex"},
- %{"a" => 1, "b" => 2, "string" => "doc 2", "type" => "complex"},
- %{"a" => "test", "b" => %{}, "string" => "doc 3", "type" =>
"complex"},
- %{
- "a" => "test",
- "b" => ["test", "essai"],
- "string" => "doc 4",
- "type" => "complex"
- },
- %{"a" => %{"c" => 1}, "b" => "", "string" => "doc 5", "type" =>
"complex"}
- ]
-
- assert Couch.put("/#{db_name}/_design/test", body: ddoc).body["ok"]
-
- assert Couch.post(
- "/#{db_name}/_bulk_docs",
- body: %{:docs => docs1},
- query: %{w: 3}
- ).status_code in [201, 202]
-
- assert Couch.post(
- "/#{db_name}/_bulk_docs",
- body: %{:docs => docs2},
- query: %{w: 3}
- ).status_code in [201, 202]
-
- # Test simple rewriting
- resp = Couch.get("/#{db_name}/_design/test/_rewrite/foo")
- assert resp.body == "This is a base64 encoded text"
- assert resp.headers["Content-Type"] == "text/plain"
-
- resp = Couch.get("/#{db_name}/_design/test/_rewrite/foo2")
- assert resp.body == "This is a base64 encoded text"
- assert resp.headers["Content-Type"] == "text/plain"
-
- # Test POST, hello update world
- resp =
- Couch.post("/#{db_name}", body: %{"word" => "plankton", "name" =>
"Rusty"}).body
-
- assert resp["ok"]
- doc_id = resp["id"]
- assert doc_id
-
- resp = Couch.put("/#{db_name}/_design/test/_rewrite/hello/#{doc_id}")
- assert resp.status_code in [201, 202]
- assert resp.body == "hello doc"
- assert String.match?(resp.headers["Content-Type"], ~r/charset=utf-8/)
+ }
+ """
+
+ ddoc = String.replace(ddoc, ~r/[\r\n]+/, "")
+
+ docs1 = make_docs(0..9)
+
+ docs2 = [
+ %{"a" => 1, "b" => 1, "string" => "doc 1", "type" => "complex"},
+ %{"a" => 1, "b" => 2, "string" => "doc 2", "type" => "complex"},
+ %{"a" => "test", "b" => %{}, "string" => "doc 3", "type" => "complex"},
+ %{
+ "a" => "test",
+ "b" => ["test", "essai"],
+ "string" => "doc 4",
+ "type" => "complex"
+ },
+ %{"a" => %{"c" => 1}, "b" => "", "string" => "doc 5", "type" =>
"complex"}
+ ]
+
+ assert Couch.put("/#{db_name}/_design/test", body: ddoc).body["ok"]
+
+ assert Couch.post(
+ "/#{db_name}/_bulk_docs",
+ body: %{:docs => docs1},
+ query: %{w: 3}
+ ).status_code in [201, 202]
+
+ assert Couch.post(
+ "/#{db_name}/_bulk_docs",
+ body: %{:docs => docs2},
+ query: %{w: 3}
+ ).status_code in [201, 202]
+
+ # Test simple rewriting
+ resp = Couch.get("/#{db_name}/_design/test/_rewrite/foo")
+ assert resp.body == "This is a base64 encoded text"
+ assert resp.headers["Content-Type"] == "text/plain"
+
+ resp = Couch.get("/#{db_name}/_design/test/_rewrite/foo2")
+ assert resp.body == "This is a base64 encoded text"
+ assert resp.headers["Content-Type"] == "text/plain"
+
+ # Test POST, hello update world
+ resp =
+ Couch.post("/#{db_name}", body: %{"word" => "plankton", "name" =>
"Rusty"}).body
+
+ assert resp["ok"]
+ doc_id = resp["id"]
+ assert doc_id
+
+ resp = Couch.put("/#{db_name}/_design/test/_rewrite/hello/#{doc_id}")
+ assert resp.status_code in [201, 202]
+ assert resp.body == "hello doc"
+ assert String.match?(resp.headers["Content-Type"], ~r/charset=utf-8/)
+
+ assert Couch.get("/#{db_name}/#{doc_id}").body["world"] == "hello"
+
+ resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome?name=user")
+ assert resp.body == "Welcome user"
+
+ resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome/user")
+ assert resp.body == "Welcome user"
+
+ resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome2")
+ assert resp.body == "Welcome user"
+
+ resp = Couch.put("/#{db_name}/_design/test/_rewrite/welcome3/test")
+ assert resp.status_code in [201, 202]
+ assert resp.body == "New World"
+ assert String.match?(resp.headers["Content-Type"], ~r/charset=utf-8/)
+
+ resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome3/test")
+ assert resp.body == "Welcome test"
- assert Couch.get("/#{db_name}/#{doc_id}").body["world"] == "hello"
+ # TODO: port the two "bugged" tests from rewrite.js
+
+ resp = Couch.get("/#{db_name}/_design/test/_rewrite/basicView")
+ assert resp.status_code == 200
+ assert resp.body["total_rows"] == 9
+
+ resp = Couch.get("/#{db_name}/_design/test/_rewrite")
+ assert resp.status_code == 200
+ assert resp.body["total_rows"] == 9
+
+ resp =
+ Rawresp.get(
+
"/#{db_name}/_design/test/_rewrite/simpleForm/basicView?startkey=3&endkey=8"
+ )
+
+ assert resp.status_code == 200
+ assert not String.match?(resp.body, ~r/Key: 1/)
+ assert String.match?(resp.body, ~r/FirstKey: 3/)
+ assert String.match?(resp.body, ~r/LastKey: 8/)
+
+ resp =
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/basicViewFixed")
+ assert resp.status_code == 200
+ assert not String.match?(resp.body, ~r/Key: 1/)
+ assert String.match?(resp.body, ~r/FirstKey: 3/)
+ assert String.match?(resp.body, ~r/LastKey: 8/)
+
+ resp =
+ Rawresp.get(
+
"/#{db_name}/_design/test/_rewrite/simpleForm/basicViewFixed?startkey=4"
+ )
+
+ assert resp.status_code == 200
+ assert not String.match?(resp.body, ~r/Key: 1/)
+ assert String.match?(resp.body, ~r/FirstKey: 3/)
+ assert String.match?(resp.body, ~r/LastKey: 8/)
+
+ resp =
+
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/basicViewPath/3/8")
+
+ assert resp.status_code == 200
+ assert not String.match?(resp.body, ~r/Key: 1/)
+ assert String.match?(resp.body, ~r/FirstKey: 3/)
+ assert String.match?(resp.body, ~r/LastKey: 8/)
- resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome?name=user")
- assert resp.body == "Welcome user"
+ resp =
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/complexView")
+ assert resp.status_code == 200
+ assert String.match?(resp.body, ~r/FirstKey: [1, 2]/)
- resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome/user")
- assert resp.body == "Welcome user"
+ resp =
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/complexView2")
+ assert resp.status_code == 200
+ assert String.match?(resp.body, ~r/Value: doc 3/)
- resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome2")
- assert resp.body == "Welcome user"
+ resp =
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/complexView3")
+ assert resp.status_code == 200
+ assert String.match?(resp.body, ~r/Value: doc 4/)
- resp = Couch.put("/#{db_name}/_design/test/_rewrite/welcome3/test")
- assert resp.status_code in [201, 202]
- assert resp.body == "New World"
- assert String.match?(resp.headers["Content-Type"], ~r/charset=utf-8/)
+ resp =
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/complexView4")
+ assert resp.status_code == 200
+ assert String.match?(resp.body, ~r/Value: doc 5/)
- resp = Couch.get("/#{db_name}/_design/test/_rewrite/welcome3/test")
- assert resp.body == "Welcome test"
+ resp =
+ Rawresp.get(
+
"/#{db_name}/_design/test/_rewrite/simpleForm/complexView5/test/essai"
+ )
- # TODO: port the two "bugged" tests from rewrite.js
-
- resp = Couch.get("/#{db_name}/_design/test/_rewrite/basicView")
- assert resp.status_code == 200
- assert resp.body["total_rows"] == 9
-
- resp = Couch.get("/#{db_name}/_design/test/_rewrite")
- assert resp.status_code == 200
- assert resp.body["total_rows"] == 9
+ assert resp.status_code == 200
+ assert String.match?(resp.body, ~r/Value: doc 4/)
- resp =
- Rawresp.get(
-
"/#{db_name}/_design/test/_rewrite/simpleForm/basicView?startkey=3&endkey=8"
- )
+ resp =
+ Rawresp.get(
+
"/#{db_name}/_design/test/_rewrite/simpleForm/complexView6?a=test&b=essai"
+ )
- assert resp.status_code == 200
- assert not String.match?(resp.body, ~r/Key: 1/)
- assert String.match?(resp.body, ~r/FirstKey: 3/)
- assert String.match?(resp.body, ~r/LastKey: 8/)
+ assert resp.status_code == 200
+ assert String.match?(resp.body, ~r/Value: doc 4/)
- resp =
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/basicViewFixed")
- assert resp.status_code == 200
- assert not String.match?(resp.body, ~r/Key: 1/)
- assert String.match?(resp.body, ~r/FirstKey: 3/)
- assert String.match?(resp.body, ~r/LastKey: 8/)
+ resp =
+ Rawresp.get(
+
"/#{db_name}/_design/test/_rewrite/simpleForm/complexView7/test/essai?doc=true"
+ )
- resp =
- Rawresp.get(
-
"/#{db_name}/_design/test/_rewrite/simpleForm/basicViewFixed?startkey=4"
- )
+ assert resp.status_code == 200
- assert resp.status_code == 200
- assert not String.match?(resp.body, ~r/Key: 1/)
- assert String.match?(resp.body, ~r/FirstKey: 3/)
- assert String.match?(resp.body, ~r/LastKey: 8/)
+ result =
+ resp.body |> IO.iodata_to_binary() |> :jiffy.decode([:return_maps,
:use_nil])
- resp =
-
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/basicViewPath/3/8")
+ first_row = Enum.at(result["rows"], 0)
+ assert Map.has_key?(first_row, "doc")
- assert resp.status_code == 200
- assert not String.match?(resp.body, ~r/Key: 1/)
- assert String.match?(resp.body, ~r/FirstKey: 3/)
- assert String.match?(resp.body, ~r/LastKey: 8/)
+ # COUCHDB-2031 - path normalization versus qs params
+ resp =
Rawresp.get("/#{db_name}/_design/test/_rewrite/db/_design/test?meta=true")
+ assert resp.status_code == 200
- resp =
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/complexView")
- assert resp.status_code == 200
- assert String.match?(resp.body, ~r/FirstKey: [1, 2]/)
+ result =
+ resp.body |> IO.iodata_to_binary() |> :jiffy.decode([:return_maps,
:use_nil])
- resp =
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/complexView2")
- assert resp.status_code == 200
- assert String.match?(resp.body, ~r/Value: doc 3/)
+ assert result["_id"] == "_design/test"
+ assert Map.has_key?(result, "_revs_info")
- resp =
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/complexView3")
- assert resp.status_code == 200
- assert String.match?(resp.body, ~r/Value: doc 4/)
+ ddoc2 = %{
+ _id: "_design/test2",
+ rewrites: [
+ %{
+ from: "uuids",
+ to: "../../../_uuids"
+ }
+ ]
+ }
- resp =
Rawresp.get("/#{db_name}/_design/test/_rewrite/simpleForm/complexView4")
- assert resp.status_code == 200
- assert String.match?(resp.body, ~r/Value: doc 5/)
+ create_doc(db_name, ddoc2)
+ resp = Couch.get("/#{db_name}/_design/test2/_rewrite/uuids")
+ assert resp.status_code == 500
+ assert resp.body["error"] == "insecure_rewrite_rule"
+ end
- resp =
- Rawresp.get(
-
"/#{db_name}/_design/test/_rewrite/simpleForm/complexView5/test/essai"
- )
+ @tag with_random_db: db_name
+ @tag config: [
+ {"chttpd", "secure_rewrites", "false"}
+ ]
+ test "path relative to server on #{db_name}", context do
+ db_name = context[:db_name]
- assert resp.status_code == 200
- assert String.match?(resp.body, ~r/Value: doc 4/)
+ ddoc = %{
+ _id: "_design/test2",
+ rewrites: [
+ %{
+ from: "uuids",
+ to: "../../../_uuids"
+ }
+ ]
+ }
- resp =
- Rawresp.get(
-
"/#{db_name}/_design/test/_rewrite/simpleForm/complexView6?a=test&b=essai"
- )
+ create_doc(db_name, ddoc)
- assert resp.status_code == 200
- assert String.match?(resp.body, ~r/Value: doc 4/)
+ resp = Couch.get("/#{db_name}/_design/test2/_rewrite/uuids")
+ assert resp.status_code == 200
+ assert length(resp.body["uuids"]) == 1
+ end
- resp =
- Rawresp.get(
-
"/#{db_name}/_design/test/_rewrite/simpleForm/complexView7/test/essai?doc=true"
- )
+ @tag with_random_db: db_name
+ @tag config: [
+ {"chttpd", "rewrite_limit", "2"}
+ ]
+ test "loop detection on #{db_name}", context do
+ db_name = context[:db_name]
- assert resp.status_code == 200
- result = resp.body |> IO.iodata_to_binary() |>
:jiffy.decode([:return_maps, :use_nil])
- first_row = Enum.at(result["rows"], 0)
- assert Map.has_key?(first_row, "doc")
+ ddoc_loop = %{
+ _id: "_design/loop",
+ rewrites: [%{from: "loop", to: "_rewrite/loop"}]
+ }
- # COUCHDB-2031 - path normalization versus qs params
- resp =
Rawresp.get("/#{db_name}/_design/test/_rewrite/db/_design/test?meta=true")
- assert resp.status_code == 200
- result = resp.body |> IO.iodata_to_binary() |>
:jiffy.decode([:return_maps, :use_nil])
- assert result["_id"] == "_design/test"
- assert Map.has_key?(result, "_revs_info")
-
- ddoc2 = %{
- _id: "_design/test2",
- rewrites: [
- %{
- from: "uuids",
- to: "../../../_uuids"
- }
- ]
- }
+ create_doc(db_name, ddoc_loop)
- create_doc(db_name, ddoc2)
- resp = Couch.get("/#{db_name}/_design/test2/_rewrite/uuids")
- assert resp.status_code == 500
- assert resp.body["error"] == "insecure_rewrite_rule"
- end
+ resp = Couch.get("/#{db_name}/_design/loop/_rewrite/loop")
+ assert resp.status_code == 400
+ end
- @tag with_random_db: db_name
- @tag config: [
- {"chttpd", "secure_rewrites", "false"}
- ]
- test "path relative to server on #{db_name}", context do
- db_name = context[:db_name]
-
- ddoc = %{
- _id: "_design/test2",
- rewrites: [
- %{
- from: "uuids",
- to: "../../../_uuids"
- }
- ]
- }
+ @tag with_random_db: db_name
+ @tag config: [
+ {"chttpd", "rewrite_limit", "2"},
+ {"chttpd", "secure_rewrites", "false"}
+ ]
+ test "serial execution is not spuriously counted as loop on #{db_name}",
context do
+ db_name = context[:db_name]
+
+ ddoc = %{
+ _id: "_design/test",
+ language: "javascript",
+ _attachments: %{
+ "foo.txt": %{
+ content_type: "text/plain",
+ data: "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ="
+ }
+ },
+ rewrites: [
+ %{
+ from: "foo",
+ to: "foo.txt"
+ }
+ ]
+ }
- create_doc(db_name, ddoc)
+ create_doc(db_name, ddoc)
- resp = Couch.get("/#{db_name}/_design/test2/_rewrite/uuids")
+ for _i <- 0..4 do
+ resp = Couch.get("/#{db_name}/_design/test/_rewrite/foo")
assert resp.status_code == 200
- assert length(resp.body["uuids"]) == 1
- end
-
- @tag with_random_db: db_name
- @tag config: [
- {"chttpd", "rewrite_limit", "2"}
- ]
- test "loop detection on #{db_name}", context do
- db_name = context[:db_name]
-
- ddoc_loop = %{
- _id: "_design/loop",
- rewrites: [%{from: "loop", to: "_rewrite/loop"}]
- }
-
- create_doc(db_name, ddoc_loop)
-
- resp = Couch.get("/#{db_name}/_design/loop/_rewrite/loop")
- assert resp.status_code == 400
- end
-
- @tag with_random_db: db_name
- @tag config: [
- {"chttpd", "rewrite_limit", "2"},
- {"chttpd", "secure_rewrites", "false"}
- ]
- test "serial execution is not spuriously counted as loop on #{db_name}",
context do
- db_name = context[:db_name]
-
- ddoc = %{
- _id: "_design/test",
- language: "javascript",
- _attachments: %{
- "foo.txt": %{
- content_type: "text/plain",
- data: "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ="
- }
- },
- rewrites: [
- %{
- from: "foo",
- to: "foo.txt"
- }
- ]
- }
-
- create_doc(db_name, ddoc)
-
- for _i <- 0..4 do
- resp = Couch.get("/#{db_name}/_design/test/_rewrite/foo")
- assert resp.status_code == 200
- end
end
end
- )
+ end
end
diff --git a/test/elixir/test/support/friend_docs.ex
b/test/elixir/test/support/friend_docs.ex
index 289bc999d..0e36af806 100644
--- a/test/elixir/test/support/friend_docs.ex
+++ b/test/elixir/test/support/friend_docs.ex
@@ -276,7 +276,7 @@ defmodule FriendDocs do
:ok
end
- defp add_view_indexes(db) do
+ defp add_view_indexes(_db) do
# TODO: this function is not defined in the Python version of this module?
end
diff --git a/test/elixir/test/support/limit_docs.ex
b/test/elixir/test/support/limit_docs.ex
index 5a474f2dd..4ae9a4c3d 100644
--- a/test/elixir/test/support/limit_docs.ex
+++ b/test/elixir/test/support/limit_docs.ex
@@ -102,7 +102,7 @@ defmodule LimitDocs do
:ok
end
- defp add_view_indexes(db) do
+ defp add_view_indexes(_db) do
# TODO: this function is not defined in the Python version of this module?
end
diff --git a/test/elixir/test/support/user_docs.ex
b/test/elixir/test/support/user_docs.ex
index eb015cc64..52dbca4ae 100644
--- a/test/elixir/test/support/user_docs.ex
+++ b/test/elixir/test/support/user_docs.ex
@@ -217,7 +217,7 @@ defmodule UserDocs do
"twitter" => nil,
"favorites" => ["Lisp", "Erlang", "Python"],
"exists_array" => ["should", "exist", "array1"],
- "complex_field_value" => '+-()%{}[]^~&&*||"\\/? =>!',
+ "complex_field_value" => "+-()%{}[]^~&&*||\"\\/? =>!",
"ordered" => true,
},
%{