Software /
code /
prosody
Changeset
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 |
parents | 9451:db82b096b842 |
children | 9453:b6cdadb1175d |
files | .busted spec/core_storagemanager.lua spec/core_storagemanager_spec.lua |
diffstat | 3 files changed, 92 insertions(+), 82 deletions(-) [+] |
line wrap: on
line diff
--- a/.busted Mon Oct 01 19:43:20 2018 +0100 +++ b/.busted Mon Oct 01 20:21:26 2018 +0100 @@ -2,9 +2,12 @@ _all = { }, default = { - ["exclude-tags"] = "mod_bosh"; - }, + ["exclude-tags"] = "mod_bosh,storage"; + }; bosh = { tags = "mod_bosh"; - } + }; + storage = { + tags = "storage"; + }; }
--- a/spec/core_storagemanager.lua Mon Oct 01 19:43:20 2018 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -local server = require "net.server_select"; -package.loaded["net.server"] = server; - -local function mock_prosody() - _G.prosody = { - core_post_stanza = function () end; - events = require "util.events".new(); - hosts = {}; - paths = { - data = "./data"; - }; - }; -end - -local configs = { - internal = { - storage = "internal"; - }; - sqlite = { - storage = "sql"; - sql = { driver = "SQLite3", database = "prosody-tests.sqlite" }; - }; -}; - -local test_host = "storage-unit-tests.invalid"; - -describe("storagemanager", function () - for _, backend in ipairs({ "internal", "sqlite" }) do - local tagged_name = "#"..backend; - if backend ~= configs[backend].storage then - tagged_name = tagged_name.." #"..configs[backend].storage; - end - insulate(tagged_name.." #storage backend", function () - mock_prosody(); - - local config = require "core.configmanager"; - local sm = require "core.storagemanager"; - local hm = require "core.hostmanager"; - local mm = require "core.modulemanager"; - - -- Simple check to ensure insulation is working correctly - assert.is_nil(config.get(test_host, "storage")); - - local backend_config = configs[backend]; - for k, v in pairs(backend_config) do - config.set(test_host, k, v); - end - assert(hm.activate(test_host, {})); - sm.initialize_host(test_host); - assert(mm.load(test_host, "storage_"..backend_config.storage)); - - -- These tests rely on being executed in order, disable any order - -- randomization for this block - randomize(false); - - local store; - it("may open a store", function () - store = assert(sm.open(test_host, "test")); - end); - - local simple_data = { foo = "bar" }; - - it("may set data for a user", function () - assert(store:set("user9999", simple_data)); - end); - - it("may get data for a user", function () - assert.same(simple_data, assert(store:get("user9999"))); - end); - - it("may remove data for a user", function () - assert(store:set("user9999", nil)); - local ret, err = store:get("user9999"); - assert.is_nil(ret); - assert.is_nil(err); - end); - end); - end -end);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spec/core_storagemanager_spec.lua Mon Oct 01 20:21:26 2018 +0100 @@ -0,0 +1,86 @@ +local server = require "net.server_select"; +package.loaded["net.server"] = server; + +local function mock_prosody() + _G.prosody = { + core_post_stanza = function () end; + events = require "util.events".new(); + hosts = {}; + paths = { + data = "./data"; + }; + }; +end + +local configs = { + internal = { + storage = "internal"; + }; + sqlite = { + storage = "sql"; + sql = { driver = "SQLite3", database = "prosody-tests.sqlite" }; + }; + mysql = { + storage = "sql"; + sql = { driver = "MySQL", database = "prosody", username = "prosody", password = "secret", host = "localhost" }; + }; + postgres = { + storage = "sql"; + sql = { driver = "PostgreSQL", database = "prosody", username = "prosody", password = "secret", host = "localhost" }; + }; +}; + +local test_host = "storage-unit-tests.invalid"; + +describe("storagemanager", function () + for backend, backend_config in pairs(configs) do + local tagged_name = "#"..backend; + if backend ~= backend_config.storage then + tagged_name = tagged_name.." #"..backend_config.storage; + end + insulate(tagged_name.." #storage backend", function () + mock_prosody(); + + local config = require "core.configmanager"; + local sm = require "core.storagemanager"; + local hm = require "core.hostmanager"; + local mm = require "core.modulemanager"; + + -- Simple check to ensure insulation is working correctly + assert.is_nil(config.get(test_host, "storage")); + + for k, v in pairs(backend_config) do + config.set(test_host, k, v); + end + assert(hm.activate(test_host, {})); + sm.initialize_host(test_host); + assert(mm.load(test_host, "storage_"..backend_config.storage)); + + -- These tests rely on being executed in order, disable any order + -- randomization for this block + randomize(false); + + local store; + it("may open a store", function () + store = assert(sm.open(test_host, "test")); + end); + + local simple_data = { foo = "bar" }; + + it("may set data for a user", function () + assert(store:set("user9999", simple_data)); + end); + + it("may get data for a user", function () + assert.same(simple_data, assert(store:get("user9999"))); + end); + + it("may remove data for a user", function () + assert(store:set("user9999", nil)); + local ret, err = store:get("user9999"); + assert.is_nil(ret); + assert.is_nil(err); + end); + end); + end +end);