Comparison

spec/core_storagemanager_spec.lua @ 9452:9d892b2415bf

Fix storage tests so they run, but not by default
author Matthew Wild <mwild1@gmail.com>
date Mon, 01 Oct 2018 20:21:26 +0100
parent 9389:spec/core_storagemanager.lua@9ae575efbb1f
child 9466:b70ce39d366f
comparison
equal deleted inserted replaced
9451:db82b096b842 9452:9d892b2415bf
1 local server = require "net.server_select";
2 package.loaded["net.server"] = server;
3
4 local function mock_prosody()
5 _G.prosody = {
6 core_post_stanza = function () end;
7 events = require "util.events".new();
8 hosts = {};
9 paths = {
10 data = "./data";
11 };
12 };
13 end
14
15 local configs = {
16 internal = {
17 storage = "internal";
18 };
19 sqlite = {
20 storage = "sql";
21 sql = { driver = "SQLite3", database = "prosody-tests.sqlite" };
22 };
23 mysql = {
24 storage = "sql";
25 sql = { driver = "MySQL", database = "prosody", username = "prosody", password = "secret", host = "localhost" };
26 };
27 postgres = {
28 storage = "sql";
29 sql = { driver = "PostgreSQL", database = "prosody", username = "prosody", password = "secret", host = "localhost" };
30 };
31 };
32
33 local test_host = "storage-unit-tests.invalid";
34
35 describe("storagemanager", function ()
36 for backend, backend_config in pairs(configs) do
37 local tagged_name = "#"..backend;
38 if backend ~= backend_config.storage then
39 tagged_name = tagged_name.." #"..backend_config.storage;
40 end
41 insulate(tagged_name.." #storage backend", function ()
42 mock_prosody();
43
44 local config = require "core.configmanager";
45 local sm = require "core.storagemanager";
46 local hm = require "core.hostmanager";
47 local mm = require "core.modulemanager";
48
49 -- Simple check to ensure insulation is working correctly
50 assert.is_nil(config.get(test_host, "storage"));
51
52 for k, v in pairs(backend_config) do
53 config.set(test_host, k, v);
54 end
55 assert(hm.activate(test_host, {}));
56 sm.initialize_host(test_host);
57 assert(mm.load(test_host, "storage_"..backend_config.storage));
58
59 -- These tests rely on being executed in order, disable any order
60 -- randomization for this block
61 randomize(false);
62
63 local store;
64 it("may open a store", function ()
65 store = assert(sm.open(test_host, "test"));
66 end);
67
68 local simple_data = { foo = "bar" };
69
70 it("may set data for a user", function ()
71 assert(store:set("user9999", simple_data));
72 end);
73
74 it("may get data for a user", function ()
75 assert.same(simple_data, assert(store:get("user9999")));
76 end);
77
78 it("may remove data for a user", function ()
79 assert(store:set("user9999", nil));
80 local ret, err = store:get("user9999");
81 assert.is_nil(ret);
82 assert.is_nil(err);
83 end);
84 end);
85 end
86 end);