Skip to content

Commit

Permalink
Merge pull request #111 from esl/bugfix-get-loglevel
Browse files Browse the repository at this point in the history
Test `mongooseimctl get_loglevel` command
  • Loading branch information
michalwski committed Feb 3, 2015
2 parents 862db1d + dda9774 commit 30ed7be
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions tests/ejabberdctl_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
-include_lib("escalus/include/escalus.hrl").
-include_lib("common_test/include/ct.hrl").
-include_lib("exml/include/exml.hrl").
-include_lib("eunit/include/eunit.hrl").

-define(i2l(I), integer_to_list(I)).
-define(a2l(A), atom_to_list(A)).
-define(eq(Expected, Actual), ?assertEqual(Expected, Actual)).

-import(mongoose_helper, [auth_modules/0]).

Expand All @@ -40,7 +45,8 @@ all() ->
{group, last},
{group, private},
{group, stanza},
{group, stats}
{group, stats},
{group, maintenance}
]
end.

Expand All @@ -53,7 +59,8 @@ groups() ->
{last, [sequence], last()},
{private, [sequence], private()},
{stanza, [sequence], stanza()},
{stats, [sequence], stats()}
{stats, [sequence], stats()},
{maintenance, [sequence], maintenance()}
].

accounts() -> [change_password, check_password_hash, check_password,
Expand All @@ -76,6 +83,8 @@ stanza() -> [send_message, send_stanza].

stats() -> [stats_global, stats_host].

maintenance() -> [loglevels].

suite() ->
escalus:suite().

Expand Down Expand Up @@ -592,6 +601,32 @@ stats_host(Config) ->
{"0\n", 0} = ejabberdctl("stats_host", ["onlineusers", SecDomain], Config)
end).

%%-----------------------------------------------------------------
%% mongooseimctl maintenance commands (start, started, stop, ...)
%%-----------------------------------------------------------------

loglevels(C) ->
%% setup
NC = escalus_ejabberd:setup_option(server_loglevel(), C),
try
[ loglevel(C, Level, Atom)
|| {Level, Atom} <- [{0, none},
{1, critical},
{2, error},
{3, warning},
{4, info},
{5, debug}] ]
after
%% cleanup
escalus_ejabberd:reset_option(server_loglevel(), NC)
end.

loglevel(C, Level, Atom) ->
Control = escalus_config:get_config(ctl_path, C),
ok = escalus_ejabberd:rpc(ejabberd_loglevel, set, [Level]),
Result = os:cmd([Control, " ", "get_loglevel"]),
?eq(textual_loglevel(Level, Atom), Result).

%%-----------------------------------------------------------------
%% Helpers
%%-----------------------------------------------------------------
Expand Down Expand Up @@ -709,3 +744,12 @@ match_roster(ItemsValid, Items) ->
false
end, ItemsTokens)
end, ItemsValid).

textual_loglevel(Level, Atom) ->
lists:flatten([?i2l(Level), $\t, ?a2l(Atom), $\n]).

server_loglevel() ->
{server_loglevel,
fun () -> element(1, escalus_ejabberd:rpc(ejabberd_loglevel, get, [])) end,
fun (Level) -> escalus_ejabberd:rpc(ejabberd_loglevel, set, [Level]) end,
4}.

0 comments on commit 30ed7be

Please sign in to comment.