diff options
author | Matthew Wild <mwild1@gmail.com> | 2009-10-16 22:13:54 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2009-10-16 22:13:54 +0100 |
commit | 8bfd53c8a6522257ecd397491990ab9158eb8b44 (patch) | |
tree | 6943a2606fb9a36e11b4d1b03af1e1f3233abdb2 | |
parent | 6c0b6f76fbc3df0a1d80754fd69729de4acfe347 (diff) | |
download | prosody-8bfd53c8a6522257ecd397491990ab9158eb8b44.tar.gz prosody-8bfd53c8a6522257ecd397491990ab9158eb8b44.zip |
tests: Add tests for new modulemanager load_modules_for_host code
-rw-r--r-- | tests/test.lua | 1 | ||||
-rw-r--r-- | tests/test_core_modulemanager.lua | 48 |
2 files changed, 49 insertions, 0 deletions
diff --git a/tests/test.lua b/tests/test.lua index f5bcb02e..0cec6cba 100644 --- a/tests/test.lua +++ b/tests/test.lua @@ -11,6 +11,7 @@ function run_all_tests() dotest "util.jid" dotest "util.multitable" + dotest "core.modulemanager" dotest "core.stanza_router" dotest "core.s2smanager" dotest "core.configmanager" diff --git a/tests/test_core_modulemanager.lua b/tests/test_core_modulemanager.lua new file mode 100644 index 00000000..82e9aa45 --- /dev/null +++ b/tests/test_core_modulemanager.lua @@ -0,0 +1,48 @@ +-- Prosody IM +-- Copyright (C) 2008-2009 Matthew Wild +-- Copyright (C) 2008-2009 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 |