Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B46A2185D4 for ; Wed, 2 Dec 2015 23:02:05 +0000 (UTC) Received: (qmail 43090 invoked by uid 500); 2 Dec 2015 23:02:03 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 42589 invoked by uid 500); 2 Dec 2015 23:02:03 -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 40586 invoked by uid 99); 2 Dec 2015 23:02:01 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 Dec 2015 23:02:01 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id C3E3FE67D4; Wed, 2 Dec 2015 23:02:01 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: kxepal@apache.org To: commits@couchdb.apache.org Date: Wed, 02 Dec 2015 23:02:32 -0000 Message-Id: In-Reply-To: <420563d655c74cdd8457841366bdc54d@git.apache.org> References: <420563d655c74cdd8457841366bdc54d@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [32/50] couchdb commit: updated refs/heads/1.x.x to 921006f Port couch_mrview/03-red-views.t etap test suite to eunit Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/70ddbdc5 Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/70ddbdc5 Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/70ddbdc5 Branch: refs/heads/1.x.x Commit: 70ddbdc57563ecd8ab4c1d746b8bda46ce85c406 Parents: 93266ba Author: Alexander Shorin Authored: Wed Jun 11 18:15:41 2014 +0400 Committer: Alexander Shorin Committed: Thu Dec 3 00:52:05 2015 +0300 ---------------------------------------------------------------------- src/couch_mrview/Makefile.am | 2 +- src/couch_mrview/test/03-red-views.t | 78 -------------- .../test/couch_mrview_red_views_tests.erl | 108 +++++++++++++++++++ 3 files changed, 109 insertions(+), 79 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb/blob/70ddbdc5/src/couch_mrview/Makefile.am ---------------------------------------------------------------------- diff --git a/src/couch_mrview/Makefile.am b/src/couch_mrview/Makefile.am index dfe412b..59ee5fe 100644 --- a/src/couch_mrview/Makefile.am +++ b/src/couch_mrview/Makefile.am @@ -35,7 +35,7 @@ source_files = \ test_files = \ test/couch_mrview_map_views_tests.erl \ test/couch_mrview_modules_load_tests.erl \ - test/03-red-views.t \ + test/couch_mrview_red_views_tests.erl \ test/04-index-info.t \ test/05-collation.t \ test/06-all-docs.t \ http://git-wip-us.apache.org/repos/asf/couchdb/blob/70ddbdc5/src/couch_mrview/test/03-red-views.t ---------------------------------------------------------------------- diff --git a/src/couch_mrview/test/03-red-views.t b/src/couch_mrview/test/03-red-views.t deleted file mode 100644 index 6ad341b..0000000 --- a/src/couch_mrview/test/03-red-views.t +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/env escript -%% -*- erlang -*- - -% Licensed under the Apache License, Version 2.0 (the "License"); you may not -% use this file except in compliance with the License. You may obtain a copy of -% the License at -% -% http://www.apache.org/licenses/LICENSE-2.0 -% -% Unless required by applicable law or agreed to in writing, software -% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -% License for the specific language governing permissions and limitations under -% the License. - -main(_) -> - test_util:run(4, fun() -> test() end). - -test() -> - couch_server_sup:start_link(test_util:config_files()), - - {ok, Db} = couch_mrview_test_util:init_db(<<"foo">>, red), - - test_basic(Db), - test_key_range(Db), - test_group_level(Db), - test_group_exact(Db), - - ok. - - -test_basic(Db) -> - Result = run_query(Db, []), - Expect = {ok, [ - {meta, []}, - {row, [{key, null}, {value, 55}]} - ]}, - etap:is(Result, Expect, "Simple reduce view works."). - - -test_key_range(Db) -> - Result = run_query(Db, [{start_key, [0, 2]}, {end_key, [0, 4]}]), - Expect = {ok, [ - {meta, []}, - {row, [{key, null}, {value, 6}]} - ]}, - etap:is(Result, Expect, "Reduce with key range works."). - - -test_group_level(Db) -> - Result = run_query(Db, [{group_level, 1}]), - Expect = {ok, [ - {meta, []}, - {row, [{key, [0]}, {value, 30}]}, - {row, [{key, [1]}, {value, 25}]} - ]}, - etap:is(Result, Expect, "Group level works."). - -test_group_exact(Db) -> - Result = run_query(Db, [{group_level, exact}]), - Expect = {ok, [ - {meta, []}, - {row, [{key, [0, 2]}, {value, 2}]}, - {row, [{key, [0, 4]}, {value, 4}]}, - {row, [{key, [0, 6]}, {value, 6}]}, - {row, [{key, [0, 8]}, {value, 8}]}, - {row, [{key, [0, 10]}, {value, 10}]}, - {row, [{key, [1, 1]}, {value, 1}]}, - {row, [{key, [1, 3]}, {value, 3}]}, - {row, [{key, [1, 5]}, {value, 5}]}, - {row, [{key, [1, 7]}, {value, 7}]}, - {row, [{key, [1, 9]}, {value, 9}]} - ]}, - etap:is(Result, Expect, "Group exact works."). - - -run_query(Db, Opts) -> - couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>, Opts). http://git-wip-us.apache.org/repos/asf/couchdb/blob/70ddbdc5/src/couch_mrview/test/couch_mrview_red_views_tests.erl ---------------------------------------------------------------------- diff --git a/src/couch_mrview/test/couch_mrview_red_views_tests.erl b/src/couch_mrview/test/couch_mrview_red_views_tests.erl new file mode 100644 index 0000000..430d3e2 --- /dev/null +++ b/src/couch_mrview/test/couch_mrview_red_views_tests.erl @@ -0,0 +1,108 @@ +% Licensed under the Apache License, Version 2.0 (the "License"); you may not +% use this file except in compliance with the License. You may obtain a copy of +% the License at +% +% http://www.apache.org/licenses/LICENSE-2.0 +% +% Unless required by applicable law or agreed to in writing, software +% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +% License for the specific language governing permissions and limitations under +% the License. + +-module(couch_mrview_red_views_tests). + +-include("couch_eunit.hrl"). +-include_lib("couchdb/couch_db.hrl"). + +-define(TIMEOUT, 1000). +-define(ADMIN_USER, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}). + + +start() -> + {ok, Pid} = couch_server_sup:start_link(?CONFIG_CHAIN), + Pid. + +stop(Pid) -> + erlang:monitor(process, Pid), + couch_server_sup:stop(), + receive + {'DOWN', _, _, Pid, _} -> + ok + after ?TIMEOUT -> + throw({timeout, server_stop}) + end. + +setup() -> + {ok, Db} = couch_mrview_test_util:init_db(?tempdb(), red), + Db. + +teardown(Db) -> + ok = couch_db:close(Db). + + +reduce_views_test_() -> + { + "Reduce views", + { + setup, + fun start/0, fun stop/1, + { + foreach, + fun setup/0, fun teardown/1, + [ + fun should_reduce_basic/1, + fun should_reduce_key_range/1, + fun should_reduce_with_group_level/1, + fun should_reduce_with_group_exact/1 + ] + } + } + }. + + +should_reduce_basic(Db) -> + Result = run_query(Db, []), + Expect = {ok, [ + {meta, []}, + {row, [{key, null}, {value, 55}]} + ]}, + ?_assertEqual(Expect, Result). + +should_reduce_key_range(Db) -> + Result = run_query(Db, [{start_key, [0, 2]}, {end_key, [0, 4]}]), + Expect = {ok, [ + {meta, []}, + {row, [{key, null}, {value, 6}]} + ]}, + ?_assertEqual(Expect, Result). + +should_reduce_with_group_level(Db) -> + Result = run_query(Db, [{group_level, 1}]), + Expect = {ok, [ + {meta, []}, + {row, [{key, [0]}, {value, 30}]}, + {row, [{key, [1]}, {value, 25}]} + ]}, + ?_assertEqual(Expect, Result). + +should_reduce_with_group_exact(Db) -> + Result = run_query(Db, [{group_level, exact}]), + Expect = {ok, [ + {meta, []}, + {row, [{key, [0, 2]}, {value, 2}]}, + {row, [{key, [0, 4]}, {value, 4}]}, + {row, [{key, [0, 6]}, {value, 6}]}, + {row, [{key, [0, 8]}, {value, 8}]}, + {row, [{key, [0, 10]}, {value, 10}]}, + {row, [{key, [1, 1]}, {value, 1}]}, + {row, [{key, [1, 3]}, {value, 3}]}, + {row, [{key, [1, 5]}, {value, 5}]}, + {row, [{key, [1, 7]}, {value, 7}]}, + {row, [{key, [1, 9]}, {value, 9}]} + ]}, + ?_assertEqual(Expect, Result). + + +run_query(Db, Opts) -> + couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>, Opts).