Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 92D7211D12 for ; Fri, 29 Aug 2014 20:43:05 +0000 (UTC) Received: (qmail 81053 invoked by uid 500); 29 Aug 2014 20:43:04 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 80815 invoked by uid 500); 29 Aug 2014 20:43:04 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 80277 invoked by uid 99); 29 Aug 2014 20:43:03 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 29 Aug 2014 20:43:03 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 985879A8D35; Fri, 29 Aug 2014 20:43:03 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: chewbranca@apache.org To: commits@couchdb.apache.org Date: Fri, 29 Aug 2014 20:43:18 -0000 Message-Id: <7baa5710904c4f7aab4d417943decb5a@git.apache.org> In-Reply-To: <455b2bf437ec4190a337b5785b95de93@git.apache.org> References: <455b2bf437ec4190a337b5785b95de93@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [16/50] [abbrv] couch commit: updated refs/heads/1963-eunit-bigcouch to 08c6f0b Port 171-os-daemons-config.t etap test suite to eunit Merged into couchdb_os_daemons_tests suite. Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/2c4f14f4 Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/2c4f14f4 Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/2c4f14f4 Branch: refs/heads/1963-eunit-bigcouch Commit: 2c4f14f49d6a8adefa3c424973def4983b254d6b Parents: 934d48d Author: Alexander Shorin Authored: Tue Jun 3 14:10:25 2014 +0400 Committer: Russell Branca Committed: Fri Aug 29 13:42:24 2014 -0700 ---------------------------------------------------------------------- test/couchdb/couch_auth_cache_tests.erl | 40 +++----- test/couchdb/couchdb_os_daemons_tests.erl | 21 ++++ .../couchdb/fixtures/os_daemon_configer.escript | 101 +++++++++++++++++++ 3 files changed, 138 insertions(+), 24 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/2c4f14f4/test/couchdb/couch_auth_cache_tests.erl ---------------------------------------------------------------------- diff --git a/test/couchdb/couch_auth_cache_tests.erl b/test/couchdb/couch_auth_cache_tests.erl index 34f7127..3b2321c 100644 --- a/test/couchdb/couch_auth_cache_tests.erl +++ b/test/couchdb/couch_auth_cache_tests.erl @@ -74,47 +74,43 @@ should_get_nil_on_missed_cache(_) -> ?_assertEqual(nil, couch_auth_cache:get_user_creds("joe")). should_get_right_password_hash(DbName) -> - ?_assert(begin + ?_test(begin PasswordHash = hash_password("pass1"), {ok, _} = update_user_doc(DbName, "joe", "pass1"), Creds = couch_auth_cache:get_user_creds("joe"), ?assertEqual(PasswordHash, - couch_util:get_value(<<"password_sha">>, Creds)), - true + couch_util:get_value(<<"password_sha">>, Creds)) end). should_ensure_doc_hash_equals_cached_one(DbName) -> - ?_assert(begin + ?_test(begin {ok, _} = update_user_doc(DbName, "joe", "pass1"), Creds = couch_auth_cache:get_user_creds("joe"), CachedHash = couch_util:get_value(<<"password_sha">>, Creds), StoredHash = get_user_doc_password_sha(DbName, "joe"), - ?assertEqual(StoredHash, CachedHash), - true + ?assertEqual(StoredHash, CachedHash) end). should_update_password(DbName) -> - ?_assert(begin + ?_test(begin PasswordHash = hash_password("pass2"), {ok, Rev} = update_user_doc(DbName, "joe", "pass1"), {ok, _} = update_user_doc(DbName, "joe", "pass2", Rev), Creds = couch_auth_cache:get_user_creds("joe"), ?assertEqual(PasswordHash, - couch_util:get_value(<<"password_sha">>, Creds)), - true + couch_util:get_value(<<"password_sha">>, Creds)) end). should_cleanup_cache_after_userdoc_deletion(DbName) -> - ?_assert(begin + ?_test(begin {ok, _} = update_user_doc(DbName, "joe", "pass1"), delete_user_doc(DbName, "joe"), - ?assertEqual(nil, couch_auth_cache:get_user_creds("joe")), - true + ?assertEqual(nil, couch_auth_cache:get_user_creds("joe")) end). should_restore_cache_after_userdoc_recreation(DbName) -> - ?_assert(begin + ?_test(begin PasswordHash = hash_password("pass5"), {ok, _} = update_user_doc(DbName, "joe", "pass1"), delete_user_doc(DbName, "joe"), @@ -124,22 +120,20 @@ should_restore_cache_after_userdoc_recreation(DbName) -> Creds = couch_auth_cache:get_user_creds("joe"), ?assertEqual(PasswordHash, - couch_util:get_value(<<"password_sha">>, Creds)), - true + couch_util:get_value(<<"password_sha">>, Creds)) end). should_drop_cache_on_auth_db_change(DbName) -> - ?_assert(begin + ?_test(begin {ok, _} = update_user_doc(DbName, "joe", "pass1"), full_commit(DbName), couch_config:set("couch_httpd_auth", "authentication_db", ?b2l(?tempdb()), false), - ?assertEqual(nil, couch_auth_cache:get_user_creds("joe")), - true + ?assertEqual(nil, couch_auth_cache:get_user_creds("joe")) end). should_restore_cache_on_auth_db_change(DbName) -> - ?_assert(begin + ?_test(begin PasswordHash = hash_password("pass1"), {ok, _} = update_user_doc(DbName, "joe", "pass1"), Creds = couch_auth_cache:get_user_creds("joe"), @@ -157,20 +151,18 @@ should_restore_cache_on_auth_db_change(DbName) -> Creds = couch_auth_cache:get_user_creds("joe"), ?assertEqual(PasswordHash, - couch_util:get_value(<<"password_sha">>, Creds)), - true + couch_util:get_value(<<"password_sha">>, Creds)) end). should_recover_cache_after_shutdown(DbName) -> - ?_assert(begin + ?_test(begin PasswordHash = hash_password("pass2"), {ok, Rev0} = update_user_doc(DbName, "joe", "pass1"), {ok, Rev1} = update_user_doc(DbName, "joe", "pass2", Rev0), full_commit(DbName), shutdown_db(DbName), {ok, Rev1} = get_doc_rev(DbName, "joe"), - ?assertEqual(PasswordHash, get_user_doc_password_sha(DbName, "joe")), - true + ?assertEqual(PasswordHash, get_user_doc_password_sha(DbName, "joe")) end). http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/2c4f14f4/test/couchdb/couchdb_os_daemons_tests.erl ---------------------------------------------------------------------- diff --git a/test/couchdb/couchdb_os_daemons_tests.erl b/test/couchdb/couchdb_os_daemons_tests.erl index 1f9f6be..dd07e82 100644 --- a/test/couchdb/couchdb_os_daemons_tests.erl +++ b/test/couchdb/couchdb_os_daemons_tests.erl @@ -26,6 +26,7 @@ buf=[] }). +-define(DAEMON_CONFIGER, "os_daemon_configer.escript"). -define(DAEMON_LOOPER, "os_daemon_looper.escript"). -define(DELAY, 100). -define(TIMEOUT, 1000). @@ -75,6 +76,17 @@ os_daemons_test_() -> } }. +configuration_reader_test_() -> + { + "OS Daemon requests CouchDB configuration", + { + foreachx, + fun setup/1, fun teardown/2, + [{?DAEMON_CONFIGER, + fun should_read_write_config_settings_by_daemon/2}] + } + }. + should_check_daemon(DName, _) -> ?_test(begin @@ -133,6 +145,15 @@ should_keep_alive_one_daemon_on_killing_other(DName, _) -> check_daemon(T, DName) end). +should_read_write_config_settings_by_daemon(DName, _) -> + ?_test(begin + % have to wait till daemon run all his tests + % see daemon's script for more info + timer:sleep(?TIMEOUT), + {ok, [D]} = couch_os_daemons:info([table]), + check_daemon(D, DName) + end). + check_daemon(D) -> check_daemon(D, D#daemon.name). http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/2c4f14f4/test/couchdb/fixtures/os_daemon_configer.escript ---------------------------------------------------------------------- diff --git a/test/couchdb/fixtures/os_daemon_configer.escript b/test/couchdb/fixtures/os_daemon_configer.escript new file mode 100755 index 0000000..d437423 --- /dev/null +++ b/test/couchdb/fixtures/os_daemon_configer.escript @@ -0,0 +1,101 @@ +#! /usr/bin/env escript + +% 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. + +-include("../couch_eunit.hrl"). + + +read() -> + case io:get_line('') of + eof -> + stop; + Data -> + ejson:decode(Data) + end. + +write(Mesg) -> + Data = iolist_to_binary(ejson:encode(Mesg)), + io:format(binary_to_list(Data) ++ "\n", []). + +get_cfg(Section) -> + write([<<"get">>, Section]), + read(). + +get_cfg(Section, Name) -> + write([<<"get">>, Section, Name]), + read(). + +log(Mesg) -> + write([<<"log">>, Mesg]). + +log(Mesg, Level) -> + write([<<"log">>, Mesg, {[{<<"level">>, Level}]}]). + +test_get_cfg1() -> + Path = list_to_binary(?FILE), + FileName = list_to_binary(filename:basename(?FILE)), + {[{FileName, Path}]} = get_cfg(<<"os_daemons">>). + +test_get_cfg2() -> + Path = list_to_binary(?FILE), + FileName = list_to_binary(filename:basename(?FILE)), + Path = get_cfg(<<"os_daemons">>, FileName), + <<"sequential">> = get_cfg(<<"uuids">>, <<"algorithm">>). + + +test_get_unknown_cfg() -> + {[]} = get_cfg(<<"aal;3p4">>), + null = get_cfg(<<"aal;3p4">>, <<"313234kjhsdfl">>). + +test_log() -> + log(<<"foobar!">>), + log(<<"some stuff!">>, <<"debug">>), + log(2), + log(true), + write([<<"log">>, <<"stuff">>, 2]), + write([<<"log">>, 3, null]), + write([<<"log">>, [1, 2], {[{<<"level">>, <<"debug">>}]}]), + write([<<"log">>, <<"true">>, {[]}]). + +do_tests() -> + test_get_cfg1(), + test_get_cfg2(), + test_get_unknown_cfg(), + test_log(), + loop(io:read("")). + +loop({ok, _}) -> + loop(io:read("")); +loop(eof) -> + init:stop(); +loop({error, _Reason}) -> + init:stop(). + +main([]) -> + init_code_path(), + couch_config:start_link(?CONFIG_CHAIN), + couch_drv:start_link(), + do_tests(). + +init_code_path() -> + Paths = [ + "couchdb", + "ejson", + "erlang-oauth", + "ibrowse", + "mochiweb", + "snappy" + ], + lists:foreach(fun(Name) -> + code:add_patha(filename:join([?BUILDDIR, "src", Name])) + end, Paths).