summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMickael Remond <mremond@process-one.net>2016-03-31 22:01:57 +0200
committerMickael Remond <mremond@process-one.net>2016-03-31 22:01:57 +0200
commit97d345d2877dcac10f81642d8ba09a39a4e787f8 (patch)
tree7f6ead7012edc436d46a86d9f4bb3b0e883b25c4 /test
parentFix failing tests (diff)
Port mod_admin_extra test to work with new API
Diffstat (limited to 'test')
-rw-r--r--test/ejabberd_auth_mock.exs23
-rw-r--r--test/elixir_SUITE.erl7
-rw-r--r--test/mod_admin_extra_test.exs18
-rw-r--r--test/mod_last_mock.exs40
-rw-r--r--test/mod_roster_mock.exs28
5 files changed, 86 insertions, 30 deletions
diff --git a/test/ejabberd_auth_mock.exs b/test/ejabberd_auth_mock.exs
index 495c527f..bbe90514 100644
--- a/test/ejabberd_auth_mock.exs
+++ b/test/ejabberd_auth_mock.exs
@@ -1,5 +1,22 @@
- # ejabberd_auth mock
- ######################
+# ----------------------------------------------------------------------
+#
+# ejabberd, Copyright (C) 2002-2016 ProcessOne
+#
+# 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 EjabberdAuthMock do
@@ -24,7 +41,7 @@ defmodule EjabberdAuthMock do
Agent.get(@agent, fn users -> Map.get(users, {user, domain}, "") end )
end)
mock(:ejabberd_auth, :check_password,
- fn (user, domain, password) ->
+ fn (user, authzid, domain, password) ->
Agent.get(@agent, fn users ->
Map.get(users, {user, domain}) end) == password
end)
diff --git a/test/elixir_SUITE.erl b/test/elixir_SUITE.erl
index f92f750a..2d8c3c52 100644
--- a/test/elixir_SUITE.erl
+++ b/test/elixir_SUITE.erl
@@ -69,6 +69,13 @@ run_elixir_test(Func) ->
%% Elixir tests can be tagged as follow to be ignored (place before test start)
%% @tag pending: true
'Elixir.ExUnit':start([{exclude, [{pending, true}]}]),
+
+ filelib:fold_files(test_dir(), ".*mock\.exs\$", true,
+ fun (File, N) ->
+ 'Elixir.Code':load_file(list_to_binary(File)),
+ N+1
+ end, 0),
+
'Elixir.Code':load_file(list_to_binary(filename:join(test_dir(), atom_to_list(Func)))),
%% I did not use map syntax, so that this file can still be build under R16
ResultMap = 'Elixir.ExUnit':run(),
diff --git a/test/mod_admin_extra_test.exs b/test/mod_admin_extra_test.exs
index 7fa39eef..d90aa045 100644
--- a/test/mod_admin_extra_test.exs
+++ b/test/mod_admin_extra_test.exs
@@ -21,6 +21,8 @@
defmodule EjabberdModAdminExtraTest do
use ExUnit.Case, async: false
+ require EjabberdAuthMock
+
@author "jsautret@process-one.net"
@user "user"
@@ -29,11 +31,11 @@ defmodule EjabberdModAdminExtraTest do
@resource "resource"
require Record
- Record.defrecord :jid, Record.extract(:jid,
- from: "jlib.hrl")
+ Record.defrecord :jid, Record.extract(:jid, from_lib: "ejabberd/include/jlib.hrl")
setup_all do
try do
+ :jid.start
:stringprep.start
:mnesia.start
:p1_sha.load_nif
@@ -71,13 +73,13 @@ defmodule EjabberdModAdminExtraTest do
EjabberdAuthMock.create_user @user, @domain, @password
assert :ejabberd_commands.execute_command(:check_password,
- [@user, @domain, @password])
+ [@user, <<"">>, @domain, @password])
refute :ejabberd_commands.execute_command(:check_password,
- [@user, @domain, "bad_password"])
+ [@user, <<"">>, @domain, "bad_password"])
refute :ejabberd_commands.execute_command(:check_password,
- [@user, "bad_domain", @password])
+ [@user, <<"">>, "bad_domain", @password])
refute :ejabberd_commands.execute_command(:check_password,
- ["bad_user", @domain, @password])
+ ["bad_user", <<"">>, @domain, @password])
assert :meck.validate :ejabberd_auth
@@ -115,9 +117,9 @@ defmodule EjabberdModAdminExtraTest do
assert :ejabberd_commands.execute_command(:change_password,
[@user, @domain, "new_password"])
refute :ejabberd_commands.execute_command(:check_password,
- [@user, @domain, @password])
+ [@user, <<"">>, @domain, @password])
assert :ejabberd_commands.execute_command(:check_password,
- [@user, @domain, "new_password"])
+ [@user, <<"">>, @domain, "new_password"])
assert {:not_found, 'unknown_user'} ==
catch_throw :ejabberd_commands.execute_command(:change_password,
["bad_user", @domain,
diff --git a/test/mod_last_mock.exs b/test/mod_last_mock.exs
index 7e3dc5a1..4f8da366 100644
--- a/test/mod_last_mock.exs
+++ b/test/mod_last_mock.exs
@@ -1,15 +1,29 @@
- # mod_last mock
- ######################
-
+# ----------------------------------------------------------------------
+#
+# ejabberd, Copyright (C) 2002-2016 ProcessOne
+#
+# 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 ModLastMock do
require Record
- Record.defrecord :session, Record.extract(:session,
- from: "ejabberd_sm.hrl")
- Record.defrecord :jid, Record.extract(:jid,
- from: "jlib.hrl")
-
+ Record.defrecord :session, Record.extract(:session, from_lib: "ejabberd/include/ejabberd_sm.hrl")
+ Record.defrecord :jid, Record.extract(:jid, from_lib: "ejabberd/include/jlib.hrl")
+
@author "jsautret@process-one.net"
@agent __MODULE__
@@ -19,9 +33,9 @@ defmodule ModLastMock do
catch
:exit, _e -> :ok
end
-
+
{:ok, _pid} = Agent.start_link(fn -> %{} end, name: @agent)
-
+
mock(:mod_last, :get_last_info,
fn (user, domain) ->
Agent.get(@agent, fn last ->
@@ -32,11 +46,11 @@ defmodule ModLastMock do
end)
end)
end
-
+
def set_last(user, domain, status) do
set_last(user, domain, status, now)
end
-
+
def set_last(user, domain, status, timestamp) do
Agent.update(@agent, fn last ->
Map.put(last, {user, domain}, {timestamp, status})
@@ -50,7 +64,7 @@ defmodule ModLastMock do
{megasecs, secs, _microsecs} = :os.timestamp
megasecs * 1000000 + secs
end
-
+
# TODO refactor: Move to ejabberd_test_mock
def mock(module, function, fun) do
try do
diff --git a/test/mod_roster_mock.exs b/test/mod_roster_mock.exs
index b4991cfd..b1251ba8 100644
--- a/test/mod_roster_mock.exs
+++ b/test/mod_roster_mock.exs
@@ -1,12 +1,28 @@
- # mod_roster mock
- ######################
+# ----------------------------------------------------------------------
+#
+# ejabberd, Copyright (C) 2002-2016 ProcessOne
+#
+# 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 ModRosterMock do
@author "jsautret@process-one.net"
require Record
- Record.defrecord :roster, Record.extract(:roster,
- from: "mod_roster.hrl")
+ Record.defrecord :roster, Record.extract(:roster, from_lib: "ejabberd/include/mod_roster.hrl")
@agent __MODULE__
@@ -75,7 +91,7 @@ defmodule ModRosterMock do
:moka.replace(roster_mock, :del_roster_t,
fn (user, domain, jid) ->
- remove_roster_item(user, domain, :jlib.jid_to_string(jid))
+ remove_roster_item(user, domain, :jid.to_string(jid))
end)
:moka.load(roster_mock)
@@ -163,7 +179,7 @@ defmodule ModRosterMock do
def to_record({{user, domain, jid}, r}) do
roster(usj: {user, domain, jid},
us: {user, domain},
- jid: :jlib.string_to_usr(jid),
+ jid: :jid.from_string(jid),
subscription: r.subs,
ask: r.ask,
groups: r.groups,