diff options
author | Alessio Biancalana <dottorblaster@gmail.com> | 2018-11-28 09:58:51 +0100 |
---|---|---|
committer | garren smith <garren.smith@gmail.com> | 2018-11-28 10:58:51 +0200 |
commit | eca86229233339bee8bf287975554981269f6b91 (patch) | |
tree | e03b46b206b157debff396e279a4beb0ddc2c81d | |
parent | 78b0a7d7ebe50d0cfc4f25d8779c82386f10af8a (diff) | |
download | couchdb-eca86229233339bee8bf287975554981269f6b91.tar.gz |
test: port large_docs.js to Elixir test suite (#1745)
-rw-r--r-- | test/elixir/README.md | 2 | ||||
-rw-r--r-- | test/elixir/test/large_docs_text.exs | 40 |
2 files changed, 41 insertions, 1 deletions
diff --git a/test/elixir/README.md b/test/elixir/README.md index 1b515c2da..e80df1f31 100644 --- a/test/elixir/README.md +++ b/test/elixir/README.md @@ -44,7 +44,7 @@ X means done, - means partially - [ ] Port http.js - [ ] Port invalid_docids.js - [ ] Port jsonp.js - - [ ] Port large_docs.js + - [X] Port large_docs.js - [ ] Port list_views.js - [ ] Port lorem_b64.txt - [ ] Port lorem.txt diff --git a/test/elixir/test/large_docs_text.exs b/test/elixir/test/large_docs_text.exs new file mode 100644 index 000000000..4d2c5dede --- /dev/null +++ b/test/elixir/test/large_docs_text.exs @@ -0,0 +1,40 @@ +defmodule LargeDocsTest do + use CouchTestCase + + @moduletag :large_docs + @long_string "0123456789\n" + + @moduledoc """ + Test saving a bunch of large documents. + This is a port of the large_docs.js suite + """ + + @tag :with_db + test "Large docs", context do + db_name = context[:db_name] + long_text = String.duplicate(@long_string, 10) + + resp1 = Couch.post("/#{db_name}", body: %{:_id => "0", :longtest => long_text}).body + resp2 = Couch.post("/#{db_name}", body: %{:_id => "1", :longtest => long_text}).body + resp3 = Couch.post("/#{db_name}", body: %{:_id => "2", :longtest => long_text}).body + resp4 = Couch.post("/#{db_name}", body: %{:_id => "3", :longtest => long_text}).body + + assert resp1["ok"] + assert resp2["ok"] + assert resp3["ok"] + assert resp4["ok"] + + %{"rows" => rows} = query(db_name) + assert Enum.count(rows) === 4 + Enum.each(rows, fn row -> assert row["value"] === long_text end) + end + + defp query(db_name) do + map_fun = "function(doc) { emit(null, doc.longtest); }" + map_doc = %{:views => %{:view => %{:map => map_fun}}} + %{"rev" => rev} = Couch.put("/#{db_name}/_design/tempddoc", body: map_doc).body + response = Couch.get("/#{db_name}/_design/tempddoc/_view/view").body + Couch.delete("/#{db_name}/_design/tempddoc?rev=#{rev}") + response + end +end |