You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ga...@apache.org on 2019/04/09 12:26:00 UTC
[couchdb] branch master updated: Port copy doc tests into elixir
test suite (#2000)
This is an automated email from the ASF dual-hosted git repository.
garren pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb.git
The following commit(s) were added to refs/heads/master by this push:
new 52189ee Port copy doc tests into elixir test suite (#2000)
52189ee is described below
commit 52189ee31da91a0c06c7840ba5398e64cb31d1c3
Author: Juanjo Rodriguez <jj...@gmail.com>
AuthorDate: Tue Apr 9 14:25:55 2019 +0200
Port copy doc tests into elixir test suite (#2000)
---
test/elixir/README.md | 2 +-
test/elixir/test/copy_doc_test.exs | 71 ++++++++++++++++++++++++++++++++++++++
2 files changed, 72 insertions(+), 1 deletion(-)
diff --git a/test/elixir/README.md b/test/elixir/README.md
index 8735e1e..a59b4df 100644
--- a/test/elixir/README.md
+++ b/test/elixir/README.md
@@ -41,7 +41,7 @@ X means done, - means partially
- [X] Port config.js
- [X] Port conflicts.js
- [ ] Port cookie_auth.js
- - [ ] Port copy_doc.js
+ - [X] Port copy_doc.js
- [X] Port delayed_commits.js
- [ ] Port design_docs.js
- [ ] Port design_options.js
diff --git a/test/elixir/test/copy_doc_test.exs b/test/elixir/test/copy_doc_test.exs
new file mode 100644
index 0000000..5db8549
--- /dev/null
+++ b/test/elixir/test/copy_doc_test.exs
@@ -0,0 +1,71 @@
+defmodule CopyDocTest do
+ use CouchTestCase
+
+ @moduletag :copy_doc
+
+ @moduledoc """
+ Test CouchDB Copy Doc
+ This is a port of the copy_doc.js suite
+ """
+ @tag :with_db
+ test "Copy doc tests", context do
+ db_name = context[:db_name]
+ create_doc(db_name, %{_id: "doc_to_be_copied", v: 1})
+
+ resp =
+ Couch.request(
+ :copy,
+ "/#{db_name}/doc_to_be_copied",
+ headers: [Destination: "doc_that_was_copied"]
+ )
+
+ assert resp.body["ok"]
+ assert resp.status_code == 201
+
+ assert Couch.get("/#{db_name}/doc_that_was_copied").body["v"] == 1
+
+ create_doc(db_name, %{_id: "doc_to_be_copied2", v: 1})
+ {_, resp} = create_doc(db_name, %{_id: "doc_to_be_overwritten", v: 2})
+ rev = resp.body["rev"]
+
+ resp =
+ Couch.request(
+ :copy,
+ "/#{db_name}/doc_to_be_copied2",
+ headers: [Destination: "doc_to_be_overwritten"]
+ )
+
+ assert resp.status_code == 409
+
+ resp =
+ Couch.request(
+ :copy,
+ "/#{db_name}/doc_to_be_copied2"
+ )
+
+ assert resp.status_code == 400
+ assert resp.body["reason"] == "Destination header is mandatory for COPY."
+
+ resp =
+ Couch.request(
+ :copy,
+ "/#{db_name}/doc_to_be_copied2",
+ headers: [Destination: "http://localhost:5984/#{db_name}/doc_to_be_written"]
+ )
+
+ assert resp.status_code == 400
+ assert resp.body["reason"] == "Destination URL must be relative."
+
+ resp =
+ Couch.request(
+ :copy,
+ "/#{db_name}/doc_to_be_copied2",
+ headers: [Destination: "doc_to_be_overwritten?rev=#{rev}"]
+ )
+
+ assert resp.status_code == 201
+ resp = Couch.get("/#{db_name}/doc_to_be_overwritten")
+ assert resp.body["_rev"] != rev
+ assert resp.body["v"] == 1
+ end
+end