summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Shorin <kxepal@apache.org>2014-06-03 14:10:25 +0400
committerAlexander Shorin <kxepal@apache.org>2015-12-02 03:51:26 +0300
commit21de05a8a0f974acfa977f92109d89a7b85365a3 (patch)
treefe4c2891b7171dc4020b885d3d01aa697c654c54
parentf3103f375e3c8215f0b79257f2e0dc40152e9da6 (diff)
downloadcouchdb-21de05a8a0f974acfa977f92109d89a7b85365a3.tar.gz
Port 171-os-daemons-config.t etap test suite to eunit
Simplify os_daemon_configer.escript There is no need to start couch_config, init code paths and include anything, just need to make ejson beams available.
-rw-r--r--.gitignore2
-rw-r--r--configure.ac2
-rw-r--r--test/couchdb/Makefile.am2
-rw-r--r--test/couchdb/couch_auth_cache_tests.erl40
-rw-r--r--test/couchdb/couchdb_os_daemons_tests.erl32
-rwxr-xr-xtest/couchdb/fixtures/os_daemon_configer.escript.in (renamed from test/etap/171-os-daemons-config.es)43
-rwxr-xr-xtest/etap/171-os-daemons-config.t74
-rw-r--r--test/etap/Makefile.am2
8 files changed, 73 insertions, 124 deletions
diff --git a/.gitignore b/.gitignore
index 96c995020..4789429b0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -128,6 +128,8 @@ src/snappy/snappy.app
stamp-h1
test/.deps/
test/couchdb/run
+test/couchdb/fixtures/.deps/
+test/couchdb/fixtures/os_daemon_configer.escript
test/couchdb/include/couch_eunit.hrl
test/etap/.deps/
test/etap/run
diff --git a/configure.ac b/configure.ac
index 3ae7dded3..42ea75a79 100644
--- a/configure.ac
+++ b/configure.ac
@@ -759,6 +759,8 @@ AC_CONFIG_FILES([src/ejson/Makefile])
AC_CONFIG_FILES([test/Makefile])
AC_CONFIG_FILES([test/couchdb/run])
AC_CONFIG_FILES([test/couchdb/Makefile])
+AC_CONFIG_FILES([test/couchdb/fixtures/Makefile])
+AC_CONFIG_FILES([test/couchdb/fixtures/os_daemon_configer.escript])
AC_CONFIG_FILES([test/couchdb/include/couch_eunit.hrl])
AC_CONFIG_FILES([test/etap/Makefile])
AC_CONFIG_FILES([test/etap/test_util.erl])
diff --git a/test/couchdb/Makefile.am b/test/couchdb/Makefile.am
index b568335fa..a1102bd5b 100644
--- a/test/couchdb/Makefile.am
+++ b/test/couchdb/Makefile.am
@@ -19,6 +19,7 @@ all:
-o $(top_builddir)/test/couchdb/ebin/ $(ERLC_FLAGS) ${TEST} \
$(top_srcdir)/test/couchdb/test_request.erl
chmod +x run
+ chmod +x $(top_builddir)/test/couchdb/fixtures/os_daemon_configer.escript
eunit_files = \
couch_auth_cache_tests.erl \
@@ -52,6 +53,7 @@ fixture_files = \
fixtures/couch_stats_aggregates.cfg \
fixtures/couch_stats_aggregates.ini \
fixtures/os_daemon_looper.escript \
+ fixtures/os_daemon_configer.escript \
fixtures/logo.png
EXTRA_DIST = \
diff --git a/test/couchdb/couch_auth_cache_tests.erl b/test/couchdb/couch_auth_cache_tests.erl
index 34f712742..3b2321caa 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).
diff --git a/test/couchdb/couchdb_os_daemons_tests.erl b/test/couchdb/couchdb_os_daemons_tests.erl
index 1f9f6be02..da9294e96 100644
--- a/test/couchdb/couchdb_os_daemons_tests.erl
+++ b/test/couchdb/couchdb_os_daemons_tests.erl
@@ -26,16 +26,24 @@
buf=[]
}).
+-define(DAEMON_CONFIGER, "os_daemon_configer.escript").
-define(DAEMON_LOOPER, "os_daemon_looper.escript").
-define(DELAY, 100).
+-define(FIXTURES_BUILDDIR,
+ filename:join([?BUILDDIR, "test", "couchdb", "fixtures"])).
-define(TIMEOUT, 1000).
setup(DName) ->
{ok, CfgPid} = couch_config:start_link(?CONFIG_CHAIN),
{ok, OsDPid} = couch_os_daemons:start_link(),
- couch_config:set("os_daemons", DName,
- filename:join([?FIXTURESDIR, DName]), false),
+ Path = case DName of
+ ?DAEMON_CONFIGER ->
+ filename:join([?FIXTURES_BUILDDIR, DName]);
+ _ ->
+ filename:join([?FIXTURESDIR, DName])
+ end,
+ couch_config:set("os_daemons", DName, Path, false),
timer:sleep(?DELAY), % sleep a bit to let daemon set kill flag
{CfgPid, OsDPid}.
@@ -75,6 +83,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 +152,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).
diff --git a/test/etap/171-os-daemons-config.es b/test/couchdb/fixtures/os_daemon_configer.escript.in
index b4a914e61..d2ecfa8ac 100755
--- a/test/etap/171-os-daemons-config.es
+++ b/test/couchdb/fixtures/os_daemon_configer.escript.in
@@ -1,19 +1,18 @@
#! /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.
-
-filename() ->
- list_to_binary(test_util:source_file("test/etap/171-os-daemons-config.es")).
+%% -*- erlang -*-
+%%! -DTEST -pa @abs_top_builddir@/src/ejson
+%%
+%% 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.
read() ->
case io:get_line('') of
@@ -42,14 +41,17 @@ log(Mesg, Level) ->
write([<<"log">>, Mesg, {[{<<"level">>, Level}]}]).
test_get_cfg1() ->
- FileName = filename(),
- {[{<<"foo">>, FileName}]} = get_cfg(<<"os_daemons">>).
+ Path = list_to_binary(?FILE),
+ FileName = list_to_binary(filename:basename(?FILE)),
+ {[{FileName, Path}]} = get_cfg(<<"os_daemons">>).
test_get_cfg2() ->
- FileName = filename(),
- FileName = get_cfg(<<"os_daemons">>, <<"foo">>),
+ 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">>).
@@ -79,7 +81,4 @@ loop({error, _Reason}) ->
init:stop().
main([]) ->
- test_util:init_code_path(),
- couch_config:start_link(test_util:config_files()),
- couch_drv:start_link(),
do_tests().
diff --git a/test/etap/171-os-daemons-config.t b/test/etap/171-os-daemons-config.t
deleted file mode 100755
index e9dc3f322..000000000
--- a/test/etap/171-os-daemons-config.t
+++ /dev/null
@@ -1,74 +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.
-
--record(daemon, {
- port,
- name,
- cmd,
- kill,
- status=running,
- cfg_patterns=[],
- errors=[],
- buf=[]
-}).
-
-config_files() ->
- lists:map(fun test_util:build_file/1, [
- "etc/couchdb/default_dev.ini"
- ]).
-
-daemon_cmd() ->
- test_util:source_file("test/etap/171-os-daemons-config.es").
-
-main(_) ->
- test_util:init_code_path(),
-
- etap:plan(6),
- 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_config:start_link(config_files()),
- couch_config:set("log", "level", "debug", false),
- couch_log:start_link(),
- couch_os_daemons:start_link(),
-
- % "foo" is a required name by this test.
- couch_config:set("os_daemons", "foo", daemon_cmd(), false),
- timer:sleep(1000),
-
- {ok, [D1]} = couch_os_daemons:info([table]),
- check_daemon(D1, "foo"),
-
- ok.
-
-check_daemon(D, Name) ->
- BaseName = "171-os-daemons-config.es",
- BaseLen = length(BaseName),
- CmdLen = length(D#daemon.cmd),
- CmdName = lists:sublist(D#daemon.cmd, CmdLen-BaseLen+1, BaseLen),
-
- etap:is(is_port(D#daemon.port), true, "Daemon port is a port."),
- etap:is(D#daemon.name, Name, "Daemon name was set correctly."),
- etap:is(CmdName, BaseName, "Command name was set correctly."),
- etap:isnt(D#daemon.kill, undefined, "Kill command was set."),
- etap:is(D#daemon.errors, [], "No errors occurred while booting."),
- etap:is(D#daemon.buf, [], "No extra data left in the buffer.").
diff --git a/test/etap/Makefile.am b/test/etap/Makefile.am
index 13b5b4a58..1ec6a4801 100644
--- a/test/etap/Makefile.am
+++ b/test/etap/Makefile.am
@@ -36,8 +36,6 @@ fixture_files = \
fixtures/test.couch
tap_files = \
- 171-os-daemons-config.es \
- 171-os-daemons-config.t \
172-os-daemon-errors.1.sh \
172-os-daemon-errors.2.sh \
172-os-daemon-errors.3.sh \