2016-03-31 13:53:31 +02:00
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
#
|
2017-01-03 15:58:52 +01:00
|
|
|
# ejabberd, Copyright (C) 2002-2017 ProcessOne
|
2016-03-31 13:53:31 +02:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License as
|
|
|
|
# published by the Free Software Foundation; either version 2 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
#
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
defmodule EjabberdAdminTest do
|
|
|
|
use ExUnit.Case, async: false
|
|
|
|
|
|
|
|
@author "jsautret@process-one.net"
|
|
|
|
|
|
|
|
setup_all do
|
|
|
|
:mnesia.start
|
2017-07-06 17:19:05 +02:00
|
|
|
:ejabberd_mnesia.start
|
2016-03-31 13:53:31 +02:00
|
|
|
# For some myterious reason, :ejabberd_commands.init mays
|
|
|
|
# sometimes fails if module is not loaded before
|
|
|
|
{:module, :ejabberd_commands} = Code.ensure_loaded(:ejabberd_commands)
|
2017-07-06 17:19:05 +02:00
|
|
|
:ejabberd_hooks.start_link
|
|
|
|
{:ok, _} = :acl.start_link
|
2016-10-05 13:54:29 +02:00
|
|
|
{:ok, _} = :ejabberd_access_permissions.start_link()
|
2017-07-06 17:19:05 +02:00
|
|
|
:ejabberd_commands.start_link
|
|
|
|
:ejabberd_admin.start_link
|
2016-03-31 13:53:31 +02:00
|
|
|
:ok
|
|
|
|
end
|
|
|
|
|
|
|
|
setup do
|
|
|
|
:ok
|
|
|
|
end
|
|
|
|
|
|
|
|
test "Logvel can be set and retrieved" do
|
|
|
|
:ejabberd_logger.start()
|
|
|
|
|
2017-07-06 17:19:05 +02:00
|
|
|
assert :lager == call_command(:set_loglevel, [1])
|
2016-03-31 13:53:31 +02:00
|
|
|
assert {1, :critical, 'Critical'} ==
|
2017-07-06 17:19:05 +02:00
|
|
|
call_command(:get_loglevel, [])
|
2016-03-31 13:53:31 +02:00
|
|
|
|
2017-07-06 17:19:05 +02:00
|
|
|
assert :lager == call_command(:set_loglevel, [2])
|
2016-03-31 13:53:31 +02:00
|
|
|
assert {2, :error, 'Error'} ==
|
2017-07-06 17:19:05 +02:00
|
|
|
call_command(:get_loglevel, [])
|
2016-03-31 13:53:31 +02:00
|
|
|
|
2017-07-06 17:19:05 +02:00
|
|
|
assert :lager == call_command(:set_loglevel, [3])
|
2016-03-31 13:53:31 +02:00
|
|
|
assert {3, :warning, 'Warning'} ==
|
2017-07-06 17:19:05 +02:00
|
|
|
call_command(:get_loglevel, [])
|
2016-03-31 13:53:31 +02:00
|
|
|
|
|
|
|
assert {:wrong_loglevel, 6} ==
|
2017-07-06 17:19:05 +02:00
|
|
|
catch_throw call_command(:set_loglevel, [6])
|
2016-03-31 13:53:31 +02:00
|
|
|
assert {3, :warning, 'Warning'} ==
|
2017-07-06 17:19:05 +02:00
|
|
|
call_command(:get_loglevel, [])
|
2016-03-31 13:53:31 +02:00
|
|
|
|
2017-07-06 17:19:05 +02:00
|
|
|
assert :lager == call_command(:set_loglevel, [4])
|
2016-03-31 13:53:31 +02:00
|
|
|
assert {4, :info, 'Info'} ==
|
2017-07-06 17:19:05 +02:00
|
|
|
call_command(:get_loglevel, [])
|
2016-03-31 13:53:31 +02:00
|
|
|
|
2017-07-06 17:19:05 +02:00
|
|
|
assert :lager == call_command(:set_loglevel, [5])
|
2016-03-31 13:53:31 +02:00
|
|
|
assert {5, :debug, 'Debug'} ==
|
2017-07-06 17:19:05 +02:00
|
|
|
call_command(:get_loglevel, [])
|
2016-03-31 13:53:31 +02:00
|
|
|
|
2017-07-06 17:19:05 +02:00
|
|
|
assert :lager == call_command(:set_loglevel, [0])
|
2016-03-31 13:53:31 +02:00
|
|
|
assert {0, :no_log, 'No log'} ==
|
2017-07-06 17:19:05 +02:00
|
|
|
call_command(:get_loglevel, [])
|
2016-03-31 13:53:31 +02:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2017-07-06 17:19:05 +02:00
|
|
|
defp call_command(name, args) do
|
|
|
|
:ejabberd_commands.execute_command2(name, args, %{:caller_module => :ejabberd_ctl})
|
|
|
|
end
|
|
|
|
|
2016-03-31 13:53:31 +02:00
|
|
|
test "command status works with ejabberd stopped" do
|
|
|
|
assert :ejabberd_not_running ==
|
2017-07-06 17:19:05 +02:00
|
|
|
elem(call_command(:status, []), 0)
|
2016-03-31 13:53:31 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|