aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2013-05-18 17:14:30 +0100
committerMatthew Wild <mwild1@gmail.com>2013-05-18 17:14:30 +0100
commite491b17e6f0187c419ac9a4d7178d9b1b9ac88be (patch)
treef39ac325409c6e76318d8a769f8217332e16f1d1 /tests
parent62a1d8a2d312c61673f868878efdcb747c63f772 (diff)
downloadprosody-e491b17e6f0187c419ac9a4d7178d9b1b9ac88be.tar.gz
prosody-e491b17e6f0187c419ac9a4d7178d9b1b9ac88be.zip
tests: Some much-needed cleanup...
Diffstat (limited to 'tests')
-rw-r--r--tests/test.lua16
-rw-r--r--tests/test_core_modulemanager.lua48
-rw-r--r--tests/test_core_s2smanager.lua3
-rw-r--r--tests/test_util_http.lua (renamed from tests/test_net_http.lua)0
-rw-r--r--tests/test_util_ip.lua7
-rw-r--r--tests/test_util_rfc6724.lua (renamed from tests/test_util_rfc3484.lua)0
6 files changed, 21 insertions, 53 deletions
diff --git a/tests/test.lua b/tests/test.lua
index db727ce1..b6728061 100644
--- a/tests/test.lua
+++ b/tests/test.lua
@@ -12,12 +12,12 @@ function run_all_tests()
package.loaded["net.connlisteners"] = { get = function () return {} end };
dotest "util.jid"
dotest "util.multitable"
- dotest "util.rfc3484"
- dotest "net.http"
- dotest "core.modulemanager"
+ dotest "util.rfc6724"
+ dotest "util.http"
dotest "core.stanza_router"
dotest "core.s2smanager"
dotest "core.configmanager"
+ dotest "util.ip"
dotest "util.stanza"
dotest "util.sasl.scram"
@@ -136,15 +136,21 @@ function dotest(unitname)
end
local oldmodule, old_M = _fakeG.module, _fakeG._M;
- _fakeG.module = function () _M = _G end
+ _fakeG.module = function () _M = unit end
setfenv(chunk, unit);
- local success, err = pcall(chunk);
+ local success, ret = pcall(chunk);
_fakeG.module, _fakeG._M = oldmodule, old_M;
if not success then
print("WARNING: ", "Failed to initialise module: "..unitname, err);
return;
end
+ if type(ret) == "table" then
+ for k,v in pairs(ret) do
+ unit[k] = v;
+ end
+ end
+
for name, f in pairs(unit) do
local test = rawget(tests, name);
if type(f) ~= "function" then
diff --git a/tests/test_core_modulemanager.lua b/tests/test_core_modulemanager.lua
deleted file mode 100644
index 9498875a..00000000
--- a/tests/test_core_modulemanager.lua
+++ /dev/null
@@ -1,48 +0,0 @@
--- Prosody IM
--- Copyright (C) 2008-2010 Matthew Wild
--- Copyright (C) 2008-2010 Waqas Hussain
---
--- This project is MIT/X11 licensed. Please see the
--- COPYING file in the source package for more information.
---
-
-local config = require "core.configmanager";
-local helpers = require "util.helpers";
-local set = require "util.set";
-
-function load_modules_for_host(load_modules_for_host, mm)
- local test_num = 0;
- local function test_load(global_modules_enabled, global_modules_disabled, host_modules_enabled, host_modules_disabled, expected_modules)
- test_num = test_num + 1;
- -- Prepare
- hosts = { ["example.com"] = {} };
- config.set("*", "core", "modules_enabled", global_modules_enabled);
- config.set("*", "core", "modules_disabled", global_modules_disabled);
- config.set("example.com", "core", "modules_enabled", host_modules_enabled);
- config.set("example.com", "core", "modules_disabled", host_modules_disabled);
-
- expected_modules = set.new(expected_modules);
- expected_modules:add_list(helpers.get_upvalue(load_modules_for_host, "autoload_modules"));
-
- local loaded_modules = set.new();
- function mm.load(host, module)
- assert_equal(host, "example.com", test_num..": Host isn't example.com but "..tostring(host));
- assert_equal(expected_modules:contains(module), true, test_num..": Loading unexpected module '"..tostring(module).."'");
- loaded_modules:add(module);
- end
- load_modules_for_host("example.com");
- assert_equal((expected_modules - loaded_modules):empty(), true, test_num..": Not all modules loaded: "..tostring(expected_modules - loaded_modules));
- end
-
- test_load({ "one", "two", "three" }, nil, nil, nil, { "one", "two", "three" });
- test_load({ "one", "two", "three" }, {}, nil, nil, { "one", "two", "three" });
- test_load({ "one", "two", "three" }, { "two" }, nil, nil, { "one", "three" });
- test_load({ "one", "two", "three" }, { "three" }, nil, nil, { "one", "two" });
- test_load({ "one", "two", "three" }, nil, nil, { "three" }, { "one", "two" });
- test_load({ "one", "two", "three" }, nil, { "three" }, { "three" }, { "one", "two", "three" });
-
- test_load({ "one", "two" }, nil, { "three" }, nil, { "one", "two", "three" });
- test_load({ "one", "two", "three" }, nil, { "three" }, nil, { "one", "two", "three" });
- test_load({ "one", "two", "three" }, { "three" }, { "three" }, nil, { "one", "two", "three" });
- test_load({ "one", "two" }, { "three" }, { "three" }, nil, { "one", "two", "three" });
-end
diff --git a/tests/test_core_s2smanager.lua b/tests/test_core_s2smanager.lua
index b49c7da6..7194d201 100644
--- a/tests/test_core_s2smanager.lua
+++ b/tests/test_core_s2smanager.lua
@@ -6,6 +6,9 @@
-- COPYING file in the source package for more information.
--
+env = {
+ prosody = { events = require "util.events".new() };
+};
function compare_srv_priorities(csp)
local r1 = { priority = 10, weight = 0 }
diff --git a/tests/test_net_http.lua b/tests/test_util_http.lua
index e68f96e9..e68f96e9 100644
--- a/tests/test_net_http.lua
+++ b/tests/test_util_http.lua
diff --git a/tests/test_util_ip.lua b/tests/test_util_ip.lua
new file mode 100644
index 00000000..ce7c397f
--- /dev/null
+++ b/tests/test_util_ip.lua
@@ -0,0 +1,7 @@
+
+function test_match(match_ip)
+ assert(match_ip("10.20.30.40", "10.0.0.0/8"));
+ assert(match_ip("80.244.94.84", "80.244.94.84"));
+ assert(match_ip("8.8.8.8", "8.8.0.0/16"));
+ assert(match_ip("8.8.4.4", "8.8.0.0/16"));
+end
diff --git a/tests/test_util_rfc3484.lua b/tests/test_util_rfc6724.lua
index 18ae310e..18ae310e 100644
--- a/tests/test_util_rfc3484.lua
+++ b/tests/test_util_rfc6724.lua