You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2020/01/18 00:08:39 UTC

[couchdb] branch port-etags-tests-to-elixir updated (0b623b0 -> fa82bad)

This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a change to branch port-etags-tests-to-elixir
in repository https://gitbox.apache.org/repos/asf/couchdb.git.


 discard 0b623b0  Port etags tests to elixir
     new fa82bad  Port etags tests to elixir

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (0b623b0)
            \
             N -- N -- N   refs/heads/port-etags-tests-to-elixir (fa82bad)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 test/javascript/tests/etags_head.js | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)


[couchdb] 01/01: Port etags tests to elixir

Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch port-etags-tests-to-elixir
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit fa82bad9ef09565dc310081301e5c7981f8d4267
Author: Juanjo Rodriguez <jj...@gmail.com>
AuthorDate: Sat Jan 4 22:45:42 2020 +0100

    Port etags tests to elixir
    
    Fixes #2464
---
 test/elixir/README.md                |   4 +-
 test/elixir/lib/couch.ex             |  22 +++--
 test/elixir/test/etags_head_test.exs | 151 +++++++++++++++++++++++++++++++++++
 test/javascript/tests/etags_head.js  |   2 +
 4 files changed, 170 insertions(+), 9 deletions(-)

diff --git a/test/elixir/README.md b/test/elixir/README.md
index ef95e5f..90b2fd6 100644
--- a/test/elixir/README.md
+++ b/test/elixir/README.md
@@ -46,8 +46,8 @@ X means done, - means partially
   - [ ] Port design_options.js
   - [ ] Port design_paths.js
   - [X] Port erlang_views.js
-  - [ ] Port etags_head.js
-  - [ ] Port etags_views.js
+  - [X] Port etags_head.js
+  - [ ] ~~Port etags_views.js~~ (skipped in js test suite)
   - [ ] Port form_submit.js
   - [ ] Port http.js
   - [X] Port invalid_docids.js
diff --git a/test/elixir/lib/couch.ex b/test/elixir/lib/couch.ex
index 6a63dff..3aef07f 100644
--- a/test/elixir/lib/couch.ex
+++ b/test/elixir/lib/couch.ex
@@ -97,9 +97,9 @@ defmodule Couch do
 
   def process_options(options) do
     options
-      |> set_auth_options()
-      |> set_inactivity_timeout()
-      |> set_request_timeout()
+     |> set_auth_options()
+     |> set_inactivity_timeout()
+     |> set_request_timeout()
   end
 
   def process_request_body(body) do
@@ -110,6 +110,10 @@ defmodule Couch do
     end
   end
 
+  def process_response_body(_headers, body) when body == [] do
+    ""
+  end
+
   def process_response_body(headers, body) do
     content_type = headers[:"Content-Type"]
 
@@ -137,9 +141,14 @@ defmodule Couch do
   end
 
   def set_inactivity_timeout(options) do
-    Keyword.update(options, :ibrowse, [{:inactivity_timeout, @inactivity_timeout}], fn(ibrowse) ->
-      Keyword.put_new(ibrowse, :inactivity_timeout, @inactivity_timeout)
-    end)
+    Keyword.update(
+      options,
+      :ibrowse,
+      [{:inactivity_timeout, @inactivity_timeout}],
+      fn ibrowse ->
+        Keyword.put_new(ibrowse, :inactivity_timeout, @inactivity_timeout)
+      end
+    )
   end
 
   def set_request_timeout(options) do
@@ -165,5 +174,4 @@ defmodule Couch do
       %Couch.Session{error: resp.body["error"]}
     end
   end
-
 end
diff --git a/test/elixir/test/etags_head_test.exs b/test/elixir/test/etags_head_test.exs
new file mode 100644
index 0000000..9b9ff8b
--- /dev/null
+++ b/test/elixir/test/etags_head_test.exs
@@ -0,0 +1,151 @@
+defmodule EtagsHeadTest do
+  use CouchTestCase
+
+  @moduletag :etags
+
+  @tag :with_db
+  test "etag header on creation", context do
+    db_name = context[:db_name]
+
+    resp =
+      Couch.put("/#{db_name}/1",
+        headers: ["Content-Type": "application/json"],
+        body: %{}
+      )
+
+    assert resp.status_code == 201
+    assert Map.has_key?(resp.headers.hdrs, "etag")
+  end
+
+  @tag :with_db
+  test "etag header on retrieval", context do
+    db_name = context[:db_name]
+
+    resp =
+      Couch.put("/#{db_name}/1",
+        headers: ["Content-Type": "application/json"],
+        body: %{}
+      )
+
+    etag = resp.headers.hdrs["etag"]
+
+    # get the doc and verify the headers match
+    resp = Couch.get("/#{db_name}/1")
+    assert etag == resp.headers.hdrs["etag"]
+
+    # 'head' the doc and verify the headers match
+    resp =
+      Couch.head("/#{db_name}/1",
+        headers: ["if-none-match": "s"]
+      )
+
+    assert etag == resp.headers.hdrs["etag"]
+  end
+
+  @tag :with_db
+  test "etag header on head", context do
+    db_name = context[:db_name]
+
+    resp =
+      Couch.put("/#{db_name}/1",
+        headers: ["Content-Type": "application/json"],
+        body: %{}
+      )
+
+    etag = resp.headers.hdrs["etag"]
+
+    # 'head' the doc and verify the headers match
+    resp =
+      Couch.head("/#{db_name}/1",
+        headers: ["if-none-match": "s"]
+      )
+
+    assert etag == resp.headers.hdrs["etag"]
+  end
+
+  @tag :with_db
+  test "etags head", context do
+    db_name = context[:db_name]
+
+    resp =
+      Couch.put("/#{db_name}/1",
+        headers: ["Content-Type": "application/json"],
+        body: %{}
+      )
+
+    assert resp.status_code == 201
+    assert Map.has_key?(resp.headers.hdrs, "etag")
+
+    etag = resp.headers.hdrs["etag"]
+
+    # get the doc and verify the headers match
+    resp = Couch.get("/#{db_name}/1")
+    assert etag == resp.headers.hdrs["etag"]
+
+    # 'head' the doc and verify the headers match
+    resp =
+      Couch.head("/#{db_name}/1",
+        headers: ["if-none-match": "s"]
+      )
+
+    assert etag == resp.headers.hdrs["etag"]
+
+    # replace a doc
+    resp =
+      Couch.put("/#{db_name}/1",
+        headers: ["if-match": etag],
+        body: %{}
+      )
+
+    assert resp.status_code == 201
+
+    # extract the new ETag value
+    previous_etag = etag
+    etag = resp.headers.hdrs["etag"]
+
+    # fail to replace a doc
+    resp =
+      Couch.put("/#{db_name}/1",
+        body: %{}
+      )
+
+    assert resp.status_code == 409
+
+    # verify get w/Etag
+    resp =
+      Couch.get("/#{db_name}/1",
+        headers: ["if-none-match": previous_etag]
+      )
+
+    assert resp.status_code == 200
+
+    resp =
+      Couch.get("/#{db_name}/1",
+        headers: ["if-none-match": etag]
+      )
+
+    assert resp.status_code == 304
+
+    resp =
+      Couch.get("/#{db_name}/1",
+        headers: ["if-none-match": "W/#{etag}"]
+      )
+
+    assert resp.status_code == 304
+
+    # fail to delete a doc
+    resp =
+      Couch.delete("/#{db_name}/1",
+        headers: ["if-match": previous_etag]
+      )
+
+    assert resp.status_code == 409
+
+    resp =
+      Couch.delete("/#{db_name}/1",
+        headers: ["if-match": etag]
+      )
+
+    assert resp.status_code == 200
+  end
+end
diff --git a/test/javascript/tests/etags_head.js b/test/javascript/tests/etags_head.js
index 9faca4a..6784790 100644
--- a/test/javascript/tests/etags_head.js
+++ b/test/javascript/tests/etags_head.js
@@ -10,7 +10,9 @@
 // License for the specific language governing permissions and limitations under
 // the License.
 
+couchTests.elixir = true;
 couchTests.etags_head = function(debug) {
+  return console.log('done in test/elixir/test/etags_head_test.exs');
   var db_name = get_random_db_name();
   var db = new CouchDB(db_name, {"X-Couch-Full-Commit":"false"});
   db.createDb();