aboutsummaryrefslogtreecommitdiff
path: root/test/ejabberd_sm_mock.exs
diff options
context:
space:
mode:
Diffstat (limited to 'test/ejabberd_sm_mock.exs')
-rw-r--r--test/ejabberd_sm_mock.exs45
1 files changed, 30 insertions, 15 deletions
diff --git a/test/ejabberd_sm_mock.exs b/test/ejabberd_sm_mock.exs
index 0c2fc1635..53c2c750f 100644
--- a/test/ejabberd_sm_mock.exs
+++ b/test/ejabberd_sm_mock.exs
@@ -1,15 +1,30 @@
- # ejabberd_sm 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 EjabberdSmMock do
@author "jsautret@process-one.net"
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")
+
@agent __MODULE__
def init do
@@ -20,9 +35,9 @@ defmodule EjabberdSmMock do
catch
:exit, _e -> :ok
end
-
+
{:ok, _pid} = Agent.start_link(fn -> [] end, name: @agent)
-
+
mock(:ejabberd_sm, :get_user_resources,
fn (user, domain) -> for s <- get_sessions(user, domain), do: s.resource end)
@@ -35,9 +50,9 @@ defmodule EjabberdSmMock do
:ok
(_, _, _) -> :ok
end)
-
+
end
-
+
def connect_resource(user, domain, resource,
opts \\ [priority: 1, conn: :c2s]) do
Agent.update(@agent, fn sessions ->
@@ -54,13 +69,13 @@ defmodule EjabberdSmMock do
end
def disconnect_resource(user, domain, resource, timestamp) do
- Agent.update(@agent, fn sessions ->
+ Agent.update(@agent, fn sessions ->
for s <- sessions,
s.user != user or s.domain != domain or s.resource != resource, do: s
end)
ModLastMock.set_last user, domain, "", timestamp
end
-
+
def get_sessions() do
Agent.get(@agent, fn sessions -> sessions end)
end
@@ -77,7 +92,7 @@ defmodule EjabberdSmMock do
s.user == user, s.domain == domain, s.resource == resource, do: s
end)
end
-
+
def to_record(s) do
session(usr: {s.user, s.domain, s.ressource},
us: {s.user, s.domain},
@@ -91,7 +106,7 @@ defmodule EjabberdSmMock do
# Helpers
####################################################################
-
+
# TODO refactor: Move to ejabberd_test_mock
def mock(module, function, fun) do
try do