From dda9774220ccb1ae54333039aa191a79359e40d9 Mon Sep 17 00:00:00 2001 From: Radek Szymczyszyn Date: Mon, 2 Feb 2015 16:26:04 +0100 Subject: [PATCH] Test `mongooseimctl get_loglevel` command --- tests/ejabberdctl_SUITE.erl | 48 +++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/tests/ejabberdctl_SUITE.erl b/tests/ejabberdctl_SUITE.erl index 2e07138..95c4bf4 100644 --- a/tests/ejabberdctl_SUITE.erl +++ b/tests/ejabberdctl_SUITE.erl @@ -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]). @@ -40,7 +45,8 @@ all() -> {group, last}, {group, private}, {group, stanza}, - {group, stats} + {group, stats}, + {group, maintenance} ] end. @@ -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, @@ -76,6 +83,8 @@ stanza() -> [send_message, send_stanza]. stats() -> [stats_global, stats_host]. +maintenance() -> [loglevels]. + suite() -> escalus:suite(). @@ -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 %%----------------------------------------------------------------- @@ -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}.