couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxe...@apache.org
Subject [24/31] couchdb commit: updated refs/heads/1963-eunit to 16528f8
Date Tue, 03 Jun 2014 04:50:43 GMT
Port 081-config-override.t etap test suite to eunit

Merged into couch_config_tests suite.


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

Branch: refs/heads/1963-eunit
Commit: 862a8d877dcd72f33baf7eaf48e3345d31d80383
Parents: 496bbb3
Author: Alexander Shorin <kxepal@gmail.com>
Authored: Sun May 25 22:02:19 2014 +0400
Committer: Alexander Shorin <kxepal@gmail.com>
Committed: Tue Jun 3 03:46:07 2014 +0400

----------------------------------------------------------------------
 test/couchdb/Makefile.am                       |   7 +-
 test/couchdb/couch_config_tests.erl            | 142 ++++++++++++-
 test/couchdb/fixtures/couch_config_tests_1.ini |  22 ++
 test/couchdb/fixtures/couch_config_tests_2.ini |  22 ++
 test/etap/081-config-override.1.ini            |  22 --
 test/etap/081-config-override.2.ini            |  22 --
 test/etap/081-config-override.t                | 212 --------------------
 test/etap/Makefile.am                          |   3 -
 8 files changed, 190 insertions(+), 262 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/862a8d87/test/couchdb/Makefile.am
----------------------------------------------------------------------
diff --git a/test/couchdb/Makefile.am b/test/couchdb/Makefile.am
index 8668b96..cfb4a0f 100644
--- a/test/couchdb/Makefile.am
+++ b/test/couchdb/Makefile.am
@@ -37,9 +37,14 @@ eunit_files = \
     test_request.erl \
     couchdb_tests.hrl
 
+fixture_files = \
+    couch_config_tests_1.ini \
+    couch_config_tests_2.ini
+
 EXTRA_DIST = \
     run.in \
-    $(eunit_files)
+    $(eunit_files) \
+    $(fixture_files)
 
 clean-local:
 	rm -rf ebin

http://git-wip-us.apache.org/repos/asf/couchdb/blob/862a8d87/test/couchdb/couch_config_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb/couch_config_tests.erl b/test/couchdb/couch_config_tests.erl
index 9d09640..401da58 100644
--- a/test/couchdb/couch_config_tests.erl
+++ b/test/couchdb/couch_config_tests.erl
@@ -15,9 +15,30 @@
 -include("../../src/couchdb/couch_db.hrl").
 -include("couchdb_tests.hrl").
 
+-define(CONFIG_DEFAULT,
+        filename:join([?BUILDDIR, "etc", "couchdb", "default_dev.ini"])).
+-define(CONFIG_FIXTURE_1,
+        filename:join([?FIXTURESDIR, "couch_config_tests_1.ini"])).
+-define(CONFIG_FIXTURE_2,
+        filename:join([?FIXTURESDIR, "couch_config_tests_2.ini"])).
+-define(CONFIG_FIXTURE_TEMP,
+    begin
+        FileName = filename:join([?TEMPDIR, "couch_config_temp.ini"]),
+        {ok, Fd} = file:open(FileName, write),
+        ok = file:truncate(Fd),
+        ok = file:close(Fd),
+        FileName
+    end).
+
 
 setup() ->
-    {ok, Pid} = couch_config:start_link(?CONFIG_CHAIN),
+    setup(?CONFIG_CHAIN).
+setup({temporary, Chain}) ->
+    setup(Chain);
+setup({persistent, Chain}) ->
+    setup(lists:append(Chain, [?CONFIG_FIXTURE_TEMP]));
+setup(Chain) ->
+    {ok, Pid} = couch_config:start_link(Chain),
     Pid.
 
 teardown(Pid) ->
@@ -29,6 +50,8 @@ teardown(Pid) ->
     after 1000 ->
         throw({timeout_error, config_stop})
     end.
+teardown(_, Pid) ->
+    teardown(Pid).
 
 
 couch_config_test_() ->
@@ -37,7 +60,9 @@ couch_config_test_() ->
         [
             couch_config_get_tests(),
             couch_config_set_tests(),
-            couch_config_del_tests()
+            couch_config_del_tests(),
+            config_override_tests(),
+            config_persistent_changes_tests()
         ]
     }.
 
@@ -88,6 +113,43 @@ couch_config_del_tests() ->
         }
     }.
 
+config_override_tests() ->
+    {
+        "Configs overide tests",
+        {
+            foreachx,
+            fun setup/1, fun teardown/2,
+            [
+                {{temporary, [?CONFIG_DEFAULT]},
+                 fun should_ensure_in_defaults/2},
+                {{temporary, [?CONFIG_DEFAULT, ?CONFIG_FIXTURE_1]},
+                 fun should_override_options/2},
+                {{temporary, [?CONFIG_DEFAULT, ?CONFIG_FIXTURE_2]},
+                 fun should_create_new_sections_on_override/2},
+                {{temporary, [?CONFIG_DEFAULT, ?CONFIG_FIXTURE_1,
+                              ?CONFIG_FIXTURE_2]},
+                 fun should_win_last_in_chain/2}
+            ]
+        }
+    }.
+
+config_persistent_changes_tests() ->
+    {
+        "Config persistent changes",
+        {
+            foreachx,
+            fun setup/1, fun teardown/2,
+            [
+                {{persistent, [?CONFIG_DEFAULT]},
+                 fun should_write_changes/2},
+                {{temporary, [?CONFIG_DEFAULT]},
+                 fun should_ensure_that_default_wasnt_modified/2},
+                {{temporary, [?CONFIG_FIXTURE_TEMP]},
+                 fun should_ensure_that_written_to_last_config_in_chain/2}
+            ]
+        }
+    }.
+
 
 should_load_all_configs() ->
     ?_assert(length(couch_config:all()) > 0).
@@ -161,3 +223,79 @@ should_delete_binary_option() ->
             ok = couch_config:delete(<<"foo">>, <<"bar">>, false),
             couch_config:get(<<"foo">>, <<"bar">>)
         end).
+
+should_ensure_in_defaults(_, _) ->
+    ?_assert(
+        begin
+            ?assertEqual("100",
+                         couch_config:get("couchdb", "max_dbs_open")),
+            ?assertEqual("5984",
+                         couch_config:get("httpd", "port")),
+            ?assertEqual(undefined,
+                         couch_config:get("fizbang", "unicode")),
+            true
+        end).
+
+should_override_options(_, _) ->
+    ?_assert(
+        begin
+            ?assertEqual("10",
+                         couch_config:get("couchdb", "max_dbs_open")),
+            ?assertEqual("4895",
+                         couch_config:get("httpd", "port")),
+            true
+        end).
+
+should_create_new_sections_on_override(_, _) ->
+    ?_assert(
+        begin
+            ?assertEqual("80",
+                         couch_config:get("httpd", "port")),
+            ?assertEqual("normalized",
+                         couch_config:get("fizbang", "unicode")),
+            true
+        end).
+
+should_win_last_in_chain(_, _) ->
+    ?_assert(
+        begin
+            ?assertEqual("80",
+                         couch_config:get("httpd", "port")),
+            true
+        end).
+
+should_write_changes(_, _) ->
+    ?_assert(
+        begin
+            ?assertEqual("5984",
+                         couch_config:get("httpd", "port")),
+            ?assertEqual(ok,
+                         couch_config:set("httpd", "port", "8080")),
+            ?assertEqual("8080",
+                         couch_config:get("httpd", "port")),
+            ?assertEqual(ok,
+                         couch_config:delete("httpd", "bind_address", "8080")),
+            ?assertEqual(undefined,
+                         couch_config:get("httpd", "bind_address")),
+            true
+        end).
+
+should_ensure_that_default_wasnt_modified(_, _) ->
+    ?_assert(
+        begin
+            ?assertEqual("5984",
+                         couch_config:get("httpd", "port")),
+            ?assertEqual("127.0.0.1",
+                         couch_config:get("httpd", "bind_address")),
+            true
+        end).
+
+should_ensure_that_written_to_last_config_in_chain(_, _) ->
+    ?_assert(
+        begin
+            ?assertEqual("8080",
+                         couch_config:get("httpd", "port")),
+            ?assertEqual(undefined,
+                         couch_config:get("httpd", "bind_address")),
+            true
+        end).

http://git-wip-us.apache.org/repos/asf/couchdb/blob/862a8d87/test/couchdb/fixtures/couch_config_tests_1.ini
----------------------------------------------------------------------
diff --git a/test/couchdb/fixtures/couch_config_tests_1.ini b/test/couchdb/fixtures/couch_config_tests_1.ini
new file mode 100644
index 0000000..55451da
--- /dev/null
+++ b/test/couchdb/fixtures/couch_config_tests_1.ini
@@ -0,0 +1,22 @@
+; Licensed to the Apache Software Foundation (ASF) under one
+; or more contributor license agreements.  See the NOTICE file
+; distributed with this work for additional information
+; regarding copyright ownership.  The ASF licenses this file
+; to you 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.
+
+[couchdb]
+max_dbs_open=10
+
+[httpd]
+port=4895

http://git-wip-us.apache.org/repos/asf/couchdb/blob/862a8d87/test/couchdb/fixtures/couch_config_tests_2.ini
----------------------------------------------------------------------
diff --git a/test/couchdb/fixtures/couch_config_tests_2.ini b/test/couchdb/fixtures/couch_config_tests_2.ini
new file mode 100644
index 0000000..5f46357
--- /dev/null
+++ b/test/couchdb/fixtures/couch_config_tests_2.ini
@@ -0,0 +1,22 @@
+; Licensed to the Apache Software Foundation (ASF) under one
+; or more contributor license agreements.  See the NOTICE file
+; distributed with this work for additional information
+; regarding copyright ownership.  The ASF licenses this file
+; to you 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.
+
+[httpd]
+port = 80
+
+[fizbang]
+unicode = normalized

http://git-wip-us.apache.org/repos/asf/couchdb/blob/862a8d87/test/etap/081-config-override.1.ini
----------------------------------------------------------------------
diff --git a/test/etap/081-config-override.1.ini b/test/etap/081-config-override.1.ini
deleted file mode 100644
index 55451da..0000000
--- a/test/etap/081-config-override.1.ini
+++ /dev/null
@@ -1,22 +0,0 @@
-; Licensed to the Apache Software Foundation (ASF) under one
-; or more contributor license agreements.  See the NOTICE file
-; distributed with this work for additional information
-; regarding copyright ownership.  The ASF licenses this file
-; to you 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.
-
-[couchdb]
-max_dbs_open=10
-
-[httpd]
-port=4895

http://git-wip-us.apache.org/repos/asf/couchdb/blob/862a8d87/test/etap/081-config-override.2.ini
----------------------------------------------------------------------
diff --git a/test/etap/081-config-override.2.ini b/test/etap/081-config-override.2.ini
deleted file mode 100644
index 5f46357..0000000
--- a/test/etap/081-config-override.2.ini
+++ /dev/null
@@ -1,22 +0,0 @@
-; Licensed to the Apache Software Foundation (ASF) under one
-; or more contributor license agreements.  See the NOTICE file
-; distributed with this work for additional information
-; regarding copyright ownership.  The ASF licenses this file
-; to you 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.
-
-[httpd]
-port = 80
-
-[fizbang]
-unicode = normalized

http://git-wip-us.apache.org/repos/asf/couchdb/blob/862a8d87/test/etap/081-config-override.t
----------------------------------------------------------------------
diff --git a/test/etap/081-config-override.t b/test/etap/081-config-override.t
deleted file mode 100755
index 01f8b4c..0000000
--- a/test/etap/081-config-override.t
+++ /dev/null
@@ -1,212 +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.
-
-default_config() ->
-    test_util:build_file("etc/couchdb/default_dev.ini").
-
-local_config_1() ->
-    test_util:source_file("test/etap/081-config-override.1.ini").
-
-local_config_2() ->
-    test_util:source_file("test/etap/081-config-override.2.ini").
-
-local_config_write() ->
-    test_util:build_file("test/etap/temp.081").
-
-% Run tests and wait for the config gen_server to shutdown.
-run_tests(IniFiles, Tests) ->
-    {ok, Pid} = couch_config:start_link(IniFiles),
-    erlang:monitor(process, Pid),
-    Tests(),
-    couch_config:stop(),
-    receive
-        {'DOWN', _, _, Pid, _} -> ok;
-        _Other -> etap:diag("OTHER: ~p~n", [_Other])
-    after
-        1000 -> throw({timeout_error, config_stop})
-    end.
-
-main(_) ->
-    test_util:init_code_path(),
-    etap:plan(17),
-
-    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() ->
-
-    CheckStartStop = fun() -> ok end,
-    run_tests([default_config()], CheckStartStop),
-
-    CheckDefaults = fun() ->
-        etap:is(
-            couch_config:get("couchdb", "max_dbs_open"),
-            "100",
-            "{couchdb, max_dbs_open} is 100 by defualt."
-        ),
-
-        etap:is(
-            couch_config:get("httpd","port"),
-            "5984",
-            "{httpd, port} is 5984 by default"
-        ),
-
-        etap:is(
-            couch_config:get("fizbang", "unicode"),
-            undefined,
-            "{fizbang, unicode} is undefined by default"
-        )
-    end,
-
-    run_tests([default_config()], CheckDefaults),
-
-
-    % Check that subsequent files override values appropriately
-
-    CheckOverride = fun() ->
-        etap:is(
-            couch_config:get("couchdb", "max_dbs_open"),
-            "10",
-            "{couchdb, max_dbs_open} was overriden with the value 10"
-        ),
-
-        etap:is(
-            couch_config:get("httpd", "port"),
-            "4895",
-            "{httpd, port} was overriden with the value 4895"
-        )
-    end,
-
-    run_tests([default_config(), local_config_1()], CheckOverride),
-
-
-    % Check that overrides can create new sections
-
-    CheckOverride2 = fun() ->
-        etap:is(
-            couch_config:get("httpd", "port"),
-            "80",
-            "{httpd, port} is overriden with the value 80"
-        ),
-
-        etap:is(
-            couch_config:get("fizbang", "unicode"),
-            "normalized",
-            "{fizbang, unicode} was created by override INI file"
-        )
-    end,
-
-    run_tests([default_config(), local_config_2()], CheckOverride2),
-
-
-    % Check that values can be overriden multiple times
-
-    CheckOverride3 = fun() ->
-        etap:is(
-            couch_config:get("httpd", "port"),
-            "80",
-            "{httpd, port} value was taken from the last specified INI file."
-        )
-    end,
-
-    run_tests(
-        [default_config(), local_config_1(), local_config_2()],
-        CheckOverride3
-    ),
-
-    % Check persistence to last file.
-
-    % Empty the file in case it exists.
-    {ok, Fd} = file:open(local_config_write(), write),
-    ok = file:truncate(Fd),
-    ok = file:close(Fd),
-
-    % Open and write a value
-    CheckCanWrite = fun() ->
-        etap:is(
-            couch_config:get("httpd", "port"),
-            "5984",
-            "{httpd, port} is still 5984 by default"
-        ),
-
-        etap:is(
-            couch_config:set("httpd", "port", "8080"),
-            ok,
-            "Writing {httpd, port} is kosher."
-        ),
-
-        etap:is(
-            couch_config:get("httpd", "port"),
-            "8080",
-            "{httpd, port} was updated to 8080 successfully."
-        ),
-
-        etap:is(
-            couch_config:delete("httpd", "bind_address"),
-            ok,
-            "Deleting {httpd, bind_address} succeeds"
-        ),
-
-        etap:is(
-            couch_config:get("httpd", "bind_address"),
-            undefined,
-            "{httpd, bind_address} was actually deleted."
-        )
-    end,
-
-    run_tests([default_config(), local_config_write()], CheckCanWrite),
-
-    % Open and check where we don't expect persistence.
-
-    CheckDidntWrite = fun() ->
-        etap:is(
-            couch_config:get("httpd", "port"),
-            "5984",
-            "{httpd, port} was not persisted to the primary INI file."
-        ),
-
-        etap:is(
-            couch_config:get("httpd", "bind_address"),
-            "127.0.0.1",
-            "{httpd, bind_address} was not deleted form the primary INI file."
-        )
-    end,
-
-    run_tests([default_config()], CheckDidntWrite),
-
-    % Open and check we have only the persistence we expect.
-    CheckDidWrite = fun() ->
-        etap:is(
-            couch_config:get("httpd", "port"),
-            "8080",
-            "{httpd, port} is still 8080 after reopening the config."
-        ),
-
-        etap:is(
-            couch_config:get("httpd", "bind_address"),
-            undefined,
-            "{httpd, bind_address} is still \"\" after reopening."
-        )
-    end,
-
-    run_tests([local_config_write()], CheckDidWrite),
-
-    ok.

http://git-wip-us.apache.org/repos/asf/couchdb/blob/862a8d87/test/etap/Makefile.am
----------------------------------------------------------------------
diff --git a/test/etap/Makefile.am b/test/etap/Makefile.am
index 436a27b..07583ac 100644
--- a/test/etap/Makefile.am
+++ b/test/etap/Makefile.am
@@ -36,9 +36,6 @@ fixture_files = \
     fixtures/test.couch
 
 tap_files = \
-    081-config-override.1.ini \
-    081-config-override.2.ini \
-    081-config-override.t \
     082-config-register.t \
     083-config-no-files.t \
     090-task-status.t \


Mime
View raw message