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/02/22 02:11:59 UTC

[couchdb] branch prototype/fdb-layer updated (d0ab91e -> 8c75367)

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

vatamane pushed a change to branch prototype/fdb-layer
in repository https://gitbox.apache.org/repos/asf/couchdb.git.


    from d0ab91e  Add 410 status code to stats_descriptions
     new ded6d64  Revert "Support setting base_url in Couch test helper"
     new 8c75367  Support setting base_url in Couch test helper (take 2)

The 2 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/elixir/lib/couch.ex | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)


[couchdb] 01/02: Revert "Support setting base_url in Couch test helper"

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

vatamane pushed a commit to branch prototype/fdb-layer
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit ded6d64781fa7e8b6adfd1bf5aa548503ba3606f
Author: ILYA Khlopotov <ii...@apache.org>
AuthorDate: Fri Feb 21 07:35:02 2020 -0800

    Revert "Support setting base_url in Couch test helper"
    
    This reverts commit 8650a4e0bb127165affe8972989f134d0e1f6554.
---
 test/elixir/lib/couch.ex | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/test/elixir/lib/couch.ex b/test/elixir/lib/couch.ex
index 3fa5001..8f47ad8 100644
--- a/test/elixir/lib/couch.ex
+++ b/test/elixir/lib/couch.ex
@@ -4,7 +4,7 @@ defmodule Couch.Session do
   """
 
   @enforce_keys [:cookie]
-  defstruct [:cookie, :base_url]
+  defstruct [:cookie]
 
   def new(cookie) do
     %Couch.Session{cookie: cookie}
@@ -34,7 +34,6 @@ defmodule Couch.Session do
 
   def go(%Couch.Session{} = sess, method, url, opts) do
     opts = Keyword.merge(opts, cookie: sess.cookie)
-    opts = Keyword.merge(opts, base_url: sess.base_url)
     Couch.request(method, url, opts)
   end
 
@@ -55,13 +54,8 @@ defmodule Couch do
     url
   end
 
-  def process_url(url, options) do
-    base_url = case Keyword.get(options, :base_url) do
-      nil ->
-        System.get_env("EX_COUCH_URL") || "http://127.0.0.1:15984"
-      base_url ->
-        base_url
-    end
+  def process_url(url) do
+    base_url = System.get_env("EX_COUCH_URL") || "http://127.0.0.1:15984"
     base_url <> url
   end
 
@@ -120,16 +114,15 @@ defmodule Couch do
 
   def login(userinfo) do
     [user, pass] = String.split(userinfo, ":", parts: 2)
-    login(nil, user, pass)
+    login(user, pass)
   end
 
-  def login(base_url, user, pass) do
-    resp = Couch.post("/_session",
-      body: %{:username => user, :password => pass}, base_url: base_url)
+  def login(user, pass) do
+    resp = Couch.post("/_session", body: %{:username => user, :password => pass})
     true = resp.body["ok"]
     cookie = resp.headers[:"set-cookie"]
     [token | _] = String.split(cookie, ";")
-    %Couch.Session{cookie: token, base_url: base_url}
+    %Couch.Session{cookie: token}
   end
 
 end


[couchdb] 02/02: Support setting base_url in Couch test helper (take 2)

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

vatamane pushed a commit to branch prototype/fdb-layer
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 8c75367cdfec1dca62d2dd1ee82f908fdb7b25f0
Author: ILYA Khlopotov <ii...@apache.org>
AuthorDate: Fri Feb 21 09:25:49 2020 -0800

    Support setting base_url in Couch test helper (take 2)
    
    The reason why previous attempt failed is because it overrode [important logic in
    `process_url/2`](https://github.com/myfreeweb/httpotion/blob/v3.1.2/lib/httpotion.ex#L34:L35):
    
    ```
    def process_url(url, options) do
      process_url(url)
        |> prepend_protocol
        |> append_query_string(options)
      end
    ```
    
    This PR fixes the problem by adding the `prepend_protocol`
    and `append_query_string`. It also refactor the way base_url
    is passed around.
---
 test/elixir/lib/couch.ex | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/test/elixir/lib/couch.ex b/test/elixir/lib/couch.ex
index 8f47ad8..94958ea 100644
--- a/test/elixir/lib/couch.ex
+++ b/test/elixir/lib/couch.ex
@@ -4,7 +4,7 @@ defmodule Couch.Session do
   """
 
   @enforce_keys [:cookie]
-  defstruct [:cookie]
+  defstruct [:cookie, :base_url]
 
   def new(cookie) do
     %Couch.Session{cookie: cookie}
@@ -33,12 +33,12 @@ defmodule Couch.Session do
   # if the need arises.
 
   def go(%Couch.Session{} = sess, method, url, opts) do
-    opts = Keyword.merge(opts, cookie: sess.cookie)
+    opts = Keyword.merge(opts, cookie: sess.cookie, base_url: sess.base_url)
     Couch.request(method, url, opts)
   end
 
   def go!(%Couch.Session{} = sess, method, url, opts) do
-    opts = Keyword.merge(opts, cookie: sess.cookie)
+    opts = Keyword.merge(opts, cookie: sess.cookie, base_url: sess.base_url)
     Couch.request!(method, url, opts)
   end
 end
@@ -54,9 +54,10 @@ defmodule Couch do
     url
   end
 
-  def process_url(url) do
-    base_url = System.get_env("EX_COUCH_URL") || "http://127.0.0.1:15984"
-    base_url <> url
+  def process_url(url, options) do
+    Keyword.get(options, :base_url) <> url
+      |> prepend_protocol
+      |> append_query_string(options)
   end
 
   def process_request_headers(headers, _body, options) do
@@ -79,6 +80,8 @@ defmodule Couch do
   end
 
   def process_options(options) do
+    base_url = System.get_env("EX_COUCH_URL") || "http://127.0.0.1:15984"
+    options = Keyword.put_new(options, :base_url, base_url)
     if Keyword.get(options, :cookie) == nil do
       headers = Keyword.get(options, :headers, [])
 
@@ -118,11 +121,20 @@ defmodule Couch do
   end
 
   def login(user, pass) do
-    resp = Couch.post("/_session", body: %{:username => user, :password => pass})
+    base_url = System.get_env("EX_COUCH_URL") || "http://127.0.0.1:15984"
+    login(base_url, user, pass)
+  end
+
+  def login(base_url, user, pass) do
+    resp = Couch.post(
+      "/_session",
+      body: %{:username => user, :password => pass},
+      base_url: base_url
+    )
     true = resp.body["ok"]
     cookie = resp.headers[:"set-cookie"]
     [token | _] = String.split(cookie, ";")
-    %Couch.Session{cookie: token}
+    %Couch.Session{cookie: token, base_url: base_url}
   end
 
 end