couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxe...@apache.org
Subject [16/36] couchdb commit: updated refs/heads/1963-eunit to 85f2750
Date Tue, 03 Jun 2014 15:54:54 GMT
Port 070-couch-db.t etap test suite to eunit

Fix ERL_LIB environment variable setting. Add ?tempdb macros for
unique temporary database name generation.


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

Branch: refs/heads/1963-eunit
Commit: e722195ff76244f9011dff5ff1b20bb2474dc101
Parents: 5f6a0b6
Author: Alexander Shorin <kxepal@apache.org>
Authored: Mon May 19 05:36:06 2014 +0400
Committer: Alexander Shorin <kxepal@apache.org>
Committed: Tue Jun 3 15:14:25 2014 +0400

----------------------------------------------------------------------
 test/couchdb/Makefile.am          |  1 +
 test/couchdb/couch_db_tests.erl   | 90 ++++++++++++++++++++++++++++++++++
 test/couchdb/couchdb_tests.hrl.in |  7 +++
 test/couchdb/run.in               |  2 +-
 test/etap/070-couch-db.t          | 73 ---------------------------
 test/etap/Makefile.am             |  1 -
 6 files changed, 99 insertions(+), 75 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/e722195f/test/couchdb/Makefile.am
----------------------------------------------------------------------
diff --git a/test/couchdb/Makefile.am b/test/couchdb/Makefile.am
index 396a36b..b8ad5ed 100644
--- a/test/couchdb/Makefile.am
+++ b/test/couchdb/Makefile.am
@@ -26,6 +26,7 @@ eunit_files = \
     couch_work_queue_tests.erl \
     couch_stream_tests.erl \
     couch_key_tree_tests.erl \
+    couch_db_tests.erl \
     couchdb_tests.hrl
 
 EXTRA_DIST = \

http://git-wip-us.apache.org/repos/asf/couchdb/blob/e722195f/test/couchdb/couch_db_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb/couch_db_tests.erl b/test/couchdb/couch_db_tests.erl
new file mode 100644
index 0000000..d651126
--- /dev/null
+++ b/test/couchdb/couch_db_tests.erl
@@ -0,0 +1,90 @@
+% 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_db_tests).
+
+-include_lib("couchdb_tests.hrl").
+
+
+setup() ->
+    {ok, _} = couch_server_sup:start_link(?CONFIG_CHAIN),
+    ok.
+
+teardown(_) ->
+    couch_server_sup:stop().
+
+
+create_delete_db_test_()->
+    {
+        "Database create/delete tests",
+        {
+            setup,
+            fun setup/0, fun teardown/1,
+            fun(_) ->
+                [should_create_db(),
+                 should_delete_db(),
+                 should_create_multiple_dbs(),
+                 should_delete_multiple_dbs()]
+            end
+        }
+    }.
+
+
+should_create_db() ->
+    DbName = ?tempdb(),
+    {ok, Db} = couch_db:create(DbName, []),
+    ok = couch_db:close(Db),
+    {ok, AllDbs} = couch_server:all_databases(),
+    ?_assert(lists:member(DbName, AllDbs)).
+
+should_delete_db() ->
+    DbName = ?tempdb(),
+    couch_db:create(DbName, []),
+    couch_server:delete(DbName, []),
+    {ok, AllDbs} = couch_server:all_databases(),
+    ?_assertNot(lists:member(DbName, AllDbs)).
+
+should_create_multiple_dbs() ->
+    gen_server:call(couch_server, {set_max_dbs_open, 3}),
+
+    DbNames = [?tempdb() || _ <- lists:seq(1, 6)],
+    lists:foreach(fun(DbName) ->
+        {ok, Db} = couch_db:create(DbName, []),
+        ok = couch_db:close(Db)
+    end, DbNames),
+
+    {ok, AllDbs} = couch_server:all_databases(),
+    NumCreated = lists:foldl(fun(DbName, Acc) ->
+        ?assert(lists:member(DbName, AllDbs)),
+        Acc+1
+    end, 0, DbNames),
+
+    ?_assertEqual(NumCreated, 6).
+
+should_delete_multiple_dbs() ->
+    DbNames = [?tempdb() || _ <- lists:seq(1, 6)],
+    lists:foreach(fun(DbName) ->
+        {ok, Db} = couch_db:create(DbName, []),
+        ok = couch_db:close(Db)
+    end, DbNames),
+
+    lists:foreach(fun(DbName) ->
+        ok = couch_server:delete(DbName, [])
+    end, DbNames),
+
+    {ok, AllDbs} = couch_server:all_databases(),
+    NumDeleted = lists:foldl(fun(DbName, Acc) ->
+        ?assertNot(lists:member(DbName, AllDbs)),
+        Acc + 1
+    end, 0, DbNames),
+
+    ?_assertEqual(NumDeleted, 6).

http://git-wip-us.apache.org/repos/asf/couchdb/blob/e722195f/test/couchdb/couchdb_tests.hrl.in
----------------------------------------------------------------------
diff --git a/test/couchdb/couchdb_tests.hrl.in b/test/couchdb/couchdb_tests.hrl.in
index e5a8b4e..1014c78 100644
--- a/test/couchdb/couchdb_tests.hrl.in
+++ b/test/couchdb/couchdb_tests.hrl.in
@@ -28,3 +28,10 @@
         FileName = lists:flatten(io_lib:format("~p-~p.~p.~p", [N, A, B, C])),
         filename:join([?TEMPDIR, FileName])
     end).
+-define(tempdb,
+    fun() ->
+            Nums = tuple_to_list(erlang:now()),
+            Prefix = "eunit-test-db",
+            Suffix = lists:concat([integer_to_list(Num) || Num <- Nums]),
+            list_to_binary(Prefix ++ "-" ++ Suffix)
+    end).

http://git-wip-us.apache.org/repos/asf/couchdb/blob/e722195f/test/couchdb/run.in
----------------------------------------------------------------------
diff --git a/test/couchdb/run.in b/test/couchdb/run.in
index 80f4041..06109aa 100644
--- a/test/couchdb/run.in
+++ b/test/couchdb/run.in
@@ -1,6 +1,6 @@
 #!/usr/bin/env escript
 %% -*- erlang -*-
-%%! -DTEST -pa @abs_top_builddir@/test/couchdb/ebin
+%%! -DTEST -env ERL_LIBS @abs_top_builddir@/src:$ERL_LIBS -pa @abs_top_builddir@/test/couchdb/ebin
 %%
 %% 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

http://git-wip-us.apache.org/repos/asf/couchdb/blob/e722195f/test/etap/070-couch-db.t
----------------------------------------------------------------------
diff --git a/test/etap/070-couch-db.t b/test/etap/070-couch-db.t
deleted file mode 100755
index 787d6c6..0000000
--- a/test/etap/070-couch-db.t
+++ /dev/null
@@ -1,73 +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:init_code_path(),
-
-    etap:plan(4),
-    case (catch test()) of
-        ok ->
-            etap:end_tests();
-        Other ->
-            etap:diag(io_lib:format("Test died abnormally: ~p", [Other])),
-            etap:bail(Other)
-    end,
-    ok.
-
-test() ->
-
-    couch_server_sup:start_link(test_util:config_files()),
-
-    couch_db:create(<<"etap-test-db">>, []),
-    {ok, AllDbs} = couch_server:all_databases(),
-    etap:ok(lists:member(<<"etap-test-db">>, AllDbs), "Database was created."),
-
-    couch_server:delete(<<"etap-test-db">>, []),
-    {ok, AllDbs2} = couch_server:all_databases(),
-    etap:ok(not lists:member(<<"etap-test-db">>, AllDbs2),
-        "Database was deleted."),
-
-    gen_server:call(couch_server, {set_max_dbs_open, 3}),
-    MkDbName = fun(Int) -> list_to_binary("lru-" ++ integer_to_list(Int)) end,
-
-    lists:foreach(fun(Int) ->
-        {ok, TestDbs} = couch_server:all_databases(),
-        ok = case lists:member(MkDbName(Int), TestDbs) of
-            true -> couch_server:delete(MkDbName(Int), []);
-            _ -> ok
-        end,
-        {ok, Db} = couch_db:create(MkDbName(Int), []),
-        ok = couch_db:close(Db)
-    end, lists:seq(1, 6)),
-
-    {ok, AllDbs3} = couch_server:all_databases(),
-    NumCreated = lists:foldl(fun(Int, Acc) ->
-        true = lists:member(MkDbName(Int), AllDbs3),
-        Acc+1
-    end, 0, lists:seq(1, 6)),
-    etap:is(6, NumCreated, "Created all databases."),
-
-    lists:foreach(fun(Int) ->
-        ok = couch_server:delete(MkDbName(Int), [])
-    end, lists:seq(1, 6)),
-
-    {ok, AllDbs4} = couch_server:all_databases(),
-    NumDeleted = lists:foldl(fun(Int, Acc) ->
-        false = lists:member(MkDbName(Int), AllDbs4),
-        Acc+1
-    end, 0, lists:seq(1, 6)),
-    etap:is(6, NumDeleted, "Deleted all databases."),
-
-    ok.

http://git-wip-us.apache.org/repos/asf/couchdb/blob/e722195f/test/etap/Makefile.am
----------------------------------------------------------------------
diff --git a/test/etap/Makefile.am b/test/etap/Makefile.am
index fe50da3..408ca40 100644
--- a/test/etap/Makefile.am
+++ b/test/etap/Makefile.am
@@ -36,7 +36,6 @@ fixture_files = \
     fixtures/test.couch
 
 tap_files = \
-    070-couch-db.t \
     072-cleanup.t \
     073-changes.t \
     074-doc-update-conflicts.t \


Mime
View raw message