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