2 -- Copyright (C) 2008-2010 Matthew Wild
3 -- Copyright (C) 2008-2010 Waqas Hussain
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
9 local config = require "core.configmanager";
10 local helpers = require "util.helpers";
11 local set = require "util.set";
13 function load_modules_for_host(load_modules_for_host, mm)
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;
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);
24 expected_modules = set.new(expected_modules);
25 expected_modules:add_list(helpers.get_upvalue(load_modules_for_host, "autoload_modules"));
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);
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));
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" });
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" });