You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2014/09/05 23:10:36 UTC

[01/14] couch-mrview commit: updated refs/heads/master to d548785

Repository: couchdb-couch-mrview
Updated Branches:
  refs/heads/master 08cbd5a3f -> d5487852a


Port couch_mrview/06-all-docs.t etap test suite to eunit


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/40e770ed
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/40e770ed
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/40e770ed

Branch: refs/heads/master
Commit: 40e770edb38dd10cc50797ed82c12f9715a0de36
Parents: 776605b
Author: Alexander Shorin <kx...@apache.org>
Authored: Thu Jun 12 02:39:46 2014 +0400
Committer: Russell Branca <ch...@apache.org>
Committed: Thu Aug 28 10:27:04 2014 -0700

----------------------------------------------------------------------
 .../test/couch_mrview_all_docs_tests.erl        | 154 +++++++++++++++++++
 test/06-all-docs.t                              | 127 ---------------
 2 files changed, 154 insertions(+), 127 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/40e770ed/src/couch_mrview/test/couch_mrview_all_docs_tests.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview/test/couch_mrview_all_docs_tests.erl b/src/couch_mrview/test/couch_mrview_all_docs_tests.erl
new file mode 100644
index 0000000..6d73c68
--- /dev/null
+++ b/src/couch_mrview/test/couch_mrview_all_docs_tests.erl
@@ -0,0 +1,154 @@
+% 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_all_docs_tests).
+
+-include("../../../test/couchdb/couch_eunit.hrl").
+-include_lib("couchdb/couch_db.hrl").
+
+-define(ADMIN_USER, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}).
+-define(TIMEOUT, 1000).
+
+
+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(), map),
+    Db.
+
+teardown(Db) ->
+    couch_db:close(Db),
+    couch_server:delete(Db#db.name, [?ADMIN_USER]),
+    ok.
+
+
+all_docs_test_() ->
+    {
+        "_all_docs view tests",
+        {
+            setup,
+            fun start/0, fun stop/1,
+            {
+                foreach,
+                fun setup/0, fun teardown/1,
+                [
+                    fun should_query/1,
+                    fun should_query_with_range/1,
+                    fun should_query_with_range_rev/1,
+                    fun should_query_with_limit_and_skip/1,
+                    fun should_query_with_include_docs/1,
+                    fun should_query_empty_views/1
+                ]
+            }
+        }
+    }.
+
+
+should_query(Db) ->
+    Result = run_query(Db, []),
+    Expect = {ok, [
+        {meta, [{total, 11}, {offset, 0}]},
+        mk_row(<<"1">>, <<"1-08d53a5760b95fce6df2e2c5b008be39">>),
+        mk_row(<<"10">>, <<"1-a05b6ea2bc0243949f103d5b4f15f71e">>),
+        mk_row(<<"2">>, <<"1-b57c77a9e6f7574ca6469f0d6dcd78bb">>),
+        mk_row(<<"3">>, <<"1-7fbf84d56f8017880974402d60f5acd6">>),
+        mk_row(<<"4">>, <<"1-fcaf5852c08ffb239ac8ce16c409f253">>),
+        mk_row(<<"5">>, <<"1-aaac5d460fd40f9286e57b9bf12e23d2">>),
+        mk_row(<<"6">>, <<"1-aca21c2e7bc5f8951424fcfc5d1209d8">>),
+        mk_row(<<"7">>, <<"1-4374aeec17590d82f16e70f318116ad9">>),
+        mk_row(<<"8">>, <<"1-55b9a29311341e07ec0a7ca13bc1b59f">>),
+        mk_row(<<"9">>, <<"1-558c8487d9aee25399a91b5d31d90fe2">>),
+        mk_row(<<"_design/bar">>, <<"1-a44e1dd1994a7717bf89c894ebd1f081">>)
+    ]},
+    ?_assertEqual(Expect, Result).
+
+should_query_with_range(Db) ->
+    Result = run_query(Db, [{start_key, <<"3">>}, {end_key, <<"5">>}]),
+    Expect = {ok, [
+        {meta, [{total, 11}, {offset, 3}]},
+        mk_row(<<"3">>, <<"1-7fbf84d56f8017880974402d60f5acd6">>),
+        mk_row(<<"4">>, <<"1-fcaf5852c08ffb239ac8ce16c409f253">>),
+        mk_row(<<"5">>, <<"1-aaac5d460fd40f9286e57b9bf12e23d2">>)
+    ]},
+    ?_assertEqual(Expect, Result).
+
+should_query_with_range_rev(Db) ->
+    Result = run_query(Db, [
+        {direction, rev},
+        {start_key, <<"5">>}, {end_key, <<"3">>},
+        {inclusive_end, true}
+    ]),
+    Expect = {ok, [
+        {meta, [{total, 11}, {offset, 5}]},
+        mk_row(<<"5">>, <<"1-aaac5d460fd40f9286e57b9bf12e23d2">>),
+        mk_row(<<"4">>, <<"1-fcaf5852c08ffb239ac8ce16c409f253">>),
+        mk_row(<<"3">>, <<"1-7fbf84d56f8017880974402d60f5acd6">>)
+    ]},
+    ?_assertEqual(Expect, Result).
+
+should_query_with_limit_and_skip(Db) ->
+    Result = run_query(Db, [
+        {start_key, <<"2">>},
+        {limit, 3},
+        {skip, 3}
+    ]),
+    Expect = {ok, [
+        {meta, [{total, 11}, {offset, 5}]},
+        mk_row(<<"5">>, <<"1-aaac5d460fd40f9286e57b9bf12e23d2">>),
+        mk_row(<<"6">>, <<"1-aca21c2e7bc5f8951424fcfc5d1209d8">>),
+        mk_row(<<"7">>, <<"1-4374aeec17590d82f16e70f318116ad9">>)
+    ]},
+    ?_assertEqual(Expect, Result).
+
+should_query_with_include_docs(Db) ->
+    Result = run_query(Db, [
+        {start_key, <<"8">>},
+        {end_key, <<"8">>},
+        {include_docs, true}
+    ]),
+    Doc = {[
+        {<<"_id">>,<<"8">>},
+        {<<"_rev">>, <<"1-55b9a29311341e07ec0a7ca13bc1b59f">>},
+        {<<"val">>, 8}
+    ]},
+    Val = {[{rev, <<"1-55b9a29311341e07ec0a7ca13bc1b59f">>}]},
+    Expect = {ok, [
+        {meta, [{total, 11}, {offset, 8}]},
+        {row, [{id, <<"8">>}, {key, <<"8">>}, {value, Val}, {doc, Doc}]}
+    ]},
+    ?_assertEqual(Expect, Result).
+
+should_query_empty_views(Db) ->
+    Result = couch_mrview:query_view(Db, <<"_design/bar">>, <<"bing">>),
+    Expect = {ok, [
+        {meta, [{total, 0}, {offset, 0}]}
+    ]},
+    ?_assertEqual(Expect, Result).
+
+
+mk_row(Id, Rev) ->
+    {row, [{id, Id}, {key, Id}, {value, {[{rev, Rev}]}}]}.
+
+run_query(Db, Opts) ->
+    couch_mrview:query_all_docs(Db, Opts).

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/40e770ed/test/06-all-docs.t
----------------------------------------------------------------------
diff --git a/test/06-all-docs.t b/test/06-all-docs.t
deleted file mode 100644
index a3aafa0..0000000
--- a/test/06-all-docs.t
+++ /dev/null
@@ -1,127 +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(6, fun() -> test() end).
-
-
-test() ->
-    test_util:start_couch(),
-
-    {ok, Db} = couch_mrview_test_util:init_db(<<"foo">>, map),
-
-    test_basic(Db),
-    test_range(Db),
-    test_rev_range(Db),
-    test_limit_and_skip(Db),
-    test_include_docs(Db),
-    test_empty_view(Db),
-
-    ok.
-
-
-test_basic(Db) ->
-    Result = run_query(Db, []),
-    Expect = {ok, [
-        {meta, [{total, 11}, {offset, 0}]},
-        mk_row(<<"1">>, <<"1-08d53a5760b95fce6df2e2c5b008be39">>),
-        mk_row(<<"10">>, <<"1-a05b6ea2bc0243949f103d5b4f15f71e">>),
-        mk_row(<<"2">>, <<"1-b57c77a9e6f7574ca6469f0d6dcd78bb">>),
-        mk_row(<<"3">>, <<"1-7fbf84d56f8017880974402d60f5acd6">>),
-        mk_row(<<"4">>, <<"1-fcaf5852c08ffb239ac8ce16c409f253">>),
-        mk_row(<<"5">>, <<"1-aaac5d460fd40f9286e57b9bf12e23d2">>),
-        mk_row(<<"6">>, <<"1-aca21c2e7bc5f8951424fcfc5d1209d8">>),
-        mk_row(<<"7">>, <<"1-4374aeec17590d82f16e70f318116ad9">>),
-        mk_row(<<"8">>, <<"1-55b9a29311341e07ec0a7ca13bc1b59f">>),
-        mk_row(<<"9">>, <<"1-558c8487d9aee25399a91b5d31d90fe2">>),
-        mk_row(<<"_design/bar">>, <<"1-a44e1dd1994a7717bf89c894ebd1f081">>)
-    ]},
-    etap:is(Result, Expect, "Simple view query worked.").
-
-
-test_range(Db) ->
-    Result = run_query(Db, [{start_key, <<"3">>}, {end_key, <<"5">>}]),
-    Expect = {ok, [
-        {meta, [{total, 11}, {offset, 3}]},
-        mk_row(<<"3">>, <<"1-7fbf84d56f8017880974402d60f5acd6">>),
-        mk_row(<<"4">>, <<"1-fcaf5852c08ffb239ac8ce16c409f253">>),
-        mk_row(<<"5">>, <<"1-aaac5d460fd40f9286e57b9bf12e23d2">>)
-    ]},
-    etap:is(Result, Expect, "Query with range works.").
-
-
-test_rev_range(Db) ->
-    Result = run_query(Db, [
-        {direction, rev},
-        {start_key, <<"5">>}, {end_key, <<"3">>},
-        {inclusive_end, true}
-    ]),
-    Expect = {ok, [
-        {meta, [{total, 11}, {offset, 5}]},
-        mk_row(<<"5">>, <<"1-aaac5d460fd40f9286e57b9bf12e23d2">>),
-        mk_row(<<"4">>, <<"1-fcaf5852c08ffb239ac8ce16c409f253">>),
-        mk_row(<<"3">>, <<"1-7fbf84d56f8017880974402d60f5acd6">>)
-    ]},
-    etap:is(Result, Expect, "Query with reversed range works.").
-
-
-test_limit_and_skip(Db) ->
-    Result = run_query(Db, [
-        {start_key, <<"2">>},
-        {limit, 3},
-        {skip, 3}
-    ]),
-    Expect = {ok, [
-        {meta, [{total, 11}, {offset, 5}]},
-        mk_row(<<"5">>, <<"1-aaac5d460fd40f9286e57b9bf12e23d2">>),
-        mk_row(<<"6">>, <<"1-aca21c2e7bc5f8951424fcfc5d1209d8">>),
-        mk_row(<<"7">>, <<"1-4374aeec17590d82f16e70f318116ad9">>)
-    ]},
-    etap:is(Result, Expect, "Query with limit and skip works.").
-
-
-test_include_docs(Db) ->
-    Result = run_query(Db, [
-        {start_key, <<"8">>},
-        {end_key, <<"8">>},
-        {include_docs, true}
-    ]),
-    Doc = {[
-        {<<"_id">>,<<"8">>},
-        {<<"_rev">>, <<"1-55b9a29311341e07ec0a7ca13bc1b59f">>},
-        {<<"val">>, 8}
-    ]},
-    Val = {[{rev, <<"1-55b9a29311341e07ec0a7ca13bc1b59f">>}]},
-    Expect = {ok, [
-        {meta, [{total, 11}, {offset, 8}]},
-        {row, [{id, <<"8">>}, {key, <<"8">>}, {value, Val}, {doc, Doc}]}
-    ]},
-    etap:is(Result, Expect, "Query with include docs works.").
-
-
-test_empty_view(Db) ->
-    Result = couch_mrview:query_view(Db, <<"_design/bar">>, <<"bing">>),
-    Expect = {ok, [
-        {meta, [{total, 0}, {offset, 0}]}
-    ]},
-    etap:is(Result, Expect, "Empty views are correct.").
-
-
-mk_row(Id, Rev) ->
-    {row, [{id, Id}, {key, Id}, {value, {[{rev, Rev}]}}]}.
-
-
-run_query(Db, Opts) ->
-    couch_mrview:query_all_docs(Db, Opts).


[03/14] couch-mrview commit: updated refs/heads/master to d548785

Posted by rn...@apache.org.
Port couch_mrview/01-load.t etap test suite to eunit


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/d43bfb86
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/d43bfb86
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/d43bfb86

Branch: refs/heads/master
Commit: d43bfb867e356372635bc8f794c5f172fd89422e
Parents: 4cc8114
Author: Alexander Shorin <kx...@apache.org>
Authored: Wed Jun 11 01:29:11 2014 +0400
Committer: Russell Branca <ch...@apache.org>
Committed: Thu Aug 28 10:27:04 2014 -0700

----------------------------------------------------------------------
 .../test/couch_mrview_modules_load_tests.erl    | 37 ++++++++++++++++++++
 test/01-load.t                                  | 34 ------------------
 2 files changed, 37 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/d43bfb86/src/couch_mrview/test/couch_mrview_modules_load_tests.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview/test/couch_mrview_modules_load_tests.erl b/src/couch_mrview/test/couch_mrview_modules_load_tests.erl
new file mode 100644
index 0000000..a6f752a
--- /dev/null
+++ b/src/couch_mrview/test/couch_mrview_modules_load_tests.erl
@@ -0,0 +1,37 @@
+% 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_modules_load_tests).
+
+-include("../../../test/couchdb/couch_eunit.hrl").
+
+
+modules_load_test_() ->
+    {
+        "Verify that all modules loads",
+        should_load_modules()
+    }.
+
+
+should_load_modules() ->
+    Modules = [
+        couch_mrview,
+        couch_mrview_compactor,
+        couch_mrview_http,
+        couch_mrview_index,
+        couch_mrview_updater,
+        couch_mrview_util
+    ],
+    [should_load_module(Mod) || Mod <- Modules].
+
+should_load_module(Mod) ->
+    {atom_to_list(Mod), ?_assertMatch({module, _}, code:load_file(Mod))}.

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/d43bfb86/test/01-load.t
----------------------------------------------------------------------
diff --git a/test/01-load.t b/test/01-load.t
deleted file mode 100644
index a57c1a7..0000000
--- a/test/01-load.t
+++ /dev/null
@@ -1,34 +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.
-
-% Test that we can load each module.
-
-main(_) ->
-    test_util:init_code_path(),
-    Modules = [
-        couch_mrview,
-        couch_mrview_compactor,
-        couch_mrview_http,
-        couch_mrview_index,
-        couch_mrview_updater,
-        couch_mrview_util
-    ],
-
-    etap:plan(length(Modules)),
-    lists:foreach(
-        fun(Module) ->
-            etap:loaded_ok(Module, lists:concat(["Loaded: ", Module]))
-        end, Modules),
-    etap:end_tests().


[06/14] couch-mrview commit: updated refs/heads/master to d548785

Posted by rn...@apache.org.
Port couch_mrview/04-index-info.t etap test suite to eunit


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/d98c180a
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/d98c180a
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/d98c180a

Branch: refs/heads/master
Commit: d98c180a617754213830d76749d9f7dd0816237e
Parents: ae26f14
Author: Alexander Shorin <kx...@apache.org>
Authored: Wed Jun 11 20:23:47 2014 +0400
Committer: Russell Branca <ch...@apache.org>
Committed: Thu Aug 28 10:27:04 2014 -0700

----------------------------------------------------------------------
 .../test/couch_mrview_index_info_tests.erl      | 87 ++++++++++++++++++++
 test/04-index-info.t                            | 43 ----------
 2 files changed, 87 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/d98c180a/src/couch_mrview/test/couch_mrview_index_info_tests.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview/test/couch_mrview_index_info_tests.erl b/src/couch_mrview/test/couch_mrview_index_info_tests.erl
new file mode 100644
index 0000000..0867a72
--- /dev/null
+++ b/src/couch_mrview/test/couch_mrview_index_info_tests.erl
@@ -0,0 +1,87 @@
+% 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_index_info_tests).
+
+-include("../../../test/couchdb/couch_eunit.hrl").
+-include_lib("couchdb/couch_db.hrl").
+
+-define(ADMIN_USER, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}).
+-define(TIMEOUT, 1000).
+
+
+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(), map),
+    couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>),
+    {ok, Info} = couch_mrview:get_info(Db, <<"_design/bar">>),
+    {Db, Info}.
+
+teardown({Db, _}) ->
+    couch_db:close(Db),
+    couch_server:delete(Db#db.name, [?ADMIN_USER]),
+    ok.
+
+
+view_info_test_() ->
+    {
+        "Views index tests",
+        {
+            setup,
+            fun start/0, fun stop/1,
+            {
+                foreach,
+                fun setup/0, fun teardown/1,
+                [
+                    fun should_get_property/1
+                ]
+            }
+        }
+    }.
+
+
+should_get_property({_, Info}) ->
+    InfoProps = [
+        {signature, <<"276df562b152b3c4e5d34024f62672ed">>},
+        {language, <<"javascript">>},
+        {disk_size, 314},
+        {data_size, 263},
+        {update_seq, 11},
+        {purge_seq, 0},
+        {updater_running, false},
+        {compact_running, false},
+        {waiting_clients, 0}
+    ],
+    [
+        {atom_to_list(Key), ?_assertEqual(Val, getval(Key, Info))}
+        || {Key, Val} <- InfoProps
+    ].
+
+
+getval(Key, PL) ->
+    {value, {Key, Val}} = lists:keysearch(Key, 1, PL),
+    Val.
+
+

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/d98c180a/test/04-index-info.t
----------------------------------------------------------------------
diff --git a/test/04-index-info.t b/test/04-index-info.t
deleted file mode 100644
index c86b168..0000000
--- a/test/04-index-info.t
+++ /dev/null
@@ -1,43 +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(9, fun() -> test() end).
-
-sig() -> <<"276df562b152b3c4e5d34024f62672ed">>.
-
-test() ->
-    test_util:start_couch(),
-
-    {ok, Db} = couch_mrview_test_util:init_db(<<"foo">>, map),
-    couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>),
-
-    {ok, Info} = couch_mrview:get_info(Db, <<"_design/bar">>),
-
-    etap:is(getval(signature, Info), sig(), "Signature is ok."),
-    etap:is(getval(language, Info), <<"javascript">>, "Language is ok."),
-    etap:is_greater(getval(disk_size, Info), 0, "Disk size is ok."),
-    etap:is_greater(getval(data_size, Info), 0, "Data size is ok."),
-    etap:is(getval(update_seq, Info), 11, "Update seq is ok."),
-    etap:is(getval(purge_seq, Info), 0, "Purge seq is ok."),
-    etap:is(getval(updater_running, Info), false, "No updater running."),
-    etap:is(getval(compact_running, Info), false, "No compaction running."),
-    etap:is(getval(waiting_clients, Info), 0, "No waiting clients."),
-
-    ok.
-
-getval(Key, PL) ->
-    {value, {Key, Val}} = lists:keysearch(Key, 1, PL),
-    Val.


[04/14] couch-mrview commit: updated refs/heads/master to d548785

Posted by rn...@apache.org.
Port couch_mrview/02-map-views.t etap test suite to eunit


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/f94401cc
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/f94401cc
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/f94401cc

Branch: refs/heads/master
Commit: f94401cc5b983d928e5bdf3b1c600882da56d0d7
Parents: d43bfb8
Author: Alexander Shorin <kx...@apache.org>
Authored: Wed Jun 11 18:14:22 2014 +0400
Committer: Russell Branca <ch...@apache.org>
Committed: Thu Aug 28 10:27:04 2014 -0700

----------------------------------------------------------------------
 .../test/couch_mrview_map_views_tests.erl       | 138 +++++++++++++++++++
 test/02-map-views.t                             | 120 ----------------
 2 files changed, 138 insertions(+), 120 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/f94401cc/src/couch_mrview/test/couch_mrview_map_views_tests.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview/test/couch_mrview_map_views_tests.erl b/src/couch_mrview/test/couch_mrview_map_views_tests.erl
new file mode 100644
index 0000000..c09490e
--- /dev/null
+++ b/src/couch_mrview/test/couch_mrview_map_views_tests.erl
@@ -0,0 +1,138 @@
+% 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_map_views_tests).
+
+-include("../../../test/couchdb/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(), map),
+    Db.
+
+teardown(Db) ->
+    couch_db:close(Db),
+    couch_server:delete(Db#db.name, [?ADMIN_USER]),
+    ok.
+
+
+map_views_test_() ->
+    {
+        "Map views",
+        {
+            setup,
+            fun start/0, fun stop/1,
+            {
+                foreach,
+                fun setup/0, fun teardown/1,
+                [
+                    fun should_map/1,
+                    fun should_map_with_range/1,
+                    fun should_map_with_limit_and_skip/1,
+                    fun should_map_with_include_docs/1,
+                    fun should_map_empty_views/1
+                ]
+            }
+        }
+    }.
+
+
+should_map(Db) ->
+    Result = run_query(Db, []),
+    Expect = {ok, [
+        {meta, [{total, 10}, {offset, 0}]},
+        {row, [{id, <<"1">>}, {key, 1}, {value, 1}]},
+        {row, [{id, <<"2">>}, {key, 2}, {value, 2}]},
+        {row, [{id, <<"3">>}, {key, 3}, {value, 3}]},
+        {row, [{id, <<"4">>}, {key, 4}, {value, 4}]},
+        {row, [{id, <<"5">>}, {key, 5}, {value, 5}]},
+        {row, [{id, <<"6">>}, {key, 6}, {value, 6}]},
+        {row, [{id, <<"7">>}, {key, 7}, {value, 7}]},
+        {row, [{id, <<"8">>}, {key, 8}, {value, 8}]},
+        {row, [{id, <<"9">>}, {key, 9}, {value, 9}]},
+        {row, [{id, <<"10">>}, {key, 10}, {value, 10}]}
+    ]},
+    ?_assertEqual(Expect, Result).
+
+should_map_with_range(Db) ->
+    Result = run_query(Db, [
+        {direction, rev},
+        {start_key, 5}, {end_key, 3},
+        {inclusive_end, true}
+    ]),
+    Expect = {ok, [
+        {meta, [{total, 10}, {offset, 5}]},
+        {row, [{id, <<"5">>}, {key, 5}, {value, 5}]},
+        {row, [{id, <<"4">>}, {key, 4}, {value, 4}]},
+        {row, [{id, <<"3">>}, {key, 3}, {value, 3}]}
+    ]},
+    ?_assertEqual(Expect, Result).
+
+should_map_with_limit_and_skip(Db) ->
+    Result = run_query(Db, [
+        {start_key, 2},
+        {limit, 3},
+        {skip, 3}
+    ]),
+    Expect = {ok, [
+        {meta, [{total, 10}, {offset, 4}]},
+        {row, [{id, <<"5">>}, {key, 5}, {value, 5}]},
+        {row, [{id, <<"6">>}, {key, 6}, {value, 6}]},
+        {row, [{id, <<"7">>}, {key, 7}, {value, 7}]}
+    ]},
+    ?_assertEqual(Expect, Result).
+
+should_map_with_include_docs(Db) ->
+    Result = run_query(Db, [
+        {start_key, 8},
+        {end_key, 8},
+        {include_docs, true}
+    ]),
+    Doc = {[
+        {<<"_id">>,<<"8">>},
+        {<<"_rev">>, <<"1-55b9a29311341e07ec0a7ca13bc1b59f">>},
+        {<<"val">>,8}
+    ]},
+    Expect = {ok, [
+        {meta, [{total, 10}, {offset, 7}]},
+        {row, [{id, <<"8">>}, {key, 8}, {value, 8}, {doc, Doc}]}
+    ]},
+    ?_assertEqual(Expect, Result).
+
+should_map_empty_views(Db) ->
+    Result = couch_mrview:query_view(Db, <<"_design/bar">>, <<"bing">>),
+    Expect = {ok, [
+        {meta, [{total, 0}, {offset, 0}]}
+    ]},
+    ?_assertEqual(Expect, Result).
+
+
+run_query(Db, Opts) ->
+    couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>, Opts).

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/f94401cc/test/02-map-views.t
----------------------------------------------------------------------
diff --git a/test/02-map-views.t b/test/02-map-views.t
deleted file mode 100644
index bcf4ce1..0000000
--- a/test/02-map-views.t
+++ /dev/null
@@ -1,120 +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(6, fun() -> test() end).
-
-test() ->
-    test_util:start_couch(),
-
-    {ok, Db} = couch_mrview_test_util:init_db(<<"foo">>, map),
-
-    test_basic(Db),
-    test_range(Db),
-    test_rev_range(Db),
-    test_limit_and_skip(Db),
-    test_include_docs(Db),
-    test_empty_view(Db),
-
-    ok.
-
-
-test_basic(Db) ->
-    Result = run_query(Db, []),
-    Expect = {ok, [
-        {meta, [{total, 10}, {offset, 0}]},
-        {row, [{id, <<"1">>}, {key, 1}, {value, 1}]},
-        {row, [{id, <<"2">>}, {key, 2}, {value, 2}]},
-        {row, [{id, <<"3">>}, {key, 3}, {value, 3}]},
-        {row, [{id, <<"4">>}, {key, 4}, {value, 4}]},
-        {row, [{id, <<"5">>}, {key, 5}, {value, 5}]},
-        {row, [{id, <<"6">>}, {key, 6}, {value, 6}]},
-        {row, [{id, <<"7">>}, {key, 7}, {value, 7}]},
-        {row, [{id, <<"8">>}, {key, 8}, {value, 8}]},
-        {row, [{id, <<"9">>}, {key, 9}, {value, 9}]},
-        {row, [{id, <<"10">>}, {key, 10}, {value, 10}]}
-    ]},
-    etap:is(Result, Expect, "Simple view query worked.").
-
-
-test_range(Db) ->
-    Result = run_query(Db, [{start_key, 3}, {end_key, 5}]),
-    Expect = {ok, [
-        {meta, [{total, 10}, {offset, 2}]},
-        {row, [{id, <<"3">>}, {key, 3}, {value, 3}]},
-        {row, [{id, <<"4">>}, {key, 4}, {value, 4}]},
-        {row, [{id, <<"5">>}, {key, 5}, {value, 5}]}
-    ]},
-    etap:is(Result, Expect, "Query with range works.").
-
-
-test_rev_range(Db) ->
-    Result = run_query(Db, [
-        {direction, rev},
-        {start_key, 5}, {end_key, 3},
-        {inclusive_end, true}
-    ]),
-    Expect = {ok, [
-        {meta, [{total, 10}, {offset, 5}]},
-        {row, [{id, <<"5">>}, {key, 5}, {value, 5}]},
-        {row, [{id, <<"4">>}, {key, 4}, {value, 4}]},
-        {row, [{id, <<"3">>}, {key, 3}, {value, 3}]}
-    ]},
-    etap:is(Result, Expect, "Query with reversed range works.").
-
-
-test_limit_and_skip(Db) ->
-    Result = run_query(Db, [
-        {start_key, 2},
-        {limit, 3},
-        {skip, 3}
-    ]),
-    Expect = {ok, [
-        {meta, [{total, 10}, {offset, 4}]},
-        {row, [{id, <<"5">>}, {key, 5}, {value, 5}]},
-        {row, [{id, <<"6">>}, {key, 6}, {value, 6}]},
-        {row, [{id, <<"7">>}, {key, 7}, {value, 7}]}
-    ]},
-    etap:is(Result, Expect, "Query with limit and skip works.").
-
-
-test_include_docs(Db) ->
-    Result = run_query(Db, [
-        {start_key, 8},
-        {end_key, 8},
-        {include_docs, true}
-    ]),
-    Doc = {[
-        {<<"_id">>,<<"8">>},
-        {<<"_rev">>, <<"1-55b9a29311341e07ec0a7ca13bc1b59f">>},
-        {<<"val">>,8}
-    ]},
-    Expect = {ok, [
-        {meta, [{total, 10}, {offset, 7}]},
-        {row, [{id, <<"8">>}, {key, 8}, {value, 8}, {doc, Doc}]}
-    ]},
-    etap:is(Result, Expect, "Query with include docs works.").
-
-
-test_empty_view(Db) ->
-    Result = couch_mrview:query_view(Db, <<"_design/bar">>, <<"bing">>),
-    Expect = {ok, [
-        {meta, [{total, 0}, {offset, 0}]}
-    ]},
-    etap:is(Result, Expect, "Empty views are correct.").
-
-
-run_query(Db, Opts) ->
-    couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>, Opts).


[07/14] couch-mrview commit: updated refs/heads/master to d548785

Posted by rn...@apache.org.
Move files out of test/couchdb into top level test/ folder


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/d6aa4147
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/d6aa4147
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/d6aa4147

Branch: refs/heads/master
Commit: d6aa4147fbdefd445f9cd1a15bb2c7573fa378a4
Parents: 7644769
Author: Russell Branca <ch...@apache.org>
Authored: Wed Aug 27 17:13:16 2014 -0700
Committer: Russell Branca <ch...@apache.org>
Committed: Thu Aug 28 10:27:05 2014 -0700

----------------------------------------------------------------------
 .../test/couch_mrview_all_docs_tests.erl        | 154 --------------
 .../test/couch_mrview_collation_tests.erl       | 202 -------------------
 .../test/couch_mrview_compact_tests.erl         | 101 ----------
 .../test/couch_mrview_index_info_tests.erl      |  87 --------
 .../test/couch_mrview_map_views_tests.erl       | 138 -------------
 .../test/couch_mrview_modules_load_tests.erl    |  37 ----
 .../test/couch_mrview_red_views_tests.erl       | 110 ----------
 test/couch_mrview_all_docs_tests.erl            | 154 ++++++++++++++
 test/couch_mrview_collation_tests.erl           | 202 +++++++++++++++++++
 test/couch_mrview_compact_tests.erl             | 101 ++++++++++
 test/couch_mrview_index_info_tests.erl          |  87 ++++++++
 test/couch_mrview_map_views_tests.erl           | 138 +++++++++++++
 test/couch_mrview_modules_load_tests.erl        |  37 ++++
 test/couch_mrview_red_views_tests.erl           | 110 ++++++++++
 14 files changed, 829 insertions(+), 829 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/d6aa4147/src/couch_mrview/test/couch_mrview_all_docs_tests.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview/test/couch_mrview_all_docs_tests.erl b/src/couch_mrview/test/couch_mrview_all_docs_tests.erl
deleted file mode 100644
index 6d73c68..0000000
--- a/src/couch_mrview/test/couch_mrview_all_docs_tests.erl
+++ /dev/null
@@ -1,154 +0,0 @@
-% 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_all_docs_tests).
-
--include("../../../test/couchdb/couch_eunit.hrl").
--include_lib("couchdb/couch_db.hrl").
-
--define(ADMIN_USER, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}).
--define(TIMEOUT, 1000).
-
-
-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(), map),
-    Db.
-
-teardown(Db) ->
-    couch_db:close(Db),
-    couch_server:delete(Db#db.name, [?ADMIN_USER]),
-    ok.
-
-
-all_docs_test_() ->
-    {
-        "_all_docs view tests",
-        {
-            setup,
-            fun start/0, fun stop/1,
-            {
-                foreach,
-                fun setup/0, fun teardown/1,
-                [
-                    fun should_query/1,
-                    fun should_query_with_range/1,
-                    fun should_query_with_range_rev/1,
-                    fun should_query_with_limit_and_skip/1,
-                    fun should_query_with_include_docs/1,
-                    fun should_query_empty_views/1
-                ]
-            }
-        }
-    }.
-
-
-should_query(Db) ->
-    Result = run_query(Db, []),
-    Expect = {ok, [
-        {meta, [{total, 11}, {offset, 0}]},
-        mk_row(<<"1">>, <<"1-08d53a5760b95fce6df2e2c5b008be39">>),
-        mk_row(<<"10">>, <<"1-a05b6ea2bc0243949f103d5b4f15f71e">>),
-        mk_row(<<"2">>, <<"1-b57c77a9e6f7574ca6469f0d6dcd78bb">>),
-        mk_row(<<"3">>, <<"1-7fbf84d56f8017880974402d60f5acd6">>),
-        mk_row(<<"4">>, <<"1-fcaf5852c08ffb239ac8ce16c409f253">>),
-        mk_row(<<"5">>, <<"1-aaac5d460fd40f9286e57b9bf12e23d2">>),
-        mk_row(<<"6">>, <<"1-aca21c2e7bc5f8951424fcfc5d1209d8">>),
-        mk_row(<<"7">>, <<"1-4374aeec17590d82f16e70f318116ad9">>),
-        mk_row(<<"8">>, <<"1-55b9a29311341e07ec0a7ca13bc1b59f">>),
-        mk_row(<<"9">>, <<"1-558c8487d9aee25399a91b5d31d90fe2">>),
-        mk_row(<<"_design/bar">>, <<"1-a44e1dd1994a7717bf89c894ebd1f081">>)
-    ]},
-    ?_assertEqual(Expect, Result).
-
-should_query_with_range(Db) ->
-    Result = run_query(Db, [{start_key, <<"3">>}, {end_key, <<"5">>}]),
-    Expect = {ok, [
-        {meta, [{total, 11}, {offset, 3}]},
-        mk_row(<<"3">>, <<"1-7fbf84d56f8017880974402d60f5acd6">>),
-        mk_row(<<"4">>, <<"1-fcaf5852c08ffb239ac8ce16c409f253">>),
-        mk_row(<<"5">>, <<"1-aaac5d460fd40f9286e57b9bf12e23d2">>)
-    ]},
-    ?_assertEqual(Expect, Result).
-
-should_query_with_range_rev(Db) ->
-    Result = run_query(Db, [
-        {direction, rev},
-        {start_key, <<"5">>}, {end_key, <<"3">>},
-        {inclusive_end, true}
-    ]),
-    Expect = {ok, [
-        {meta, [{total, 11}, {offset, 5}]},
-        mk_row(<<"5">>, <<"1-aaac5d460fd40f9286e57b9bf12e23d2">>),
-        mk_row(<<"4">>, <<"1-fcaf5852c08ffb239ac8ce16c409f253">>),
-        mk_row(<<"3">>, <<"1-7fbf84d56f8017880974402d60f5acd6">>)
-    ]},
-    ?_assertEqual(Expect, Result).
-
-should_query_with_limit_and_skip(Db) ->
-    Result = run_query(Db, [
-        {start_key, <<"2">>},
-        {limit, 3},
-        {skip, 3}
-    ]),
-    Expect = {ok, [
-        {meta, [{total, 11}, {offset, 5}]},
-        mk_row(<<"5">>, <<"1-aaac5d460fd40f9286e57b9bf12e23d2">>),
-        mk_row(<<"6">>, <<"1-aca21c2e7bc5f8951424fcfc5d1209d8">>),
-        mk_row(<<"7">>, <<"1-4374aeec17590d82f16e70f318116ad9">>)
-    ]},
-    ?_assertEqual(Expect, Result).
-
-should_query_with_include_docs(Db) ->
-    Result = run_query(Db, [
-        {start_key, <<"8">>},
-        {end_key, <<"8">>},
-        {include_docs, true}
-    ]),
-    Doc = {[
-        {<<"_id">>,<<"8">>},
-        {<<"_rev">>, <<"1-55b9a29311341e07ec0a7ca13bc1b59f">>},
-        {<<"val">>, 8}
-    ]},
-    Val = {[{rev, <<"1-55b9a29311341e07ec0a7ca13bc1b59f">>}]},
-    Expect = {ok, [
-        {meta, [{total, 11}, {offset, 8}]},
-        {row, [{id, <<"8">>}, {key, <<"8">>}, {value, Val}, {doc, Doc}]}
-    ]},
-    ?_assertEqual(Expect, Result).
-
-should_query_empty_views(Db) ->
-    Result = couch_mrview:query_view(Db, <<"_design/bar">>, <<"bing">>),
-    Expect = {ok, [
-        {meta, [{total, 0}, {offset, 0}]}
-    ]},
-    ?_assertEqual(Expect, Result).
-
-
-mk_row(Id, Rev) ->
-    {row, [{id, Id}, {key, Id}, {value, {[{rev, Rev}]}}]}.
-
-run_query(Db, Opts) ->
-    couch_mrview:query_all_docs(Db, Opts).

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/d6aa4147/src/couch_mrview/test/couch_mrview_collation_tests.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview/test/couch_mrview_collation_tests.erl b/src/couch_mrview/test/couch_mrview_collation_tests.erl
deleted file mode 100644
index 485fd2d..0000000
--- a/src/couch_mrview/test/couch_mrview_collation_tests.erl
+++ /dev/null
@@ -1,202 +0,0 @@
-% 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_collation_tests).
-
--include("../../../test/couchdb/couch_eunit.hrl").
--include_lib("couchdb/couch_db.hrl").
-
--define(ADMIN_USER, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}).
--define(TIMEOUT, 1000).
--define(VALUES, [
-    null,
-    false,
-    true,
-
-    1,
-    2,
-    3.0,
-    4,
-
-    <<"a">>,
-    <<"A">>,
-    <<"aa">>,
-    <<"b">>,
-    <<"B">>,
-    <<"ba">>,
-    <<"bb">>,
-
-    [<<"a">>],
-    [<<"b">>],
-    [<<"b">>, <<"c">>],
-    [<<"b">>, <<"c">>, <<"a">>],
-    [<<"b">>, <<"d">>],
-    [<<"b">>, <<"d">>, <<"e">>],
-
-    {[{<<"a">>, 1}]},
-    {[{<<"a">>, 2}]},
-    {[{<<"b">>, 1}]},
-    {[{<<"b">>, 2}]},
-    {[{<<"b">>, 2}, {<<"a">>, 1}]},
-    {[{<<"b">>, 2}, {<<"c">>, 2}]}
-]).
-
-
-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, Db1} = couch_mrview_test_util:new_db(?tempdb(), map),
-    {ok, Db2} = couch_mrview_test_util:save_docs(Db1, make_docs()),
-    Db2.
-
-teardown(Db) ->
-    couch_db:close(Db),
-    couch_server:delete(Db#db.name, [?ADMIN_USER]),
-    ok.
-
-
-collation_test_() ->
-    {
-        "Collation tests",
-        {
-            setup,
-            fun start/0, fun stop/1,
-            {
-                foreach,
-                fun setup/0, fun teardown/1,
-                [
-                    fun should_collate_fwd/1,
-                    fun should_collate_rev/1,
-                    fun should_collate_range/1,
-                    fun should_collate_with_inclusive_end_fwd/1,
-                    fun should_collate_with_inclusive_end_rev/1,
-                    fun should_collate_without_inclusive_end_fwd/1,
-                    fun should_collate_without_inclusive_end_rev/1,
-                    fun should_collate_with_endkey_docid/1
-                ]
-            }
-        }
-    }.
-
-
-should_collate_fwd(Db) ->
-    {ok, Results} = run_query(Db, []),
-    Expect = [{meta, [{total, 26}, {offset, 0}]}] ++ rows(),
-    %% cannot use _assertEqual since mrview converts
-    %% value 3.0 to 3 making assertion fail
-    ?_assert(Expect == Results).
-
-should_collate_rev(Db) ->
-    {ok, Results} = run_query(Db, [{direction, rev}]),
-    Expect = [{meta, [{total, 26}, {offset, 0}]}] ++ lists:reverse(rows()),
-    %% cannot use _assertEqual since mrview converts
-    %% value 3.0 to 3 making assertion fail
-    ?_assert(Expect == Results).
-
-should_collate_range(Db) ->
-    ?_assertNot(
-        begin
-            {_, Error} = lists:foldl(fun(V, {Count, Error}) ->
-                {ok, Results} = run_query(Db, [{start_key, V}, {end_key, V}]),
-                Id = list_to_binary(integer_to_list(Count)),
-                Expect = [
-                    {meta, [{total, 26}, {offset, Count}]},
-                    {row, [{id, Id}, {key, V}, {value, 0}]}
-                ],
-                case Results == Expect of
-                    true -> {Count+1, Error};
-                    _ -> {Count+1, true}
-                end
-            end, {0, false}, ?VALUES),
-            Error
-        end).
-
-should_collate_with_inclusive_end_fwd(Db) ->
-    Opts = [{end_key, <<"b">>}, {inclusive_end, true}],
-    {ok, Rows0} = run_query(Db, Opts),
-    LastRow = lists:last(Rows0),
-    Expect = {row, [{id,<<"10">>}, {key,<<"b">>}, {value,0}]},
-    ?_assertEqual(Expect, LastRow).
-
-should_collate_with_inclusive_end_rev(Db) ->
-    Opts = [{end_key, <<"b">>}, {inclusive_end, true}, {direction, rev}],
-    {ok, Rows} = run_query(Db, Opts),
-    LastRow = lists:last(Rows),
-    Expect = {row, [{id,<<"10">>}, {key,<<"b">>}, {value,0}]},
-    ?_assertEqual(Expect, LastRow).
-
-should_collate_without_inclusive_end_fwd(Db) ->
-    Opts = [{end_key, <<"b">>}, {inclusive_end, false}],
-    {ok, Rows0} = run_query(Db, Opts),
-    LastRow = lists:last(Rows0),
-    Expect = {row, [{id,<<"9">>}, {key,<<"aa">>}, {value,0}]},
-    ?_assertEqual(Expect, LastRow).
-
-should_collate_without_inclusive_end_rev(Db) ->
-    Opts = [{end_key, <<"b">>}, {inclusive_end, false}, {direction, rev}],
-    {ok, Rows} = run_query(Db, Opts),
-    LastRow = lists:last(Rows),
-    Expect = {row, [{id,<<"11">>}, {key,<<"B">>}, {value,0}]},
-    ?_assertEqual(Expect, LastRow).
-
-should_collate_with_endkey_docid(Db) ->
-    ?_test(begin
-        {ok, Rows0} = run_query(Db, [
-            {end_key, <<"b">>}, {end_key_docid, <<"10">>},
-            {inclusive_end, false}
-        ]),
-        Result0 = lists:last(Rows0),
-        Expect0 = {row, [{id,<<"9">>}, {key,<<"aa">>}, {value,0}]},
-        ?assertEqual(Expect0, Result0),
-
-        {ok, Rows1} = run_query(Db, [
-            {end_key, <<"b">>}, {end_key_docid, <<"11">>},
-            {inclusive_end, false}
-        ]),
-        Result1 = lists:last(Rows1),
-        Expect1 = {row, [{id,<<"10">>}, {key,<<"b">>}, {value,0}]},
-        ?assertEqual(Expect1, Result1)
-    end).
-
-
-make_docs() ->
-    {Docs, _} = lists:foldl(fun(V, {Docs0, Count}) ->
-        Doc = couch_doc:from_json_obj({[
-            {<<"_id">>, list_to_binary(integer_to_list(Count))},
-            {<<"foo">>, V}
-        ]}),
-        {[Doc | Docs0], Count+1}
-    end, {[], 0}, ?VALUES),
-    Docs.
-
-rows() ->
-    {Rows, _} = lists:foldl(fun(V, {Rows0, Count}) ->
-        Id = list_to_binary(integer_to_list(Count)),
-        Row = {row, [{id, Id}, {key, V}, {value, 0}]},
-        {[Row | Rows0], Count+1}
-    end, {[], 0}, ?VALUES),
-    lists:reverse(Rows).
-
-run_query(Db, Opts) ->
-    couch_mrview:query_view(Db, <<"_design/bar">>, <<"zing">>, Opts).

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/d6aa4147/src/couch_mrview/test/couch_mrview_compact_tests.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview/test/couch_mrview_compact_tests.erl b/src/couch_mrview/test/couch_mrview_compact_tests.erl
deleted file mode 100644
index 62d0362..0000000
--- a/src/couch_mrview/test/couch_mrview_compact_tests.erl
+++ /dev/null
@@ -1,101 +0,0 @@
-% 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_compact_tests).
-
--include("../../../test/couchdb/couch_eunit.hrl").
--include_lib("couchdb/couch_db.hrl").
-
--define(ADMIN_USER, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}).
--define(TIMEOUT, 1000).
-
-
-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(), map, 1000),
-    Db.
-
-teardown(Db) ->
-    couch_db:close(Db),
-    couch_server:delete(Db#db.name, [?ADMIN_USER]),
-    ok.
-
-
-compaction_test_() ->
-    {
-        "Compaction tests",
-        {
-            setup,
-            fun start/0, fun stop/1,
-            {
-                foreach,
-                fun setup/0, fun teardown/1,
-                [
-                    fun should_swap/1
-                ]
-            }
-        }
-    }.
-
-
-should_swap(Db) ->
-    ?_test(begin
-        couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>),
-        {ok, QPid} = start_query(Db),
-        {ok, MonRef} = couch_mrview:compact(Db, <<"_design/bar">>, [monitor]),
-        receive
-            {'DOWN', MonRef, process, _, _} -> ok
-        after ?TIMEOUT ->
-            erlang:error(
-                {assertion_failed,
-                 [{module, ?MODULE}, {line, ?LINE},
-                  {reason, "compaction failed"}]})
-        end,
-        QPid ! {self(), continue},
-        receive
-            {QPid, Count} ->
-                ?assertEqual(1000, Count)
-        after ?TIMEOUT ->
-            erlang:error(
-                {assertion_failed,
-                 [{module, ?MODULE}, {line, ?LINE},
-                  {reason, "query failed"}]})
-        end
-    end).
-
-
-start_query(Db) ->
-    Self = self(),
-    Pid = spawn(fun() ->
-        CB = fun
-            (_, wait) -> receive {Self, continue} -> {ok, 0} end;
-            ({row, _}, Count) -> {ok, Count+1};
-            (_, Count) -> {ok, Count}
-        end,
-        {ok, Result} =
-        couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>, [], CB, wait),
-        Self ! {self(), Result}
-    end),
-    {ok, Pid}.

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/d6aa4147/src/couch_mrview/test/couch_mrview_index_info_tests.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview/test/couch_mrview_index_info_tests.erl b/src/couch_mrview/test/couch_mrview_index_info_tests.erl
deleted file mode 100644
index 0867a72..0000000
--- a/src/couch_mrview/test/couch_mrview_index_info_tests.erl
+++ /dev/null
@@ -1,87 +0,0 @@
-% 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_index_info_tests).
-
--include("../../../test/couchdb/couch_eunit.hrl").
--include_lib("couchdb/couch_db.hrl").
-
--define(ADMIN_USER, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}).
--define(TIMEOUT, 1000).
-
-
-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(), map),
-    couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>),
-    {ok, Info} = couch_mrview:get_info(Db, <<"_design/bar">>),
-    {Db, Info}.
-
-teardown({Db, _}) ->
-    couch_db:close(Db),
-    couch_server:delete(Db#db.name, [?ADMIN_USER]),
-    ok.
-
-
-view_info_test_() ->
-    {
-        "Views index tests",
-        {
-            setup,
-            fun start/0, fun stop/1,
-            {
-                foreach,
-                fun setup/0, fun teardown/1,
-                [
-                    fun should_get_property/1
-                ]
-            }
-        }
-    }.
-
-
-should_get_property({_, Info}) ->
-    InfoProps = [
-        {signature, <<"276df562b152b3c4e5d34024f62672ed">>},
-        {language, <<"javascript">>},
-        {disk_size, 314},
-        {data_size, 263},
-        {update_seq, 11},
-        {purge_seq, 0},
-        {updater_running, false},
-        {compact_running, false},
-        {waiting_clients, 0}
-    ],
-    [
-        {atom_to_list(Key), ?_assertEqual(Val, getval(Key, Info))}
-        || {Key, Val} <- InfoProps
-    ].
-
-
-getval(Key, PL) ->
-    {value, {Key, Val}} = lists:keysearch(Key, 1, PL),
-    Val.
-
-

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/d6aa4147/src/couch_mrview/test/couch_mrview_map_views_tests.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview/test/couch_mrview_map_views_tests.erl b/src/couch_mrview/test/couch_mrview_map_views_tests.erl
deleted file mode 100644
index c09490e..0000000
--- a/src/couch_mrview/test/couch_mrview_map_views_tests.erl
+++ /dev/null
@@ -1,138 +0,0 @@
-% 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_map_views_tests).
-
--include("../../../test/couchdb/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(), map),
-    Db.
-
-teardown(Db) ->
-    couch_db:close(Db),
-    couch_server:delete(Db#db.name, [?ADMIN_USER]),
-    ok.
-
-
-map_views_test_() ->
-    {
-        "Map views",
-        {
-            setup,
-            fun start/0, fun stop/1,
-            {
-                foreach,
-                fun setup/0, fun teardown/1,
-                [
-                    fun should_map/1,
-                    fun should_map_with_range/1,
-                    fun should_map_with_limit_and_skip/1,
-                    fun should_map_with_include_docs/1,
-                    fun should_map_empty_views/1
-                ]
-            }
-        }
-    }.
-
-
-should_map(Db) ->
-    Result = run_query(Db, []),
-    Expect = {ok, [
-        {meta, [{total, 10}, {offset, 0}]},
-        {row, [{id, <<"1">>}, {key, 1}, {value, 1}]},
-        {row, [{id, <<"2">>}, {key, 2}, {value, 2}]},
-        {row, [{id, <<"3">>}, {key, 3}, {value, 3}]},
-        {row, [{id, <<"4">>}, {key, 4}, {value, 4}]},
-        {row, [{id, <<"5">>}, {key, 5}, {value, 5}]},
-        {row, [{id, <<"6">>}, {key, 6}, {value, 6}]},
-        {row, [{id, <<"7">>}, {key, 7}, {value, 7}]},
-        {row, [{id, <<"8">>}, {key, 8}, {value, 8}]},
-        {row, [{id, <<"9">>}, {key, 9}, {value, 9}]},
-        {row, [{id, <<"10">>}, {key, 10}, {value, 10}]}
-    ]},
-    ?_assertEqual(Expect, Result).
-
-should_map_with_range(Db) ->
-    Result = run_query(Db, [
-        {direction, rev},
-        {start_key, 5}, {end_key, 3},
-        {inclusive_end, true}
-    ]),
-    Expect = {ok, [
-        {meta, [{total, 10}, {offset, 5}]},
-        {row, [{id, <<"5">>}, {key, 5}, {value, 5}]},
-        {row, [{id, <<"4">>}, {key, 4}, {value, 4}]},
-        {row, [{id, <<"3">>}, {key, 3}, {value, 3}]}
-    ]},
-    ?_assertEqual(Expect, Result).
-
-should_map_with_limit_and_skip(Db) ->
-    Result = run_query(Db, [
-        {start_key, 2},
-        {limit, 3},
-        {skip, 3}
-    ]),
-    Expect = {ok, [
-        {meta, [{total, 10}, {offset, 4}]},
-        {row, [{id, <<"5">>}, {key, 5}, {value, 5}]},
-        {row, [{id, <<"6">>}, {key, 6}, {value, 6}]},
-        {row, [{id, <<"7">>}, {key, 7}, {value, 7}]}
-    ]},
-    ?_assertEqual(Expect, Result).
-
-should_map_with_include_docs(Db) ->
-    Result = run_query(Db, [
-        {start_key, 8},
-        {end_key, 8},
-        {include_docs, true}
-    ]),
-    Doc = {[
-        {<<"_id">>,<<"8">>},
-        {<<"_rev">>, <<"1-55b9a29311341e07ec0a7ca13bc1b59f">>},
-        {<<"val">>,8}
-    ]},
-    Expect = {ok, [
-        {meta, [{total, 10}, {offset, 7}]},
-        {row, [{id, <<"8">>}, {key, 8}, {value, 8}, {doc, Doc}]}
-    ]},
-    ?_assertEqual(Expect, Result).
-
-should_map_empty_views(Db) ->
-    Result = couch_mrview:query_view(Db, <<"_design/bar">>, <<"bing">>),
-    Expect = {ok, [
-        {meta, [{total, 0}, {offset, 0}]}
-    ]},
-    ?_assertEqual(Expect, Result).
-
-
-run_query(Db, Opts) ->
-    couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>, Opts).

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/d6aa4147/src/couch_mrview/test/couch_mrview_modules_load_tests.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview/test/couch_mrview_modules_load_tests.erl b/src/couch_mrview/test/couch_mrview_modules_load_tests.erl
deleted file mode 100644
index a6f752a..0000000
--- a/src/couch_mrview/test/couch_mrview_modules_load_tests.erl
+++ /dev/null
@@ -1,37 +0,0 @@
-% 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_modules_load_tests).
-
--include("../../../test/couchdb/couch_eunit.hrl").
-
-
-modules_load_test_() ->
-    {
-        "Verify that all modules loads",
-        should_load_modules()
-    }.
-
-
-should_load_modules() ->
-    Modules = [
-        couch_mrview,
-        couch_mrview_compactor,
-        couch_mrview_http,
-        couch_mrview_index,
-        couch_mrview_updater,
-        couch_mrview_util
-    ],
-    [should_load_module(Mod) || Mod <- Modules].
-
-should_load_module(Mod) ->
-    {atom_to_list(Mod), ?_assertMatch({module, _}, code:load_file(Mod))}.

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/d6aa4147/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
deleted file mode 100644
index 59333e8..0000000
--- a/src/couch_mrview/test/couch_mrview_red_views_tests.erl
+++ /dev/null
@@ -1,110 +0,0 @@
-% 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("../../../test/couchdb/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) ->
-    couch_db:close(Db),
-    couch_server:delete(Db#db.name, [?ADMIN_USER]),
-    ok.
-
-
-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).

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/d6aa4147/test/couch_mrview_all_docs_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_all_docs_tests.erl b/test/couch_mrview_all_docs_tests.erl
new file mode 100644
index 0000000..6d73c68
--- /dev/null
+++ b/test/couch_mrview_all_docs_tests.erl
@@ -0,0 +1,154 @@
+% 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_all_docs_tests).
+
+-include("../../../test/couchdb/couch_eunit.hrl").
+-include_lib("couchdb/couch_db.hrl").
+
+-define(ADMIN_USER, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}).
+-define(TIMEOUT, 1000).
+
+
+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(), map),
+    Db.
+
+teardown(Db) ->
+    couch_db:close(Db),
+    couch_server:delete(Db#db.name, [?ADMIN_USER]),
+    ok.
+
+
+all_docs_test_() ->
+    {
+        "_all_docs view tests",
+        {
+            setup,
+            fun start/0, fun stop/1,
+            {
+                foreach,
+                fun setup/0, fun teardown/1,
+                [
+                    fun should_query/1,
+                    fun should_query_with_range/1,
+                    fun should_query_with_range_rev/1,
+                    fun should_query_with_limit_and_skip/1,
+                    fun should_query_with_include_docs/1,
+                    fun should_query_empty_views/1
+                ]
+            }
+        }
+    }.
+
+
+should_query(Db) ->
+    Result = run_query(Db, []),
+    Expect = {ok, [
+        {meta, [{total, 11}, {offset, 0}]},
+        mk_row(<<"1">>, <<"1-08d53a5760b95fce6df2e2c5b008be39">>),
+        mk_row(<<"10">>, <<"1-a05b6ea2bc0243949f103d5b4f15f71e">>),
+        mk_row(<<"2">>, <<"1-b57c77a9e6f7574ca6469f0d6dcd78bb">>),
+        mk_row(<<"3">>, <<"1-7fbf84d56f8017880974402d60f5acd6">>),
+        mk_row(<<"4">>, <<"1-fcaf5852c08ffb239ac8ce16c409f253">>),
+        mk_row(<<"5">>, <<"1-aaac5d460fd40f9286e57b9bf12e23d2">>),
+        mk_row(<<"6">>, <<"1-aca21c2e7bc5f8951424fcfc5d1209d8">>),
+        mk_row(<<"7">>, <<"1-4374aeec17590d82f16e70f318116ad9">>),
+        mk_row(<<"8">>, <<"1-55b9a29311341e07ec0a7ca13bc1b59f">>),
+        mk_row(<<"9">>, <<"1-558c8487d9aee25399a91b5d31d90fe2">>),
+        mk_row(<<"_design/bar">>, <<"1-a44e1dd1994a7717bf89c894ebd1f081">>)
+    ]},
+    ?_assertEqual(Expect, Result).
+
+should_query_with_range(Db) ->
+    Result = run_query(Db, [{start_key, <<"3">>}, {end_key, <<"5">>}]),
+    Expect = {ok, [
+        {meta, [{total, 11}, {offset, 3}]},
+        mk_row(<<"3">>, <<"1-7fbf84d56f8017880974402d60f5acd6">>),
+        mk_row(<<"4">>, <<"1-fcaf5852c08ffb239ac8ce16c409f253">>),
+        mk_row(<<"5">>, <<"1-aaac5d460fd40f9286e57b9bf12e23d2">>)
+    ]},
+    ?_assertEqual(Expect, Result).
+
+should_query_with_range_rev(Db) ->
+    Result = run_query(Db, [
+        {direction, rev},
+        {start_key, <<"5">>}, {end_key, <<"3">>},
+        {inclusive_end, true}
+    ]),
+    Expect = {ok, [
+        {meta, [{total, 11}, {offset, 5}]},
+        mk_row(<<"5">>, <<"1-aaac5d460fd40f9286e57b9bf12e23d2">>),
+        mk_row(<<"4">>, <<"1-fcaf5852c08ffb239ac8ce16c409f253">>),
+        mk_row(<<"3">>, <<"1-7fbf84d56f8017880974402d60f5acd6">>)
+    ]},
+    ?_assertEqual(Expect, Result).
+
+should_query_with_limit_and_skip(Db) ->
+    Result = run_query(Db, [
+        {start_key, <<"2">>},
+        {limit, 3},
+        {skip, 3}
+    ]),
+    Expect = {ok, [
+        {meta, [{total, 11}, {offset, 5}]},
+        mk_row(<<"5">>, <<"1-aaac5d460fd40f9286e57b9bf12e23d2">>),
+        mk_row(<<"6">>, <<"1-aca21c2e7bc5f8951424fcfc5d1209d8">>),
+        mk_row(<<"7">>, <<"1-4374aeec17590d82f16e70f318116ad9">>)
+    ]},
+    ?_assertEqual(Expect, Result).
+
+should_query_with_include_docs(Db) ->
+    Result = run_query(Db, [
+        {start_key, <<"8">>},
+        {end_key, <<"8">>},
+        {include_docs, true}
+    ]),
+    Doc = {[
+        {<<"_id">>,<<"8">>},
+        {<<"_rev">>, <<"1-55b9a29311341e07ec0a7ca13bc1b59f">>},
+        {<<"val">>, 8}
+    ]},
+    Val = {[{rev, <<"1-55b9a29311341e07ec0a7ca13bc1b59f">>}]},
+    Expect = {ok, [
+        {meta, [{total, 11}, {offset, 8}]},
+        {row, [{id, <<"8">>}, {key, <<"8">>}, {value, Val}, {doc, Doc}]}
+    ]},
+    ?_assertEqual(Expect, Result).
+
+should_query_empty_views(Db) ->
+    Result = couch_mrview:query_view(Db, <<"_design/bar">>, <<"bing">>),
+    Expect = {ok, [
+        {meta, [{total, 0}, {offset, 0}]}
+    ]},
+    ?_assertEqual(Expect, Result).
+
+
+mk_row(Id, Rev) ->
+    {row, [{id, Id}, {key, Id}, {value, {[{rev, Rev}]}}]}.
+
+run_query(Db, Opts) ->
+    couch_mrview:query_all_docs(Db, Opts).

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/d6aa4147/test/couch_mrview_collation_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_collation_tests.erl b/test/couch_mrview_collation_tests.erl
new file mode 100644
index 0000000..485fd2d
--- /dev/null
+++ b/test/couch_mrview_collation_tests.erl
@@ -0,0 +1,202 @@
+% 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_collation_tests).
+
+-include("../../../test/couchdb/couch_eunit.hrl").
+-include_lib("couchdb/couch_db.hrl").
+
+-define(ADMIN_USER, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}).
+-define(TIMEOUT, 1000).
+-define(VALUES, [
+    null,
+    false,
+    true,
+
+    1,
+    2,
+    3.0,
+    4,
+
+    <<"a">>,
+    <<"A">>,
+    <<"aa">>,
+    <<"b">>,
+    <<"B">>,
+    <<"ba">>,
+    <<"bb">>,
+
+    [<<"a">>],
+    [<<"b">>],
+    [<<"b">>, <<"c">>],
+    [<<"b">>, <<"c">>, <<"a">>],
+    [<<"b">>, <<"d">>],
+    [<<"b">>, <<"d">>, <<"e">>],
+
+    {[{<<"a">>, 1}]},
+    {[{<<"a">>, 2}]},
+    {[{<<"b">>, 1}]},
+    {[{<<"b">>, 2}]},
+    {[{<<"b">>, 2}, {<<"a">>, 1}]},
+    {[{<<"b">>, 2}, {<<"c">>, 2}]}
+]).
+
+
+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, Db1} = couch_mrview_test_util:new_db(?tempdb(), map),
+    {ok, Db2} = couch_mrview_test_util:save_docs(Db1, make_docs()),
+    Db2.
+
+teardown(Db) ->
+    couch_db:close(Db),
+    couch_server:delete(Db#db.name, [?ADMIN_USER]),
+    ok.
+
+
+collation_test_() ->
+    {
+        "Collation tests",
+        {
+            setup,
+            fun start/0, fun stop/1,
+            {
+                foreach,
+                fun setup/0, fun teardown/1,
+                [
+                    fun should_collate_fwd/1,
+                    fun should_collate_rev/1,
+                    fun should_collate_range/1,
+                    fun should_collate_with_inclusive_end_fwd/1,
+                    fun should_collate_with_inclusive_end_rev/1,
+                    fun should_collate_without_inclusive_end_fwd/1,
+                    fun should_collate_without_inclusive_end_rev/1,
+                    fun should_collate_with_endkey_docid/1
+                ]
+            }
+        }
+    }.
+
+
+should_collate_fwd(Db) ->
+    {ok, Results} = run_query(Db, []),
+    Expect = [{meta, [{total, 26}, {offset, 0}]}] ++ rows(),
+    %% cannot use _assertEqual since mrview converts
+    %% value 3.0 to 3 making assertion fail
+    ?_assert(Expect == Results).
+
+should_collate_rev(Db) ->
+    {ok, Results} = run_query(Db, [{direction, rev}]),
+    Expect = [{meta, [{total, 26}, {offset, 0}]}] ++ lists:reverse(rows()),
+    %% cannot use _assertEqual since mrview converts
+    %% value 3.0 to 3 making assertion fail
+    ?_assert(Expect == Results).
+
+should_collate_range(Db) ->
+    ?_assertNot(
+        begin
+            {_, Error} = lists:foldl(fun(V, {Count, Error}) ->
+                {ok, Results} = run_query(Db, [{start_key, V}, {end_key, V}]),
+                Id = list_to_binary(integer_to_list(Count)),
+                Expect = [
+                    {meta, [{total, 26}, {offset, Count}]},
+                    {row, [{id, Id}, {key, V}, {value, 0}]}
+                ],
+                case Results == Expect of
+                    true -> {Count+1, Error};
+                    _ -> {Count+1, true}
+                end
+            end, {0, false}, ?VALUES),
+            Error
+        end).
+
+should_collate_with_inclusive_end_fwd(Db) ->
+    Opts = [{end_key, <<"b">>}, {inclusive_end, true}],
+    {ok, Rows0} = run_query(Db, Opts),
+    LastRow = lists:last(Rows0),
+    Expect = {row, [{id,<<"10">>}, {key,<<"b">>}, {value,0}]},
+    ?_assertEqual(Expect, LastRow).
+
+should_collate_with_inclusive_end_rev(Db) ->
+    Opts = [{end_key, <<"b">>}, {inclusive_end, true}, {direction, rev}],
+    {ok, Rows} = run_query(Db, Opts),
+    LastRow = lists:last(Rows),
+    Expect = {row, [{id,<<"10">>}, {key,<<"b">>}, {value,0}]},
+    ?_assertEqual(Expect, LastRow).
+
+should_collate_without_inclusive_end_fwd(Db) ->
+    Opts = [{end_key, <<"b">>}, {inclusive_end, false}],
+    {ok, Rows0} = run_query(Db, Opts),
+    LastRow = lists:last(Rows0),
+    Expect = {row, [{id,<<"9">>}, {key,<<"aa">>}, {value,0}]},
+    ?_assertEqual(Expect, LastRow).
+
+should_collate_without_inclusive_end_rev(Db) ->
+    Opts = [{end_key, <<"b">>}, {inclusive_end, false}, {direction, rev}],
+    {ok, Rows} = run_query(Db, Opts),
+    LastRow = lists:last(Rows),
+    Expect = {row, [{id,<<"11">>}, {key,<<"B">>}, {value,0}]},
+    ?_assertEqual(Expect, LastRow).
+
+should_collate_with_endkey_docid(Db) ->
+    ?_test(begin
+        {ok, Rows0} = run_query(Db, [
+            {end_key, <<"b">>}, {end_key_docid, <<"10">>},
+            {inclusive_end, false}
+        ]),
+        Result0 = lists:last(Rows0),
+        Expect0 = {row, [{id,<<"9">>}, {key,<<"aa">>}, {value,0}]},
+        ?assertEqual(Expect0, Result0),
+
+        {ok, Rows1} = run_query(Db, [
+            {end_key, <<"b">>}, {end_key_docid, <<"11">>},
+            {inclusive_end, false}
+        ]),
+        Result1 = lists:last(Rows1),
+        Expect1 = {row, [{id,<<"10">>}, {key,<<"b">>}, {value,0}]},
+        ?assertEqual(Expect1, Result1)
+    end).
+
+
+make_docs() ->
+    {Docs, _} = lists:foldl(fun(V, {Docs0, Count}) ->
+        Doc = couch_doc:from_json_obj({[
+            {<<"_id">>, list_to_binary(integer_to_list(Count))},
+            {<<"foo">>, V}
+        ]}),
+        {[Doc | Docs0], Count+1}
+    end, {[], 0}, ?VALUES),
+    Docs.
+
+rows() ->
+    {Rows, _} = lists:foldl(fun(V, {Rows0, Count}) ->
+        Id = list_to_binary(integer_to_list(Count)),
+        Row = {row, [{id, Id}, {key, V}, {value, 0}]},
+        {[Row | Rows0], Count+1}
+    end, {[], 0}, ?VALUES),
+    lists:reverse(Rows).
+
+run_query(Db, Opts) ->
+    couch_mrview:query_view(Db, <<"_design/bar">>, <<"zing">>, Opts).

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/d6aa4147/test/couch_mrview_compact_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_compact_tests.erl b/test/couch_mrview_compact_tests.erl
new file mode 100644
index 0000000..62d0362
--- /dev/null
+++ b/test/couch_mrview_compact_tests.erl
@@ -0,0 +1,101 @@
+% 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_compact_tests).
+
+-include("../../../test/couchdb/couch_eunit.hrl").
+-include_lib("couchdb/couch_db.hrl").
+
+-define(ADMIN_USER, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}).
+-define(TIMEOUT, 1000).
+
+
+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(), map, 1000),
+    Db.
+
+teardown(Db) ->
+    couch_db:close(Db),
+    couch_server:delete(Db#db.name, [?ADMIN_USER]),
+    ok.
+
+
+compaction_test_() ->
+    {
+        "Compaction tests",
+        {
+            setup,
+            fun start/0, fun stop/1,
+            {
+                foreach,
+                fun setup/0, fun teardown/1,
+                [
+                    fun should_swap/1
+                ]
+            }
+        }
+    }.
+
+
+should_swap(Db) ->
+    ?_test(begin
+        couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>),
+        {ok, QPid} = start_query(Db),
+        {ok, MonRef} = couch_mrview:compact(Db, <<"_design/bar">>, [monitor]),
+        receive
+            {'DOWN', MonRef, process, _, _} -> ok
+        after ?TIMEOUT ->
+            erlang:error(
+                {assertion_failed,
+                 [{module, ?MODULE}, {line, ?LINE},
+                  {reason, "compaction failed"}]})
+        end,
+        QPid ! {self(), continue},
+        receive
+            {QPid, Count} ->
+                ?assertEqual(1000, Count)
+        after ?TIMEOUT ->
+            erlang:error(
+                {assertion_failed,
+                 [{module, ?MODULE}, {line, ?LINE},
+                  {reason, "query failed"}]})
+        end
+    end).
+
+
+start_query(Db) ->
+    Self = self(),
+    Pid = spawn(fun() ->
+        CB = fun
+            (_, wait) -> receive {Self, continue} -> {ok, 0} end;
+            ({row, _}, Count) -> {ok, Count+1};
+            (_, Count) -> {ok, Count}
+        end,
+        {ok, Result} =
+        couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>, [], CB, wait),
+        Self ! {self(), Result}
+    end),
+    {ok, Pid}.

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/d6aa4147/test/couch_mrview_index_info_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_index_info_tests.erl b/test/couch_mrview_index_info_tests.erl
new file mode 100644
index 0000000..0867a72
--- /dev/null
+++ b/test/couch_mrview_index_info_tests.erl
@@ -0,0 +1,87 @@
+% 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_index_info_tests).
+
+-include("../../../test/couchdb/couch_eunit.hrl").
+-include_lib("couchdb/couch_db.hrl").
+
+-define(ADMIN_USER, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}).
+-define(TIMEOUT, 1000).
+
+
+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(), map),
+    couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>),
+    {ok, Info} = couch_mrview:get_info(Db, <<"_design/bar">>),
+    {Db, Info}.
+
+teardown({Db, _}) ->
+    couch_db:close(Db),
+    couch_server:delete(Db#db.name, [?ADMIN_USER]),
+    ok.
+
+
+view_info_test_() ->
+    {
+        "Views index tests",
+        {
+            setup,
+            fun start/0, fun stop/1,
+            {
+                foreach,
+                fun setup/0, fun teardown/1,
+                [
+                    fun should_get_property/1
+                ]
+            }
+        }
+    }.
+
+
+should_get_property({_, Info}) ->
+    InfoProps = [
+        {signature, <<"276df562b152b3c4e5d34024f62672ed">>},
+        {language, <<"javascript">>},
+        {disk_size, 314},
+        {data_size, 263},
+        {update_seq, 11},
+        {purge_seq, 0},
+        {updater_running, false},
+        {compact_running, false},
+        {waiting_clients, 0}
+    ],
+    [
+        {atom_to_list(Key), ?_assertEqual(Val, getval(Key, Info))}
+        || {Key, Val} <- InfoProps
+    ].
+
+
+getval(Key, PL) ->
+    {value, {Key, Val}} = lists:keysearch(Key, 1, PL),
+    Val.
+
+

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/d6aa4147/test/couch_mrview_map_views_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_map_views_tests.erl b/test/couch_mrview_map_views_tests.erl
new file mode 100644
index 0000000..c09490e
--- /dev/null
+++ b/test/couch_mrview_map_views_tests.erl
@@ -0,0 +1,138 @@
+% 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_map_views_tests).
+
+-include("../../../test/couchdb/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(), map),
+    Db.
+
+teardown(Db) ->
+    couch_db:close(Db),
+    couch_server:delete(Db#db.name, [?ADMIN_USER]),
+    ok.
+
+
+map_views_test_() ->
+    {
+        "Map views",
+        {
+            setup,
+            fun start/0, fun stop/1,
+            {
+                foreach,
+                fun setup/0, fun teardown/1,
+                [
+                    fun should_map/1,
+                    fun should_map_with_range/1,
+                    fun should_map_with_limit_and_skip/1,
+                    fun should_map_with_include_docs/1,
+                    fun should_map_empty_views/1
+                ]
+            }
+        }
+    }.
+
+
+should_map(Db) ->
+    Result = run_query(Db, []),
+    Expect = {ok, [
+        {meta, [{total, 10}, {offset, 0}]},
+        {row, [{id, <<"1">>}, {key, 1}, {value, 1}]},
+        {row, [{id, <<"2">>}, {key, 2}, {value, 2}]},
+        {row, [{id, <<"3">>}, {key, 3}, {value, 3}]},
+        {row, [{id, <<"4">>}, {key, 4}, {value, 4}]},
+        {row, [{id, <<"5">>}, {key, 5}, {value, 5}]},
+        {row, [{id, <<"6">>}, {key, 6}, {value, 6}]},
+        {row, [{id, <<"7">>}, {key, 7}, {value, 7}]},
+        {row, [{id, <<"8">>}, {key, 8}, {value, 8}]},
+        {row, [{id, <<"9">>}, {key, 9}, {value, 9}]},
+        {row, [{id, <<"10">>}, {key, 10}, {value, 10}]}
+    ]},
+    ?_assertEqual(Expect, Result).
+
+should_map_with_range(Db) ->
+    Result = run_query(Db, [
+        {direction, rev},
+        {start_key, 5}, {end_key, 3},
+        {inclusive_end, true}
+    ]),
+    Expect = {ok, [
+        {meta, [{total, 10}, {offset, 5}]},
+        {row, [{id, <<"5">>}, {key, 5}, {value, 5}]},
+        {row, [{id, <<"4">>}, {key, 4}, {value, 4}]},
+        {row, [{id, <<"3">>}, {key, 3}, {value, 3}]}
+    ]},
+    ?_assertEqual(Expect, Result).
+
+should_map_with_limit_and_skip(Db) ->
+    Result = run_query(Db, [
+        {start_key, 2},
+        {limit, 3},
+        {skip, 3}
+    ]),
+    Expect = {ok, [
+        {meta, [{total, 10}, {offset, 4}]},
+        {row, [{id, <<"5">>}, {key, 5}, {value, 5}]},
+        {row, [{id, <<"6">>}, {key, 6}, {value, 6}]},
+        {row, [{id, <<"7">>}, {key, 7}, {value, 7}]}
+    ]},
+    ?_assertEqual(Expect, Result).
+
+should_map_with_include_docs(Db) ->
+    Result = run_query(Db, [
+        {start_key, 8},
+        {end_key, 8},
+        {include_docs, true}
+    ]),
+    Doc = {[
+        {<<"_id">>,<<"8">>},
+        {<<"_rev">>, <<"1-55b9a29311341e07ec0a7ca13bc1b59f">>},
+        {<<"val">>,8}
+    ]},
+    Expect = {ok, [
+        {meta, [{total, 10}, {offset, 7}]},
+        {row, [{id, <<"8">>}, {key, 8}, {value, 8}, {doc, Doc}]}
+    ]},
+    ?_assertEqual(Expect, Result).
+
+should_map_empty_views(Db) ->
+    Result = couch_mrview:query_view(Db, <<"_design/bar">>, <<"bing">>),
+    Expect = {ok, [
+        {meta, [{total, 0}, {offset, 0}]}
+    ]},
+    ?_assertEqual(Expect, Result).
+
+
+run_query(Db, Opts) ->
+    couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>, Opts).

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/d6aa4147/test/couch_mrview_modules_load_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_modules_load_tests.erl b/test/couch_mrview_modules_load_tests.erl
new file mode 100644
index 0000000..a6f752a
--- /dev/null
+++ b/test/couch_mrview_modules_load_tests.erl
@@ -0,0 +1,37 @@
+% 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_modules_load_tests).
+
+-include("../../../test/couchdb/couch_eunit.hrl").
+
+
+modules_load_test_() ->
+    {
+        "Verify that all modules loads",
+        should_load_modules()
+    }.
+
+
+should_load_modules() ->
+    Modules = [
+        couch_mrview,
+        couch_mrview_compactor,
+        couch_mrview_http,
+        couch_mrview_index,
+        couch_mrview_updater,
+        couch_mrview_util
+    ],
+    [should_load_module(Mod) || Mod <- Modules].
+
+should_load_module(Mod) ->
+    {atom_to_list(Mod), ?_assertMatch({module, _}, code:load_file(Mod))}.

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/d6aa4147/test/couch_mrview_red_views_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_red_views_tests.erl b/test/couch_mrview_red_views_tests.erl
new file mode 100644
index 0000000..59333e8
--- /dev/null
+++ b/test/couch_mrview_red_views_tests.erl
@@ -0,0 +1,110 @@
+% 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("../../../test/couchdb/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) ->
+    couch_db:close(Db),
+    couch_server:delete(Db#db.name, [?ADMIN_USER]),
+    ok.
+
+
+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).


[10/14] couch-mrview commit: updated refs/heads/master to d548785

Posted by rn...@apache.org.
Update include paths


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/b4e490fb
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/b4e490fb
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/b4e490fb

Branch: refs/heads/master
Commit: b4e490fbb0b53a512c99528285d0745620839c8d
Parents: d6aa414
Author: Russell Branca <ch...@apache.org>
Authored: Wed Aug 27 17:13:46 2014 -0700
Committer: Russell Branca <ch...@apache.org>
Committed: Thu Aug 28 10:27:05 2014 -0700

----------------------------------------------------------------------
 test/couch_mrview_all_docs_tests.erl     | 4 ++--
 test/couch_mrview_collation_tests.erl    | 4 ++--
 test/couch_mrview_compact_tests.erl      | 4 ++--
 test/couch_mrview_index_info_tests.erl   | 4 ++--
 test/couch_mrview_map_views_tests.erl    | 4 ++--
 test/couch_mrview_modules_load_tests.erl | 2 +-
 test/couch_mrview_red_views_tests.erl    | 4 ++--
 7 files changed, 13 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/b4e490fb/test/couch_mrview_all_docs_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_all_docs_tests.erl b/test/couch_mrview_all_docs_tests.erl
index 6d73c68..c7f24bd 100644
--- a/test/couch_mrview_all_docs_tests.erl
+++ b/test/couch_mrview_all_docs_tests.erl
@@ -12,8 +12,8 @@
 
 -module(couch_mrview_all_docs_tests).
 
--include("../../../test/couchdb/couch_eunit.hrl").
--include_lib("couchdb/couch_db.hrl").
+-include_lib("couch/include/couch_eunit.hrl").
+-include_lib("couch/include/couch_db.hrl").
 
 -define(ADMIN_USER, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}).
 -define(TIMEOUT, 1000).

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/b4e490fb/test/couch_mrview_collation_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_collation_tests.erl b/test/couch_mrview_collation_tests.erl
index 485fd2d..cd017b2 100644
--- a/test/couch_mrview_collation_tests.erl
+++ b/test/couch_mrview_collation_tests.erl
@@ -12,8 +12,8 @@
 
 -module(couch_mrview_collation_tests).
 
--include("../../../test/couchdb/couch_eunit.hrl").
--include_lib("couchdb/couch_db.hrl").
+-include_lib("couch/include/couch_eunit.hrl").
+-include_lib("couch/include/couch_db.hrl").
 
 -define(ADMIN_USER, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}).
 -define(TIMEOUT, 1000).

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/b4e490fb/test/couch_mrview_compact_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_compact_tests.erl b/test/couch_mrview_compact_tests.erl
index 62d0362..3c51138 100644
--- a/test/couch_mrview_compact_tests.erl
+++ b/test/couch_mrview_compact_tests.erl
@@ -12,8 +12,8 @@
 
 -module(couch_mrview_compact_tests).
 
--include("../../../test/couchdb/couch_eunit.hrl").
--include_lib("couchdb/couch_db.hrl").
+-include_lib("couch/include/couch_eunit.hrl").
+-include_lib("couch/include/couch_db.hrl").
 
 -define(ADMIN_USER, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}).
 -define(TIMEOUT, 1000).

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/b4e490fb/test/couch_mrview_index_info_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_index_info_tests.erl b/test/couch_mrview_index_info_tests.erl
index 0867a72..aebc443 100644
--- a/test/couch_mrview_index_info_tests.erl
+++ b/test/couch_mrview_index_info_tests.erl
@@ -12,8 +12,8 @@
 
 -module(couch_mrview_index_info_tests).
 
--include("../../../test/couchdb/couch_eunit.hrl").
--include_lib("couchdb/couch_db.hrl").
+-include_lib("couch/include/couch_eunit.hrl").
+-include_lib("couch/include/couch_db.hrl").
 
 -define(ADMIN_USER, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}).
 -define(TIMEOUT, 1000).

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/b4e490fb/test/couch_mrview_map_views_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_map_views_tests.erl b/test/couch_mrview_map_views_tests.erl
index c09490e..62049f9 100644
--- a/test/couch_mrview_map_views_tests.erl
+++ b/test/couch_mrview_map_views_tests.erl
@@ -12,8 +12,8 @@
 
 -module(couch_mrview_map_views_tests).
 
--include("../../../test/couchdb/couch_eunit.hrl").
--include_lib("couchdb/couch_db.hrl").
+-include_lib("couch/include/couch_eunit.hrl").
+-include_lib("couch/include/couch_db.hrl").
 
 -define(TIMEOUT, 1000).
 -define(ADMIN_USER, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}).

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/b4e490fb/test/couch_mrview_modules_load_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_modules_load_tests.erl b/test/couch_mrview_modules_load_tests.erl
index a6f752a..15ce443 100644
--- a/test/couch_mrview_modules_load_tests.erl
+++ b/test/couch_mrview_modules_load_tests.erl
@@ -12,7 +12,7 @@
 
 -module(couch_mrview_modules_load_tests).
 
--include("../../../test/couchdb/couch_eunit.hrl").
+-include_lib("couch/include/couch_eunit.hrl").
 
 
 modules_load_test_() ->

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/b4e490fb/test/couch_mrview_red_views_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_red_views_tests.erl b/test/couch_mrview_red_views_tests.erl
index 59333e8..382963a 100644
--- a/test/couch_mrview_red_views_tests.erl
+++ b/test/couch_mrview_red_views_tests.erl
@@ -12,8 +12,8 @@
 
 -module(couch_mrview_red_views_tests).
 
--include("../../../test/couchdb/couch_eunit.hrl").
--include_lib("couchdb/couch_db.hrl").
+-include_lib("couch/include/couch_eunit.hrl").
+-include_lib("couch/include/couch_db.hrl").
 
 -define(TIMEOUT, 1000).
 -define(ADMIN_USER, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}).


[14/14] couch-mrview commit: updated refs/heads/master to d548785

Posted by rn...@apache.org.
Merge remote-tracking branch 'origin/1963-eunit-bigcouch'


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/d5487852
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/d5487852
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/d5487852

Branch: refs/heads/master
Commit: d5487852a8c5d52bfa4b0e980772b14a145edf78
Parents: 08cbd5a cc9c436
Author: Robert Newson <rn...@apache.org>
Authored: Fri Sep 5 12:49:43 2014 +0100
Committer: Robert Newson <rn...@apache.org>
Committed: Fri Sep 5 12:49:43 2014 +0100

----------------------------------------------------------------------
 src/couch_mrview_test_util.erl           |   6 +-
 test/01-load.t                           |  34 -----
 test/02-map-views.t                      | 120 -----------------
 test/03-red-views.t                      |  78 -----------
 test/04-index-info.t                     |  43 ------
 test/05-collation.t                      | 164 ----------------------
 test/06-all-docs.t                       | 127 -----------------
 test/07-compact-swap.t                   |  57 --------
 test/couch_mrview_all_docs_tests.erl     | 140 +++++++++++++++++++
 test/couch_mrview_collation_tests.erl    | 187 ++++++++++++++++++++++++++
 test/couch_mrview_compact_tests.erl      |  86 ++++++++++++
 test/couch_mrview_index_info_tests.erl   |  75 +++++++++++
 test/couch_mrview_map_views_tests.erl    | 123 +++++++++++++++++
 test/couch_mrview_modules_load_tests.erl |  37 +++++
 test/couch_mrview_red_views_tests.erl    |  95 +++++++++++++
 15 files changed, 746 insertions(+), 626 deletions(-)
----------------------------------------------------------------------



[09/14] couch-mrview commit: updated refs/heads/master to d548785

Posted by rn...@apache.org.
Port couch_mrview/07-compact-swap.t etap test suite to eunit


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/7644769a
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/7644769a
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/7644769a

Branch: refs/heads/master
Commit: 7644769a73acad3ff523cbaba2374d9976242ae6
Parents: 40e770e
Author: Alexander Shorin <kx...@apache.org>
Authored: Thu Jun 12 02:44:30 2014 +0400
Committer: Russell Branca <ch...@apache.org>
Committed: Thu Aug 28 10:27:05 2014 -0700

----------------------------------------------------------------------
 .../test/couch_mrview_compact_tests.erl         | 101 +++++++++++++++++++
 test/07-compact-swap.t                          |  57 -----------
 2 files changed, 101 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/7644769a/src/couch_mrview/test/couch_mrview_compact_tests.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview/test/couch_mrview_compact_tests.erl b/src/couch_mrview/test/couch_mrview_compact_tests.erl
new file mode 100644
index 0000000..62d0362
--- /dev/null
+++ b/src/couch_mrview/test/couch_mrview_compact_tests.erl
@@ -0,0 +1,101 @@
+% 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_compact_tests).
+
+-include("../../../test/couchdb/couch_eunit.hrl").
+-include_lib("couchdb/couch_db.hrl").
+
+-define(ADMIN_USER, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}).
+-define(TIMEOUT, 1000).
+
+
+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(), map, 1000),
+    Db.
+
+teardown(Db) ->
+    couch_db:close(Db),
+    couch_server:delete(Db#db.name, [?ADMIN_USER]),
+    ok.
+
+
+compaction_test_() ->
+    {
+        "Compaction tests",
+        {
+            setup,
+            fun start/0, fun stop/1,
+            {
+                foreach,
+                fun setup/0, fun teardown/1,
+                [
+                    fun should_swap/1
+                ]
+            }
+        }
+    }.
+
+
+should_swap(Db) ->
+    ?_test(begin
+        couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>),
+        {ok, QPid} = start_query(Db),
+        {ok, MonRef} = couch_mrview:compact(Db, <<"_design/bar">>, [monitor]),
+        receive
+            {'DOWN', MonRef, process, _, _} -> ok
+        after ?TIMEOUT ->
+            erlang:error(
+                {assertion_failed,
+                 [{module, ?MODULE}, {line, ?LINE},
+                  {reason, "compaction failed"}]})
+        end,
+        QPid ! {self(), continue},
+        receive
+            {QPid, Count} ->
+                ?assertEqual(1000, Count)
+        after ?TIMEOUT ->
+            erlang:error(
+                {assertion_failed,
+                 [{module, ?MODULE}, {line, ?LINE},
+                  {reason, "query failed"}]})
+        end
+    end).
+
+
+start_query(Db) ->
+    Self = self(),
+    Pid = spawn(fun() ->
+        CB = fun
+            (_, wait) -> receive {Self, continue} -> {ok, 0} end;
+            ({row, _}, Count) -> {ok, Count+1};
+            (_, Count) -> {ok, Count}
+        end,
+        {ok, Result} =
+        couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>, [], CB, wait),
+        Self ! {self(), Result}
+    end),
+    {ok, Pid}.

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/7644769a/test/07-compact-swap.t
----------------------------------------------------------------------
diff --git a/test/07-compact-swap.t b/test/07-compact-swap.t
deleted file mode 100644
index c1fd043..0000000
--- a/test/07-compact-swap.t
+++ /dev/null
@@ -1,57 +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(1, fun() -> test() end).
-
-
-test() ->
-    test_util:start_couch(),
-    {ok, Db} = couch_mrview_test_util:init_db(<<"foo">>, map, 1000),
-    couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>),
-    test_swap(Db),
-    ok.
-
-
-test_swap(Db) ->
-    {ok, QPid} = start_query(Db),    
-    {ok, MonRef} = couch_mrview:compact(Db, <<"_design/bar">>, [monitor]),
-    receive
-        {'DOWN', MonRef, process, _, _} -> ok
-    after 1000 ->
-        throw(compaction_failed)
-    end,
-    QPid ! {self(), continue},
-    receive
-        {QPid, Count} ->
-            etap:is(Count, 1000, "View finished successfully.")
-    after 1000 ->
-        throw("query failed")
-    end.
-
-
-start_query(Db) ->
-    Self = self(),
-    Pid = spawn(fun() ->
-        CB = fun
-            (_, wait) -> receive {Self, continue} -> {ok, 0} end;
-            ({row, _}, Count) -> {ok, Count+1};
-            (_, Count) -> {ok, Count}
-        end,
-        {ok, Result} = 
-        couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>, [], CB, wait),
-        Self ! {self(), Result}
-    end),
-    {ok, Pid}.


[12/14] couch-mrview commit: updated refs/heads/master to d548785

Posted by rn...@apache.org.
Switch to using test_util:{start,stop}_couch


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/1d110e14
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/1d110e14
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/1d110e14

Branch: refs/heads/master
Commit: 1d110e14b99c0292cd09523ccec408e31a1b41e5
Parents: 7857cf8
Author: Russell Branca <ch...@apache.org>
Authored: Wed Aug 27 17:40:00 2014 -0700
Committer: Russell Branca <ch...@apache.org>
Committed: Thu Aug 28 10:27:05 2014 -0700

----------------------------------------------------------------------
 test/couch_mrview_all_docs_tests.erl   | 15 +--------------
 test/couch_mrview_collation_tests.erl  | 16 +---------------
 test/couch_mrview_compact_tests.erl    | 16 +---------------
 test/couch_mrview_index_info_tests.erl | 16 +---------------
 test/couch_mrview_map_views_tests.erl  | 16 +---------------
 test/couch_mrview_red_views_tests.erl  | 16 +---------------
 6 files changed, 6 insertions(+), 89 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/1d110e14/test/couch_mrview_all_docs_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_all_docs_tests.erl b/test/couch_mrview_all_docs_tests.erl
index 0b40587..0f32d59 100644
--- a/test/couch_mrview_all_docs_tests.erl
+++ b/test/couch_mrview_all_docs_tests.erl
@@ -18,19 +18,6 @@
 -define(TIMEOUT, 1000).
 
 
-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(), map),
@@ -47,7 +34,7 @@ all_docs_test_() ->
         "_all_docs view tests",
         {
             setup,
-            fun start/0, fun stop/1,
+            fun test_util:start_couch/0, fun test_util:stop_couch/1,
             {
                 foreach,
                 fun setup/0, fun teardown/1,

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/1d110e14/test/couch_mrview_collation_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_collation_tests.erl b/test/couch_mrview_collation_tests.erl
index ae0d821..2ea6d6b 100644
--- a/test/couch_mrview_collation_tests.erl
+++ b/test/couch_mrview_collation_tests.erl
@@ -50,20 +50,6 @@
 ]).
 
 
-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, Db1} = couch_mrview_test_util:new_db(?tempdb(), map),
     {ok, Db2} = couch_mrview_test_util:save_docs(Db1, make_docs()),
@@ -80,7 +66,7 @@ collation_test_() ->
         "Collation tests",
         {
             setup,
-            fun start/0, fun stop/1,
+            fun test_util:start_couch/0, fun test_util:stop_couch/1,
             {
                 foreach,
                 fun setup/0, fun teardown/1,

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/1d110e14/test/couch_mrview_compact_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_compact_tests.erl b/test/couch_mrview_compact_tests.erl
index 4085d4f..385dc3b 100644
--- a/test/couch_mrview_compact_tests.erl
+++ b/test/couch_mrview_compact_tests.erl
@@ -18,20 +18,6 @@
 -define(TIMEOUT, 1000).
 
 
-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(), map, 1000),
     Db.
@@ -47,7 +33,7 @@ compaction_test_() ->
         "Compaction tests",
         {
             setup,
-            fun start/0, fun stop/1,
+            fun test_util:start_couch/0, fun test_util:stop_couch/1,
             {
                 foreach,
                 fun setup/0, fun teardown/1,

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/1d110e14/test/couch_mrview_index_info_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_index_info_tests.erl b/test/couch_mrview_index_info_tests.erl
index 7afb196..3dd049d 100644
--- a/test/couch_mrview_index_info_tests.erl
+++ b/test/couch_mrview_index_info_tests.erl
@@ -18,20 +18,6 @@
 -define(TIMEOUT, 1000).
 
 
-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(), map),
     couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>),
@@ -49,7 +35,7 @@ view_info_test_() ->
         "Views index tests",
         {
             setup,
-            fun start/0, fun stop/1,
+            fun test_util:start_couch/0, fun test_util:stop_couch/1,
             {
                 foreach,
                 fun setup/0, fun teardown/1,

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/1d110e14/test/couch_mrview_map_views_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_map_views_tests.erl b/test/couch_mrview_map_views_tests.erl
index 3dc373f..fe3b8f4 100644
--- a/test/couch_mrview_map_views_tests.erl
+++ b/test/couch_mrview_map_views_tests.erl
@@ -18,20 +18,6 @@
 -define(TIMEOUT, 1000).
 
 
-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(), map),
     Db.
@@ -47,7 +33,7 @@ map_views_test_() ->
         "Map views",
         {
             setup,
-            fun start/0, fun stop/1,
+            fun test_util:start_couch/0, fun test_util:stop_couch/1,
             {
                 foreach,
                 fun setup/0, fun teardown/1,

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/1d110e14/test/couch_mrview_red_views_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_red_views_tests.erl b/test/couch_mrview_red_views_tests.erl
index 10f0fe3..8c2ff47 100644
--- a/test/couch_mrview_red_views_tests.erl
+++ b/test/couch_mrview_red_views_tests.erl
@@ -18,20 +18,6 @@
 -define(TIMEOUT, 1000).
 
 
-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.
@@ -47,7 +33,7 @@ reduce_views_test_() ->
         "Reduce views",
         {
             setup,
-            fun start/0, fun stop/1,
+            fun test_util:start_couch/0, fun test_util:stop_couch/1,
             {
                 foreach,
                 fun setup/0, fun teardown/1,


[13/14] couch-mrview commit: updated refs/heads/master to d548785

Posted by rn...@apache.org.
Disable problematic tests


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/cc9c4360
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/cc9c4360
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/cc9c4360

Branch: refs/heads/master
Commit: cc9c4360feb092e92cc5c9ac57fee33bd24a85a7
Parents: 0320170
Author: Russell Branca <ch...@apache.org>
Authored: Wed Aug 27 18:27:54 2014 -0700
Committer: Russell Branca <ch...@apache.org>
Committed: Thu Aug 28 10:27:05 2014 -0700

----------------------------------------------------------------------
 test/couch_mrview_index_info_tests.erl | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/cc9c4360/test/couch_mrview_index_info_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_index_info_tests.erl b/test/couch_mrview_index_info_tests.erl
index 3dd049d..3577095 100644
--- a/test/couch_mrview_index_info_tests.erl
+++ b/test/couch_mrview_index_info_tests.erl
@@ -18,6 +18,8 @@
 -define(TIMEOUT, 1000).
 
 
+-ifdef(run_broken_tests).
+
 setup() ->
     {ok, Db} = couch_mrview_test_util:init_db(?tempdb(), map),
     couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>),
@@ -70,3 +72,4 @@ getval(Key, PL) ->
     Val.
 
 
+-endif.


[02/14] couch-mrview commit: updated refs/heads/master to d548785

Posted by rn...@apache.org.
Port couch_mrview/03-red-views.t etap test suite to eunit


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/ae26f148
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/ae26f148
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/ae26f148

Branch: refs/heads/master
Commit: ae26f148ce6f3ae5b28493e88eb542fab2a30a29
Parents: f94401c
Author: Alexander Shorin <kx...@apache.org>
Authored: Wed Jun 11 18:15:41 2014 +0400
Committer: Russell Branca <ch...@apache.org>
Committed: Thu Aug 28 10:27:04 2014 -0700

----------------------------------------------------------------------
 .../test/couch_mrview_red_views_tests.erl       | 110 +++++++++++++++++++
 test/03-red-views.t                             |  78 -------------
 2 files changed, 110 insertions(+), 78 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/ae26f148/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..59333e8
--- /dev/null
+++ b/src/couch_mrview/test/couch_mrview_red_views_tests.erl
@@ -0,0 +1,110 @@
+% 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("../../../test/couchdb/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) ->
+    couch_db:close(Db),
+    couch_server:delete(Db#db.name, [?ADMIN_USER]),
+    ok.
+
+
+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).

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/ae26f148/test/03-red-views.t
----------------------------------------------------------------------
diff --git a/test/03-red-views.t b/test/03-red-views.t
deleted file mode 100644
index 0d11d51..0000000
--- a/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() ->
-    test_util:start_couch(),
-
-    {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).


[08/14] couch-mrview commit: updated refs/heads/master to d548785

Posted by rn...@apache.org.
Admin user again


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/03201704
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/03201704
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/03201704

Branch: refs/heads/master
Commit: 03201704663baa0e7775d28b1edfbdc98693e193
Parents: 1d110e1
Author: Russell Branca <ch...@apache.org>
Authored: Wed Aug 27 18:27:13 2014 -0700
Committer: Russell Branca <ch...@apache.org>
Committed: Thu Aug 28 10:27:05 2014 -0700

----------------------------------------------------------------------
 src/couch_mrview_test_util.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/03201704/src/couch_mrview_test_util.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_test_util.erl b/src/couch_mrview_test_util.erl
index 7599786..40ccf09 100644
--- a/src/couch_mrview_test_util.erl
+++ b/src/couch_mrview_test_util.erl
@@ -30,7 +30,7 @@ init_db(Name, Type, Count) ->
 
 new_db(Name, Type) ->
     couch_server:delete(Name, [?ADMIN_USER]),
-    {ok, Db} = couch_db:create(Name, [{user_ctx, ?ADMIN}]),
+    {ok, Db} = couch_db:create(Name, [?ADMIN_USER]),
     save_docs(Db, [ddoc(Type)]).
 
 


[11/14] couch-mrview commit: updated refs/heads/master to d548785

Posted by rn...@apache.org.
Use ?ADMIN macros from couch_eunit.hrl


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/7857cf8e
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/7857cf8e
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/7857cf8e

Branch: refs/heads/master
Commit: 7857cf8ebbaa717c078c59d9f4604bc31409d494
Parents: b4e490f
Author: Russell Branca <ch...@apache.org>
Authored: Wed Aug 27 17:17:15 2014 -0700
Committer: Russell Branca <ch...@apache.org>
Committed: Thu Aug 28 10:27:05 2014 -0700

----------------------------------------------------------------------
 src/couch_mrview_test_util.erl         | 4 ++--
 test/couch_mrview_all_docs_tests.erl   | 1 -
 test/couch_mrview_collation_tests.erl  | 1 -
 test/couch_mrview_compact_tests.erl    | 1 -
 test/couch_mrview_index_info_tests.erl | 1 -
 test/couch_mrview_map_views_tests.erl  | 1 -
 test/couch_mrview_red_views_tests.erl  | 1 -
 7 files changed, 2 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/7857cf8e/src/couch_mrview_test_util.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_test_util.erl b/src/couch_mrview_test_util.erl
index 4109fd6..7599786 100644
--- a/src/couch_mrview_test_util.erl
+++ b/src/couch_mrview_test_util.erl
@@ -15,7 +15,7 @@
 -compile(export_all).
 
 -include_lib("couch/include/couch_db.hrl").
--define(ADMIN, #user_ctx{roles=[<<"_admin">>]}).
+-include_lib("couch/include/couch_eunit.hrl").
 
 
 init_db(Name, Type) ->
@@ -29,7 +29,7 @@ init_db(Name, Type, Count) ->
 
 
 new_db(Name, Type) ->
-    couch_server:delete(Name, [{user_ctx, ?ADMIN}]),
+    couch_server:delete(Name, [?ADMIN_USER]),
     {ok, Db} = couch_db:create(Name, [{user_ctx, ?ADMIN}]),
     save_docs(Db, [ddoc(Type)]).
 

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/7857cf8e/test/couch_mrview_all_docs_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_all_docs_tests.erl b/test/couch_mrview_all_docs_tests.erl
index c7f24bd..0b40587 100644
--- a/test/couch_mrview_all_docs_tests.erl
+++ b/test/couch_mrview_all_docs_tests.erl
@@ -15,7 +15,6 @@
 -include_lib("couch/include/couch_eunit.hrl").
 -include_lib("couch/include/couch_db.hrl").
 
--define(ADMIN_USER, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}).
 -define(TIMEOUT, 1000).
 
 

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/7857cf8e/test/couch_mrview_collation_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_collation_tests.erl b/test/couch_mrview_collation_tests.erl
index cd017b2..ae0d821 100644
--- a/test/couch_mrview_collation_tests.erl
+++ b/test/couch_mrview_collation_tests.erl
@@ -15,7 +15,6 @@
 -include_lib("couch/include/couch_eunit.hrl").
 -include_lib("couch/include/couch_db.hrl").
 
--define(ADMIN_USER, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}).
 -define(TIMEOUT, 1000).
 -define(VALUES, [
     null,

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/7857cf8e/test/couch_mrview_compact_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_compact_tests.erl b/test/couch_mrview_compact_tests.erl
index 3c51138..4085d4f 100644
--- a/test/couch_mrview_compact_tests.erl
+++ b/test/couch_mrview_compact_tests.erl
@@ -15,7 +15,6 @@
 -include_lib("couch/include/couch_eunit.hrl").
 -include_lib("couch/include/couch_db.hrl").
 
--define(ADMIN_USER, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}).
 -define(TIMEOUT, 1000).
 
 

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/7857cf8e/test/couch_mrview_index_info_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_index_info_tests.erl b/test/couch_mrview_index_info_tests.erl
index aebc443..7afb196 100644
--- a/test/couch_mrview_index_info_tests.erl
+++ b/test/couch_mrview_index_info_tests.erl
@@ -15,7 +15,6 @@
 -include_lib("couch/include/couch_eunit.hrl").
 -include_lib("couch/include/couch_db.hrl").
 
--define(ADMIN_USER, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}).
 -define(TIMEOUT, 1000).
 
 

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/7857cf8e/test/couch_mrview_map_views_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_map_views_tests.erl b/test/couch_mrview_map_views_tests.erl
index 62049f9..3dc373f 100644
--- a/test/couch_mrview_map_views_tests.erl
+++ b/test/couch_mrview_map_views_tests.erl
@@ -16,7 +16,6 @@
 -include_lib("couch/include/couch_db.hrl").
 
 -define(TIMEOUT, 1000).
--define(ADMIN_USER, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}).
 
 
 start() ->

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/7857cf8e/test/couch_mrview_red_views_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_red_views_tests.erl b/test/couch_mrview_red_views_tests.erl
index 382963a..10f0fe3 100644
--- a/test/couch_mrview_red_views_tests.erl
+++ b/test/couch_mrview_red_views_tests.erl
@@ -16,7 +16,6 @@
 -include_lib("couch/include/couch_db.hrl").
 
 -define(TIMEOUT, 1000).
--define(ADMIN_USER, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}).
 
 
 start() ->


[05/14] couch-mrview commit: updated refs/heads/master to d548785

Posted by rn...@apache.org.
Port couch_mrview/05-collation.t etap test suite to eunit


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/776605bf
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/776605bf
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/776605bf

Branch: refs/heads/master
Commit: 776605bf5433b7e9d345891bf5336e9db02bce31
Parents: d98c180
Author: Alexander Shorin <kx...@apache.org>
Authored: Thu Jun 12 02:30:45 2014 +0400
Committer: Russell Branca <ch...@apache.org>
Committed: Thu Aug 28 10:27:04 2014 -0700

----------------------------------------------------------------------
 .../test/couch_mrview_collation_tests.erl       | 202 +++++++++++++++++++
 test/05-collation.t                             | 164 ---------------
 2 files changed, 202 insertions(+), 164 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/776605bf/src/couch_mrview/test/couch_mrview_collation_tests.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview/test/couch_mrview_collation_tests.erl b/src/couch_mrview/test/couch_mrview_collation_tests.erl
new file mode 100644
index 0000000..485fd2d
--- /dev/null
+++ b/src/couch_mrview/test/couch_mrview_collation_tests.erl
@@ -0,0 +1,202 @@
+% 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_collation_tests).
+
+-include("../../../test/couchdb/couch_eunit.hrl").
+-include_lib("couchdb/couch_db.hrl").
+
+-define(ADMIN_USER, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}).
+-define(TIMEOUT, 1000).
+-define(VALUES, [
+    null,
+    false,
+    true,
+
+    1,
+    2,
+    3.0,
+    4,
+
+    <<"a">>,
+    <<"A">>,
+    <<"aa">>,
+    <<"b">>,
+    <<"B">>,
+    <<"ba">>,
+    <<"bb">>,
+
+    [<<"a">>],
+    [<<"b">>],
+    [<<"b">>, <<"c">>],
+    [<<"b">>, <<"c">>, <<"a">>],
+    [<<"b">>, <<"d">>],
+    [<<"b">>, <<"d">>, <<"e">>],
+
+    {[{<<"a">>, 1}]},
+    {[{<<"a">>, 2}]},
+    {[{<<"b">>, 1}]},
+    {[{<<"b">>, 2}]},
+    {[{<<"b">>, 2}, {<<"a">>, 1}]},
+    {[{<<"b">>, 2}, {<<"c">>, 2}]}
+]).
+
+
+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, Db1} = couch_mrview_test_util:new_db(?tempdb(), map),
+    {ok, Db2} = couch_mrview_test_util:save_docs(Db1, make_docs()),
+    Db2.
+
+teardown(Db) ->
+    couch_db:close(Db),
+    couch_server:delete(Db#db.name, [?ADMIN_USER]),
+    ok.
+
+
+collation_test_() ->
+    {
+        "Collation tests",
+        {
+            setup,
+            fun start/0, fun stop/1,
+            {
+                foreach,
+                fun setup/0, fun teardown/1,
+                [
+                    fun should_collate_fwd/1,
+                    fun should_collate_rev/1,
+                    fun should_collate_range/1,
+                    fun should_collate_with_inclusive_end_fwd/1,
+                    fun should_collate_with_inclusive_end_rev/1,
+                    fun should_collate_without_inclusive_end_fwd/1,
+                    fun should_collate_without_inclusive_end_rev/1,
+                    fun should_collate_with_endkey_docid/1
+                ]
+            }
+        }
+    }.
+
+
+should_collate_fwd(Db) ->
+    {ok, Results} = run_query(Db, []),
+    Expect = [{meta, [{total, 26}, {offset, 0}]}] ++ rows(),
+    %% cannot use _assertEqual since mrview converts
+    %% value 3.0 to 3 making assertion fail
+    ?_assert(Expect == Results).
+
+should_collate_rev(Db) ->
+    {ok, Results} = run_query(Db, [{direction, rev}]),
+    Expect = [{meta, [{total, 26}, {offset, 0}]}] ++ lists:reverse(rows()),
+    %% cannot use _assertEqual since mrview converts
+    %% value 3.0 to 3 making assertion fail
+    ?_assert(Expect == Results).
+
+should_collate_range(Db) ->
+    ?_assertNot(
+        begin
+            {_, Error} = lists:foldl(fun(V, {Count, Error}) ->
+                {ok, Results} = run_query(Db, [{start_key, V}, {end_key, V}]),
+                Id = list_to_binary(integer_to_list(Count)),
+                Expect = [
+                    {meta, [{total, 26}, {offset, Count}]},
+                    {row, [{id, Id}, {key, V}, {value, 0}]}
+                ],
+                case Results == Expect of
+                    true -> {Count+1, Error};
+                    _ -> {Count+1, true}
+                end
+            end, {0, false}, ?VALUES),
+            Error
+        end).
+
+should_collate_with_inclusive_end_fwd(Db) ->
+    Opts = [{end_key, <<"b">>}, {inclusive_end, true}],
+    {ok, Rows0} = run_query(Db, Opts),
+    LastRow = lists:last(Rows0),
+    Expect = {row, [{id,<<"10">>}, {key,<<"b">>}, {value,0}]},
+    ?_assertEqual(Expect, LastRow).
+
+should_collate_with_inclusive_end_rev(Db) ->
+    Opts = [{end_key, <<"b">>}, {inclusive_end, true}, {direction, rev}],
+    {ok, Rows} = run_query(Db, Opts),
+    LastRow = lists:last(Rows),
+    Expect = {row, [{id,<<"10">>}, {key,<<"b">>}, {value,0}]},
+    ?_assertEqual(Expect, LastRow).
+
+should_collate_without_inclusive_end_fwd(Db) ->
+    Opts = [{end_key, <<"b">>}, {inclusive_end, false}],
+    {ok, Rows0} = run_query(Db, Opts),
+    LastRow = lists:last(Rows0),
+    Expect = {row, [{id,<<"9">>}, {key,<<"aa">>}, {value,0}]},
+    ?_assertEqual(Expect, LastRow).
+
+should_collate_without_inclusive_end_rev(Db) ->
+    Opts = [{end_key, <<"b">>}, {inclusive_end, false}, {direction, rev}],
+    {ok, Rows} = run_query(Db, Opts),
+    LastRow = lists:last(Rows),
+    Expect = {row, [{id,<<"11">>}, {key,<<"B">>}, {value,0}]},
+    ?_assertEqual(Expect, LastRow).
+
+should_collate_with_endkey_docid(Db) ->
+    ?_test(begin
+        {ok, Rows0} = run_query(Db, [
+            {end_key, <<"b">>}, {end_key_docid, <<"10">>},
+            {inclusive_end, false}
+        ]),
+        Result0 = lists:last(Rows0),
+        Expect0 = {row, [{id,<<"9">>}, {key,<<"aa">>}, {value,0}]},
+        ?assertEqual(Expect0, Result0),
+
+        {ok, Rows1} = run_query(Db, [
+            {end_key, <<"b">>}, {end_key_docid, <<"11">>},
+            {inclusive_end, false}
+        ]),
+        Result1 = lists:last(Rows1),
+        Expect1 = {row, [{id,<<"10">>}, {key,<<"b">>}, {value,0}]},
+        ?assertEqual(Expect1, Result1)
+    end).
+
+
+make_docs() ->
+    {Docs, _} = lists:foldl(fun(V, {Docs0, Count}) ->
+        Doc = couch_doc:from_json_obj({[
+            {<<"_id">>, list_to_binary(integer_to_list(Count))},
+            {<<"foo">>, V}
+        ]}),
+        {[Doc | Docs0], Count+1}
+    end, {[], 0}, ?VALUES),
+    Docs.
+
+rows() ->
+    {Rows, _} = lists:foldl(fun(V, {Rows0, Count}) ->
+        Id = list_to_binary(integer_to_list(Count)),
+        Row = {row, [{id, Id}, {key, V}, {value, 0}]},
+        {[Row | Rows0], Count+1}
+    end, {[], 0}, ?VALUES),
+    lists:reverse(Rows).
+
+run_query(Db, Opts) ->
+    couch_mrview:query_view(Db, <<"_design/bar">>, <<"zing">>, Opts).

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/776605bf/test/05-collation.t
----------------------------------------------------------------------
diff --git a/test/05-collation.t b/test/05-collation.t
deleted file mode 100644
index 09878af..0000000
--- a/test/05-collation.t
+++ /dev/null
@@ -1,164 +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(9, fun() -> test() end).
-
-
-test() ->
-    test_util:start_couch(),
-
-    {ok, Db0} = couch_mrview_test_util:new_db(<<"foo">>, map),
-    {ok, Db1} = couch_mrview_test_util:save_docs(Db0, docs()),
-
-    test_collated_fwd(Db1),
-    test_collated_rev(Db1),
-    test_range_collation(Db1),
-    test_inclusive_end(Db1),
-    test_uninclusive_end(Db1),
-    test_with_endkey_docid(Db1),
-
-    ok.
-
-test_collated_fwd(Db) ->
-    {ok, Results} = run_query(Db, []),
-    Expect = [{meta, [{total, 26}, {offset, 0}]}] ++ rows(),
-    etap:is(Results, Expect, "Values were collated correctly.").
-
-
-test_collated_rev(Db) ->
-    {ok, Results} = run_query(Db, [{direction, rev}]),
-    Expect = [{meta, [{total, 26}, {offset, 0}]}] ++ lists:reverse(rows()),
-    etap:is(Results, Expect, "Values were collated correctly descending.").
-
-
-test_range_collation(Db) ->
-    {_, Error} = lists:foldl(fun(V, {Count, Error}) ->
-        {ok, Results} = run_query(Db, [{start_key, V}, {end_key, V}]),
-        Id = list_to_binary(integer_to_list(Count)),
-        Expect = [
-            {meta, [{total, 26}, {offset, Count}]},
-            {row, [{id, Id}, {key, V}, {value, 0}]}
-        ],
-        case Results == Expect of
-            true -> {Count+1, Error};
-            _ -> {Count+1, true}
-        end
-    end, {0, false}, vals()),
-    etap:is(Error, false, "Found each individual key correctly.").
-
-
-test_inclusive_end(Db) ->
-    Opts = [{end_key, <<"b">>}, {inclusive_end, true}],
-    {ok, Rows0} = run_query(Db, Opts),
-    LastRow0 = lists:last(Rows0),
-    Expect0 = {row, [{id,<<"10">>}, {key,<<"b">>}, {value,0}]},
-    etap:is(LastRow0, Expect0, "Inclusive end is correct."),
-
-    {ok, Rows1} = run_query(Db, Opts ++ [{direction, rev}]),
-    LastRow1 = lists:last(Rows1),
-    Expect1 = {row, [{id,<<"10">>}, {key,<<"b">>}, {value,0}]},
-    etap:is(LastRow1, Expect1,
-            "Inclusive end is correct with descending=true").
-
-test_uninclusive_end(Db) ->
-    Opts = [{end_key, <<"b">>}, {inclusive_end, false}],
-    {ok, Rows0} = run_query(Db, Opts),
-    LastRow0 = lists:last(Rows0),
-    Expect0 = {row, [{id,<<"9">>}, {key,<<"aa">>}, {value,0}]},
-    etap:is(LastRow0, Expect0, "Uninclusive end is correct."),
-
-    {ok, Rows1} = run_query(Db, Opts ++ [{direction, rev}]),
-    LastRow1 = lists:last(Rows1),
-    Expect1 = {row, [{id,<<"11">>}, {key,<<"B">>}, {value,0}]},
-    etap:is(LastRow1, Expect1,
-            "Uninclusive end is correct with descending=true").
-
-
-test_with_endkey_docid(Db) ->
-    {ok, Rows0} = run_query(Db, [
-        {end_key, <<"b">>}, {end_key_docid, <<"10">>},
-        {inclusive_end, false}
-    ]),
-    Result0 = lists:last(Rows0),
-    Expect0 = {row, [{id,<<"9">>}, {key,<<"aa">>}, {value,0}]},
-    etap:is(Result0, Expect0, "Uninclsuive end with endkey_docid set is ok."),
-
-    {ok, Rows1} = run_query(Db, [
-        {end_key, <<"b">>}, {end_key_docid, <<"11">>},
-        {inclusive_end, false}
-    ]),
-    Result1 = lists:last(Rows1),
-    Expect1 = {row, [{id,<<"10">>}, {key,<<"b">>}, {value,0}]},
-    etap:is(Result1, Expect1, "Uninclsuive end with endkey_docid set is ok.").
-
-
-run_query(Db, Opts) ->
-    couch_mrview:query_view(Db, <<"_design/bar">>, <<"zing">>, Opts).
-
-
-docs() ->
-    {Docs, _} = lists:foldl(fun(V, {Docs0, Count}) ->
-        Doc = couch_doc:from_json_obj({[
-            {<<"_id">>, list_to_binary(integer_to_list(Count))},
-            {<<"foo">>, V}
-        ]}),
-        {[Doc | Docs0], Count+1}
-    end, {[], 0}, vals()),
-    Docs.
-
-
-rows() ->
-    {Rows, _} = lists:foldl(fun(V, {Rows0, Count}) ->
-        Id = list_to_binary(integer_to_list(Count)),
-        Row = {row, [{id, Id}, {key, V}, {value, 0}]},
-        {[Row | Rows0], Count+1}
-    end, {[], 0}, vals()),
-    lists:reverse(Rows).
-
-
-vals() ->
-    [
-        null,
-        false,
-        true,
-
-        1,
-        2,
-        3.0,
-        4,
-
-        <<"a">>,
-        <<"A">>,
-        <<"aa">>,
-        <<"b">>,
-        <<"B">>,
-        <<"ba">>,
-        <<"bb">>,
-
-        [<<"a">>],
-        [<<"b">>],
-        [<<"b">>, <<"c">>],
-        [<<"b">>, <<"c">>, <<"a">>],
-        [<<"b">>, <<"d">>],
-        [<<"b">>, <<"d">>, <<"e">>],
-
-        {[{<<"a">>, 1}]},
-        {[{<<"a">>, 2}]},
-        {[{<<"b">>, 1}]},
-        {[{<<"b">>, 2}]},
-        {[{<<"b">>, 2}, {<<"a">>, 1}]},
-        {[{<<"b">>, 2}, {<<"c">>, 2}]}
-    ].