You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2017/12/07 18:07:17 UTC
[couchdb] branch elixir-suite-davisp updated (5c5b60b -> 86708b5)
This is an automated email from the ASF dual-hosted git repository.
davisp pushed a change to branch elixir-suite-davisp
in repository https://gitbox.apache.org/repos/asf/couchdb.git.
from 5c5b60b Port uuids.js to Elixir
new 4898c08 Remove module attribute
new 44516be Add simple Makefile for muscle memory
new 7e10c70 Simple .gitignore for sanity
new b52f778 Ignore erln8.config
new 1e0cb25 DRY constant definition
new 67f6fae Update the context in place for setup
new 7b8e6c1 Embrace the Elixir
new 86708b5 Port view_collation.js to view_collation_test.exs
The 8 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:
.gitignore | 1 +
elixir_suite/.gitignore | 2 +
elixir_suite/Makefile | 2 +
elixir_suite/test/test_helper.exs | 43 +++++-----
elixir_suite/test/uuids_test.exs | 18 ++--
elixir_suite/test/view_collation_test.exs | 133 ++++++++++++++++++++++++++++++
6 files changed, 168 insertions(+), 31 deletions(-)
create mode 100644 elixir_suite/.gitignore
create mode 100644 elixir_suite/Makefile
create mode 100644 elixir_suite/test/view_collation_test.exs
--
To stop receiving notification emails like this one, please contact
['"commits@couchdb.apache.org" <co...@couchdb.apache.org>'].
[couchdb] 05/08: DRY constant definition
Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
davisp pushed a commit to branch elixir-suite-davisp
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 1e0cb25b0d708249bc266728d486f6b3235db19b
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Thu Dec 7 10:40:40 2017 -0600
DRY constant definition
---
elixir_suite/test/uuids_test.exs | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/elixir_suite/test/uuids_test.exs b/elixir_suite/test/uuids_test.exs
index 8a9d7f4..563f73b 100644
--- a/elixir_suite/test/uuids_test.exs
+++ b/elixir_suite/test/uuids_test.exs
@@ -79,9 +79,10 @@ defmodule UUIDsTest do
assert u1 < u2
end
+ @utc_id_suffix "frog"
@tag config: [
{"uuids", "algorithm", "utc_id"},
- {"uuids", "utc_id_suffix", "frog"}
+ {"uuids", "utc_id_suffix", @utc_id_suffix}
]
test "utc_id uuids are correct" do
resp = Couch.get("/_uuids", query: %{:count => 10})
@@ -89,8 +90,8 @@ defmodule UUIDsTest do
[uuid | rest_uuids] = resp.body["uuids"]
Enum.reduce(rest_uuids, uuid, fn curr, acc ->
- assert String.length(curr) == 14 + String.length("frog")
- assert String.slice(curr, 14..-1) == "frog"
+ assert String.length(curr) == 14 + String.length(@utc_id_suffix)
+ assert String.slice(curr, 14..-1) == @utc_id_suffix
assert curr > acc
curr
end)
--
To stop receiving notification emails like this one, please contact
"commits@couchdb.apache.org" <co...@couchdb.apache.org>.
[couchdb] 04/08: Ignore erln8.config
Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
davisp pushed a commit to branch elixir-suite-davisp
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit b52f7787ad49668a50660fbbc48bfe69fa3ddaaa
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Thu Dec 7 10:39:35 2017 -0600
Ignore erln8.config
---
.gitignore | 1 +
1 file changed, 1 insertion(+)
diff --git a/.gitignore b/.gitignore
index 3e22192..bef8c44 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,6 +16,7 @@ dev/lib/
dev/logs/
ebin/
erl_crash.dump
+erln8.config
install.mk
rel/*.config
rel/couchdb
--
To stop receiving notification emails like this one, please contact
"commits@couchdb.apache.org" <co...@couchdb.apache.org>.
[couchdb] 06/08: Update the context in place for setup
Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
davisp pushed a commit to branch elixir-suite-davisp
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 67f6faef462e1b1327596dc2228c28c3deeaba0c
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Thu Dec 7 11:38:38 2017 -0600
Update the context in place for setup
Turns out that with multiple setup functions the same context is piped
through each definition. Thus we'll always want to update in place
rather than creating empty contexts which possibly removes settings made
in previous setup or setup_all invocations.
---
elixir_suite/test/test_helper.exs | 43 ++++++++++++++++++++++-----------------
1 file changed, 24 insertions(+), 19 deletions(-)
diff --git a/elixir_suite/test/test_helper.exs b/elixir_suite/test/test_helper.exs
index ecd88e5..cef7d13 100644
--- a/elixir_suite/test/test_helper.exs
+++ b/elixir_suite/test/test_helper.exs
@@ -15,31 +15,36 @@ defmodule CouchTestCase do
use ExUnit.Case
setup context do
- {:ok, db_context} = set_db_context(context)
- {:ok, cfg_context} = set_config_context(context)
- {:ok, db_context ++ cfg_context}
+ setup_funs = [
+ &set_db_context/1,
+ &set_config_context/1
+ ]
+ context = Enum.reduce(setup_funs, context, fn setup_fun, acc ->
+ setup_fun.(acc)
+ end)
+ {:ok, context}
end
def set_db_context(context) do
- db_name = if context[:with_db] != nil or context[:with_db_name] != nil do
- if context[:with_db] != nil and context[:with_db] != true do
- context[:with_db]
- else
- case context[:with_db_name] do
- nil -> random_db_name()
- true -> random_db_name()
- name -> name
- end
- end
+ context = case context do
+ %{:with_db_name => true} ->
+ Map.put(context, :db_name, random_db_name())
+ %{:with_db_name => db_name} when is_binary(db_name) ->
+ Map.put(context, :db_name, db_name)
+ %{:with_db => true} ->
+ Map.put(context, :db_name, random_db_name())
+ %{:with_db => db_name} when is_binary(db_name) ->
+ Map.put(context, :db_name, db_name)
+ _ ->
+ context
end
- if context[:with_db] != nil do
- {:ok, _} = create_db(db_name)
-
- on_exit(fn -> delete_db(db_name) end)
+ if Map.has_key? context, :with_db do
+ {:ok, _} = create_db(context[:db_name])
+ on_exit(fn -> delete_db(context[:db_name]) end)
end
- {:ok, db_name: db_name}
+ context
end
def set_config_context(context) do
@@ -48,7 +53,7 @@ defmodule CouchTestCase do
set_config(cfg)
end)
end
- {:ok, []}
+ context
end
def random_db_name do
--
To stop receiving notification emails like this one, please contact
"commits@couchdb.apache.org" <co...@couchdb.apache.org>.
[couchdb] 07/08: Embrace the Elixir
Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
davisp pushed a commit to branch elixir-suite-davisp
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 7b8e6c12d5f6da2bd787b84700504a3a82431b56
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Thu Dec 7 11:39:43 2017 -0600
Embrace the Elixir
Turns out this idiom has a builtin reduce variant.
---
elixir_suite/test/uuids_test.exs | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/elixir_suite/test/uuids_test.exs b/elixir_suite/test/uuids_test.exs
index 563f73b..3eda458 100644
--- a/elixir_suite/test/uuids_test.exs
+++ b/elixir_suite/test/uuids_test.exs
@@ -50,10 +50,7 @@ defmodule UUIDsTest do
test "sequential uuids are sequential" do
resp = Couch.get("/_uuids", query: %{:count => 1000})
assert resp.status_code == 200
- [uuid | rest_uuids] = resp.body["uuids"]
-
- assert String.length(uuid) == 32
- Enum.reduce(rest_uuids, uuid, fn curr, acc ->
+ Enum.reduce(resp.body["uuids"], fn curr, acc ->
assert String.length(curr) == 32
assert acc < curr
curr
@@ -87,9 +84,7 @@ defmodule UUIDsTest do
test "utc_id uuids are correct" do
resp = Couch.get("/_uuids", query: %{:count => 10})
assert resp.status_code == 200
- [uuid | rest_uuids] = resp.body["uuids"]
-
- Enum.reduce(rest_uuids, uuid, fn curr, acc ->
+ Enum.reduce(resp.body["uuids"], fn curr, acc ->
assert String.length(curr) == 14 + String.length(@utc_id_suffix)
assert String.slice(curr, 14..-1) == @utc_id_suffix
assert curr > acc
--
To stop receiving notification emails like this one, please contact
"commits@couchdb.apache.org" <co...@couchdb.apache.org>.
[couchdb] 02/08: Add simple Makefile for muscle memory
Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
davisp pushed a commit to branch elixir-suite-davisp
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 44516be84d6daa6d0a7fba7354ebe2cbabd1404c
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Thu Dec 7 10:38:40 2017 -0600
Add simple Makefile for muscle memory
---
elixir_suite/Makefile | 2 ++
1 file changed, 2 insertions(+)
diff --git a/elixir_suite/Makefile b/elixir_suite/Makefile
new file mode 100644
index 0000000..bfcf017
--- /dev/null
+++ b/elixir_suite/Makefile
@@ -0,0 +1,2 @@
+all:
+ mix test --trace
--
To stop receiving notification emails like this one, please contact
"commits@couchdb.apache.org" <co...@couchdb.apache.org>.
[couchdb] 01/08: Remove module attribute
Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
davisp pushed a commit to branch elixir-suite-davisp
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 4898c0850e304692f1568cf9d8ca41f35c1868f8
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Thu Dec 7 10:38:26 2017 -0600
Remove module attribute
---
elixir_suite/test/uuids_test.exs | 2 --
1 file changed, 2 deletions(-)
diff --git a/elixir_suite/test/uuids_test.exs b/elixir_suite/test/uuids_test.exs
index 3e18e4a..8a9d7f4 100644
--- a/elixir_suite/test/uuids_test.exs
+++ b/elixir_suite/test/uuids_test.exs
@@ -1,8 +1,6 @@
defmodule UUIDsTest do
use CouchTestCase
- @moduletag :config
-
@moduledoc """
Test CouchDB UUIDs API
This is a port of the uuids.js suite
--
To stop receiving notification emails like this one, please contact
"commits@couchdb.apache.org" <co...@couchdb.apache.org>.
[couchdb] 08/08: Port view_collation.js to view_collation_test.exs
Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
davisp pushed a commit to branch elixir-suite-davisp
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 86708b5c63f8e78d44a225ce02b027f812cdb7f7
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Thu Dec 7 12:06:59 2017 -0600
Port view_collation.js to view_collation_test.exs
---
elixir_suite/test/view_collation_test.exs | 133 ++++++++++++++++++++++++++++++
1 file changed, 133 insertions(+)
diff --git a/elixir_suite/test/view_collation_test.exs b/elixir_suite/test/view_collation_test.exs
new file mode 100644
index 0000000..10aec2f
--- /dev/null
+++ b/elixir_suite/test/view_collation_test.exs
@@ -0,0 +1,133 @@
+defmodule ViewCollationTest do
+ use CouchTestCase
+
+ @moduledoc """
+ Test CouchDB View Collation Behavior
+ This is a port of the view_collation.js suite
+ """
+
+ @values [
+ # Special values sort before all other types
+ :null,
+ :false,
+ :true,
+
+ # Then numbers
+ 1,
+ 2,
+ 3.0,
+ 4,
+
+ # Then text, case sensitive
+ "a",
+ "A",
+ "aa",
+ "b",
+ "B",
+ "ba",
+ "bb",
+
+ # Then arrays, compared element by element until different.
+ # Longer arrays sort after their prefixes
+ ["a"],
+ ["b"],
+ ["b", "c"],
+ ["b", "c", "a"],
+ ["b", "d"],
+ ["b", "d", "e"],
+
+ # Then objects, compared each key value in the list until different.
+ # Larger objects sort after their subset objects
+ {[a: 1]},
+ {[a: 2]},
+ {[b: 1]},
+ {[b: 2]},
+ # Member order does matter for collation
+ {[b: 2, a: 1]},
+ {[b: 2, c: 2]}
+ ]
+
+ setup_all do
+ db_name = random_db_name()
+ {:ok, _} = create_db(db_name)
+ on_exit(fn -> delete_db(db_name) end)
+
+ {docs, _} = Enum.flat_map_reduce(@values, 1, fn value, idx ->
+ doc = %{:_id => Integer.to_string(idx), :foo => value}
+ {[doc], idx + 1}
+ end)
+ resp = Couch.post("/#{db_name}/_bulk_docs", body: %{:docs => docs})
+ Enum.each(resp.body, &(assert &1["ok"]))
+
+ map_fun = "function(doc) { emit(doc.foo, null); }"
+ map_doc = %{:views => %{:foo => %{:map => map_fun}}}
+ resp = Couch.put("/#{db_name}/_design/foo", body: map_doc)
+ assert resp.body["ok"]
+
+ {:ok, [db_name: db_name]}
+ end
+
+ test "ascending collation order", context do
+ resp = Couch.get(url(context))
+ pairs = Enum.zip(resp.body["rows"], @values)
+ Enum.each(pairs, fn {row, value} ->
+ assert row["key"] == convert(value)
+ end)
+ end
+
+ test "descending collation order", context do
+ resp = Couch.get(url(context), query: %{"descending" => "true"})
+ pairs = Enum.zip(resp.body["rows"], Enum.reverse(@values))
+ Enum.each(pairs, fn {row, value} ->
+ assert row["key"] == convert(value)
+ end)
+ end
+
+ test "key query option", context do
+ Enum.each(@values, fn value ->
+ resp = Couch.get(url(context), query: %{:key => :jiffy.encode(value)})
+ assert length(resp.body["rows"]) == 1
+ assert Enum.at(resp.body["rows"], 0)["key"] == convert(value)
+ end)
+ end
+
+ test "inclusive_end=true", context do
+ query = %{:endkey => :jiffy.encode("b"), :inclusive_end => true}
+ resp = Couch.get(url(context), query: query)
+ assert Enum.at(resp.body["rows"], -1)["key"] == "b"
+
+ query = Map.put(query, :descending, true)
+ resp = Couch.get(url(context), query: query)
+ assert Enum.at(resp.body["rows"], -1)["key"] == "b"
+ end
+
+ test "inclusive_end=false", context do
+ query = %{:endkey => :jiffy.encode("b"), :inclusive_end => false}
+ resp = Couch.get(url(context), query: query)
+ assert Enum.at(resp.body["rows"], -1)["key"] == "aa"
+
+ query = Map.put(query, :descending, true)
+ resp = Couch.get(url(context), query: query)
+ assert Enum.at(resp.body["rows"], -1)["key"] == "B"
+
+ query = %{
+ :endkey => :jiffy.encode("b"),
+ :endkey_docid => 11,
+ :inclusive_end => false
+ }
+ resp = Couch.get(url(context), query: query)
+ assert Enum.at(resp.body["rows"], -1)["key"] == "aa"
+
+ query = Map.put(query, :endkey_docid, 12)
+ resp = Couch.get(url(context), query: query)
+ assert Enum.at(resp.body["rows"], -1)["key"] == "b"
+ end
+
+ def url(context) do
+ "/#{context[:db_name]}/_design/foo/_view/foo"
+ end
+
+ def convert(value) do
+ :jiffy.decode(:jiffy.encode(value), [:return_maps])
+ end
+end
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
"commits@couchdb.apache.org" <co...@couchdb.apache.org>.
[couchdb] 03/08: Simple .gitignore for sanity
Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
davisp pushed a commit to branch elixir-suite-davisp
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 7e10c7094994bdbedb8afbae42252712846273bb
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Thu Dec 7 10:39:04 2017 -0600
Simple .gitignore for sanity
---
elixir_suite/.gitignore | 2 ++
1 file changed, 2 insertions(+)
diff --git a/elixir_suite/.gitignore b/elixir_suite/.gitignore
new file mode 100644
index 0000000..2e39def
--- /dev/null
+++ b/elixir_suite/.gitignore
@@ -0,0 +1,2 @@
+_build/
+deps/
--
To stop receiving notification emails like this one, please contact
"commits@couchdb.apache.org" <co...@couchdb.apache.org>.