Software /
code /
prosody
Comparison
tests/test_core_modulemanager.lua @ 1961:3652ef68c361
tests: Add tests for new modulemanager load_modules_for_host code
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 16 Oct 2009 22:13:54 +0100 |
child | 2923:b7049746bd29 |
comparison
equal
deleted
inserted
replaced
1960:1e674dae31ae | 1961:3652ef68c361 |
---|---|
1 -- Prosody IM | |
2 -- Copyright (C) 2008-2009 Matthew Wild | |
3 -- Copyright (C) 2008-2009 Waqas Hussain | |
4 -- | |
5 -- This project is MIT/X11 licensed. Please see the | |
6 -- COPYING file in the source package for more information. | |
7 -- | |
8 | |
9 local config = require "core.configmanager"; | |
10 local helpers = require "util.helpers"; | |
11 local set = require "util.set"; | |
12 | |
13 function load_modules_for_host(load_modules_for_host, mm) | |
14 local test_num = 0; | |
15 local function test_load(global_modules_enabled, global_modules_disabled, host_modules_enabled, host_modules_disabled, expected_modules) | |
16 test_num = test_num + 1; | |
17 -- Prepare | |
18 hosts = { ["example.com"] = {} }; | |
19 config.set("*", "core", "modules_enabled", global_modules_enabled); | |
20 config.set("*", "core", "modules_disabled", global_modules_disabled); | |
21 config.set("example.com", "core", "modules_enabled", host_modules_enabled); | |
22 config.set("example.com", "core", "modules_disabled", host_modules_disabled); | |
23 | |
24 expected_modules = set.new(expected_modules); | |
25 expected_modules:add_list(helpers.get_upvalue(load_modules_for_host, "autoload_modules")); | |
26 | |
27 local loaded_modules = set.new(); | |
28 function mm.load(host, module) | |
29 assert_equal(host, "example.com", test_num..": Host isn't example.com but "..tostring(host)); | |
30 assert_equal(expected_modules:contains(module), true, test_num..": Loading unexpected module '"..tostring(module).."'"); | |
31 loaded_modules:add(module); | |
32 end | |
33 load_modules_for_host("example.com"); | |
34 assert_equal((expected_modules - loaded_modules):empty(), true, test_num..": Not all modules loaded: "..tostring(expected_modules - loaded_modules)); | |
35 end | |
36 | |
37 test_load({ "one", "two", "three" }, nil, nil, nil, { "one", "two", "three" }); | |
38 test_load({ "one", "two", "three" }, {}, nil, nil, { "one", "two", "three" }); | |
39 test_load({ "one", "two", "three" }, { "two" }, nil, nil, { "one", "three" }); | |
40 test_load({ "one", "two", "three" }, { "three" }, nil, nil, { "one", "two" }); | |
41 test_load({ "one", "two", "three" }, nil, nil, { "three" }, { "one", "two" }); | |
42 test_load({ "one", "two", "three" }, nil, { "three" }, { "three" }, { "one", "two", "three" }); | |
43 | |
44 test_load({ "one", "two" }, nil, { "three" }, nil, { "one", "two", "three" }); | |
45 test_load({ "one", "two", "three" }, nil, { "three" }, nil, { "one", "two", "three" }); | |
46 test_load({ "one", "two", "three" }, { "three" }, { "three" }, nil, { "one", "two", "three" }); | |
47 test_load({ "one", "two" }, { "three" }, { "three" }, nil, { "one", "two", "three" }); | |
48 end |