From commits-return-36018-archive-asf-public=cust-asf.ponee.io@couchdb.apache.org Tue Jan 15 16:14:42 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 6077B180675 for ; Tue, 15 Jan 2019 16:14:42 +0100 (CET) Received: (qmail 36578 invoked by uid 500); 15 Jan 2019 15:14:41 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 36477 invoked by uid 99); 15 Jan 2019 15:14:41 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Jan 2019 15:14:41 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id C990E870CF; Tue, 15 Jan 2019 15:14:40 +0000 (UTC) Date: Tue, 15 Jan 2019 15:14:41 +0000 To: "commits@couchdb.apache.org" Subject: [couchdb] 01/01: add partition tests for all_docs endpoint MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit From: garren@apache.org In-Reply-To: <154756528059.21136.7426152633514093366@gitbox.apache.org> References: <154756528059.21136.7426152633514093366@gitbox.apache.org> X-Git-Host: gitbox.apache.org X-Git-Repo: couchdb X-Git-Refname: refs/heads/partition-all-docs-tests X-Git-Reftype: branch X-Git-Rev: 0cd437126a9fad591aa56a37bbd6f34b183329c5 X-Git-NotificationType: diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated Message-Id: <20190115151440.C990E870CF@gitbox.apache.org> This is an automated email from the ASF dual-hosted git repository. garren pushed a commit to branch partition-all-docs-tests in repository https://gitbox.apache.org/repos/asf/couchdb.git commit 0cd437126a9fad591aa56a37bbd6f34b183329c5 Author: Garren Smith AuthorDate: Tue Jan 15 17:14:15 2019 +0200 add partition tests for all_docs endpoint --- test/elixir/test/partition_all_docs_test.exs | 118 +++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) diff --git a/test/elixir/test/partition_all_docs_test.exs b/test/elixir/test/partition_all_docs_test.exs new file mode 100644 index 0000000..0941daf --- /dev/null +++ b/test/elixir/test/partition_all_docs_test.exs @@ -0,0 +1,118 @@ +defmodule PartitionAllDocsTest do + use CouchTestCase + import PartitionHelpers + + @moduledoc """ + Test Partition functionality for for all_docs + """ + + setup_all do + db_name = random_db_name() + {:ok, _} = create_db(db_name, query: %{partitioned: true, q: 1}) + on_exit(fn -> delete_db(db_name) end) + + create_partition_docs(db_name) + + {:ok, [db_name: db_name]} + end + + test "all_docs with partitioned:true returns partitioned fields", context do + db_name = context[:db_name] + + url = "/#{db_name}/_partition/foo/_all_docs" + resp = Couch.get(url) + assert resp.status_code == 200 + partitions = get_partitions(resp) + assert Enum.dedup(partitions) == ["foo"] + + url = "/#{db_name}/_partition/bar/_all_docs" + resp = Couch.get(url) + assert resp.status_code == 200 + partitions = get_partitions(resp) + assert Enum.dedup(partitions) == ["bar"] + end + + test "partition all_docs errors with incorrect partition supplied", context do + db_name = context[:db_name] + + url = "/#{db_name}/_partition/_bar/_all_docs" + resp = Couch.get(url) + assert resp.status_code == 400 + + url = "/#{db_name}/_partition//_all_docs" + resp = Couch.get(url) + assert resp.status_code == 400 + end + + test "partitioned _all_docs works with startkey, endkey range", context do + db_name = context[:db_name] + + url = "/#{db_name}/_partition/foo/_all_docs" + resp = Couch.get(url, query: %{start_key: "\"foo:12\"", end_key: "\"foo:2\""}) + assert resp.status_code == 200 + partitions = get_partitions(resp) + assert length(partitions) == 5 + assert Enum.dedup(partitions) == ["foo"] + end + + test "partitioned _all_docs works with keys", context do + db_name = context[:db_name] + + url = "/#{db_name}/_partition/foo/_all_docs" + resp = Couch.post(url, body: %{keys: ["foo:2", "foo:4", "foo:6"]}) + assert resp.status_code == 200 + ids = get_ids(resp) + assert length(ids) == 3 + assert ids == ["foo:2", "foo:4", "foo:6"] + end + + test "partition _all_docs works with limit", context do + db_name = context[:db_name] + + url = "/#{db_name}/_partition/foo/_all_docs" + resp = Couch.get(url, query: %{limit: 5}) + assert resp.status_code == 200 + partitions = get_partitions(resp) + assert length(partitions) == 5 + assert Enum.dedup(partitions) == ["foo"] + end + + test "partition _all_docs with descending", context do + db_name = context[:db_name] + + url = "/#{db_name}/_partition/foo/_all_docs" + resp = Couch.get(url, query: %{descending: true, limit: 5}) + assert resp.status_code == 200 + ids = get_ids(resp) + assert length(ids) == 5 + assert ids == ["foo:98", "foo:96", "foo:94", "foo:92", "foo:90"] + + resp = Couch.get(url, query: %{descending: false, limit: 5}) + assert resp.status_code == 200 + ids = get_ids(resp) + assert length(ids) == 5 + assert ids == ["foo:10", "foo:100", "foo:12", "foo:14", "foo:16"] + end + + test "partition _all_docs with skip", context do + db_name = context[:db_name] + + url = "/#{db_name}/_partition/foo/_all_docs" + resp = Couch.get(url, query: %{skip: 5, limit: 5}) + assert resp.status_code == 200 + ids = get_ids(resp) + assert length(ids) == 5 + assert ids == ["foo:18", "foo:2", "foo:20", "foo:22", "foo:24"] + end + + test "partition _all_docs with key", context do + db_name = context[:db_name] + + url = "/#{db_name}/_partition/foo/_all_docs" + resp = Couch.get(url, query: %{key: "\"foo:22\""}) + assert resp.status_code == 200 + ids = get_ids(resp) + assert length(ids) == 1 + assert ids == ["foo:22"] + end +end