You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ch...@apache.org on 2014/07/22 01:57:32 UTC

[19/43] couchdb commit: updated refs/heads/1963-eunit-bigcouch to 424dca5

Port 081-config-override.t etap test suite to eunit

Merged into couch_config_tests suite.
Setup fixtures.


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

Branch: refs/heads/1963-eunit-bigcouch
Commit: cfdcbac4117b157b27cad75d2f8fb5a4f4939be8
Parents: 458c7d0
Author: Alexander Shorin <kx...@apache.org>
Authored: Sun May 25 22:02:19 2014 +0400
Committer: Russell Branca <ch...@apache.org>
Committed: Mon Jul 21 16:43:25 2014 -0700

----------------------------------------------------------------------
 test/couchdb/couch_config_tests.erl            | 130 +++++++++++-
 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                | 208 --------------------
 6 files changed, 168 insertions(+), 258 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/cfdcbac4/test/couchdb/couch_config_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb/couch_config_tests.erl b/test/couchdb/couch_config_tests.erl
index ecff590..4bdc333 100644
--- a/test/couchdb/couch_config_tests.erl
+++ b/test/couchdb/couch_config_tests.erl
@@ -17,9 +17,30 @@
 
 -define(TIMEOUT, 1000).
 
+-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) ->
@@ -31,6 +52,8 @@ teardown(Pid) ->
     after ?TIMEOUT ->
         throw({timeout_error, config_stop})
     end.
+teardown(_, Pid) ->
+    teardown(Pid).
 
 
 couch_config_test_() ->
@@ -39,7 +62,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()
         ]
     }.
 
@@ -90,6 +115,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).
@@ -151,10 +213,7 @@ should_return_undefined_atom_after_option_deletion() ->
         end).
 
 should_be_ok_on_deleting_unknown_options() ->
-    ?_assertEqual(ok,
-        begin
-            couch_config:delete("zoo", "boo", false)
-        end).
+    ?_assertEqual(ok, couch_config:delete("zoo", "boo", false)).
 
 should_delete_binary_option() ->
     ?_assertEqual(undefined,
@@ -163,3 +222,62 @@ should_delete_binary_option() ->
             ok = couch_config:delete(<<"foo">>, <<"bar">>, false),
             couch_config:get(<<"foo">>, <<"bar">>)
         end).
+
+should_ensure_in_defaults(_, _) ->
+    ?_test(begin
+        ?assertEqual("100",
+                     couch_config:get("couchdb", "max_dbs_open")),
+        ?assertEqual("5984",
+                     couch_config:get("httpd", "port")),
+        ?assertEqual(undefined,
+                     couch_config:get("fizbang", "unicode"))
+    end).
+
+should_override_options(_, _) ->
+    ?_test(begin
+        ?assertEqual("10",
+                     couch_config:get("couchdb", "max_dbs_open")),
+        ?assertEqual("4895",
+                     couch_config:get("httpd", "port"))
+    end).
+
+should_create_new_sections_on_override(_, _) ->
+    ?_test(begin
+        ?assertEqual("80",
+                     couch_config:get("httpd", "port")),
+        ?assertEqual("normalized",
+                     couch_config:get("fizbang", "unicode"))
+    end).
+
+should_win_last_in_chain(_, _) ->
+    ?_assertEqual("80", couch_config:get("httpd", "port")).
+
+should_write_changes(_, _) ->
+    ?_test(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"))
+    end).
+
+should_ensure_that_default_wasnt_modified(_, _) ->
+    ?_test(begin
+        ?assertEqual("5984",
+                     couch_config:get("httpd", "port")),
+        ?assertEqual("127.0.0.1",
+                     couch_config:get("httpd", "bind_address"))
+    end).
+
+should_ensure_that_written_to_last_config_in_chain(_, _) ->
+    ?_test(begin
+        ?assertEqual("8080",
+                     couch_config:get("httpd", "port")),
+        ?assertEqual(undefined,
+                     couch_config:get("httpd", "bind_address"))
+    end).

http://git-wip-us.apache.org/repos/asf/couchdb/blob/cfdcbac4/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/cfdcbac4/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/cfdcbac4/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/cfdcbac4/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/cfdcbac4/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 3a97b66..0000000
--- a/test/etap/081-config-override.t
+++ /dev/null
@@ -1,208 +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) ->
-    application:set_env(config, ini_files, IniFiles),
-    ok = application:start(config),
-    Tests(),
-    timer:sleep(1000),
-    ok = application:stop(config),
-    ok.
-
-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(
-            config:get("couchdb", "max_dbs_open"),
-            "100",
-            "{couchdb, max_dbs_open} is 100 by defualt."
-        ),
-
-        etap:is(
-            config:get("httpd","port"),
-            "5984",
-            "{httpd, port} is 5984 by default"
-        ),
-
-        etap:is(
-            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(
-            config:get("couchdb", "max_dbs_open"),
-            "10",
-            "{couchdb, max_dbs_open} was overriden with the value 10"
-        ),
-
-        etap:is(
-            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(
-            config:get("httpd", "port"),
-            "80",
-            "{httpd, port} is overriden with the value 80"
-        ),
-
-        etap:is(
-            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(
-            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(
-            config:get("httpd", "port"),
-            "5984",
-            "{httpd, port} is still 5984 by default"
-        ),
-
-        etap:is(
-            config:set("httpd", "port", "8080"),
-            ok,
-            "Writing {httpd, port} is kosher."
-        ),
-
-        etap:is(
-            config:get("httpd", "port"),
-            "8080",
-            "{httpd, port} was updated to 8080 successfully."
-        ),
-
-        etap:is(
-            config:delete("httpd", "bind_address"),
-            ok,
-            "Deleting {httpd, bind_address} succeeds"
-        ),
-
-        etap:is(
-            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(
-            config:get("httpd", "port"),
-            "5984",
-            "{httpd, port} was not persisted to the primary INI file."
-        ),
-
-        etap:is(
-            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(
-            config:get("httpd", "port"),
-            "8080",
-            "{httpd, port} is still 8080 after reopening the config."
-        ),
-
-        etap:is(
-            config:get("httpd", "bind_address"),
-            undefined,
-            "{httpd, bind_address} is still \"\" after reopening."
-        )
-    end,
-
-    run_tests([local_config_write()], CheckDidWrite),
-
-    ok.