couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxe...@apache.org
Subject [39/50] couchdb commit: updated refs/heads/1963-eunit to bfb7eb9
Date Mon, 16 Jun 2014 22:53:20 GMT
Port couch_mrview/05-collation.t etap test suite to eunit


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

Branch: refs/heads/1963-eunit
Commit: c332a227e2ce2944ed0a92a41a0538abe25ae387
Parents: 38b3ecf
Author: Alexander Shorin <kxepal@apache.org>
Authored: Thu Jun 12 02:30:45 2014 +0400
Committer: Alexander Shorin <kxepal@apache.org>
Committed: Tue Jun 17 01:42:13 2014 +0400

----------------------------------------------------------------------
 src/couch_mrview/Makefile.am                    |   2 +-
 src/couch_mrview/test/05-collation.t            | 163 ---------------
 .../test/couch_mrview_collation_tests.erl       | 202 +++++++++++++++++++
 3 files changed, 203 insertions(+), 164 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/c332a227/src/couch_mrview/Makefile.am
----------------------------------------------------------------------
diff --git a/src/couch_mrview/Makefile.am b/src/couch_mrview/Makefile.am
index 1aeee7f..cd93564 100644
--- a/src/couch_mrview/Makefile.am
+++ b/src/couch_mrview/Makefile.am
@@ -33,11 +33,11 @@ source_files = \
     src/couch_mrview_util.erl
 
 test_files = \
+    test/couch_mrview_collation_tests.erl \
     test/couch_mrview_index_info_tests.erl \
     test/couch_mrview_map_views_tests.erl \
     test/couch_mrview_modules_load_tests.erl \
     test/couch_mrview_red_views_tests.erl \
-    test/05-collation.t \
     test/06-all-docs.t \
 	test/07-compact-swap.t
 

http://git-wip-us.apache.org/repos/asf/couchdb/blob/c332a227/src/couch_mrview/test/05-collation.t
----------------------------------------------------------------------
diff --git a/src/couch_mrview/test/05-collation.t b/src/couch_mrview/test/05-collation.t
deleted file mode 100644
index ac8f8bc..0000000
--- a/src/couch_mrview/test/05-collation.t
+++ /dev/null
@@ -1,163 +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() ->
-    couch_server_sup:start_link(test_util:config_files()),
-    {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}]}
-    ].

http://git-wip-us.apache.org/repos/asf/couchdb/blob/c332a227/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).


Mime
View raw message