aboutsummaryrefslogtreecommitdiffstats
path: root/spec/core_storagemanager.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2018-09-29 11:14:29 +0100
committerMatthew Wild <mwild1@gmail.com>2018-09-29 11:14:29 +0100
commitef4087f90bfaf070c1c5a4f68bf7ec6975052cdd (patch)
tree564dfc15862c6ab5bffeb9a321182efe52008a94 /spec/core_storagemanager.lua
parenta84c5b89c01bdf6d9a4adc502bb7be30a2a1300c (diff)
downloadprosody-ef4087f90bfaf070c1c5a4f68bf7ec6975052cdd.tar.gz
prosody-ef4087f90bfaf070c1c5a4f68bf7ec6975052cdd.zip
Add storage tests (currently only internal and sqlite)
Diffstat (limited to 'spec/core_storagemanager.lua')
-rw-r--r--spec/core_storagemanager.lua79
1 files changed, 79 insertions, 0 deletions
diff --git a/spec/core_storagemanager.lua b/spec/core_storagemanager.lua
new file mode 100644
index 00000000..29a924ac
--- /dev/null
+++ b/spec/core_storagemanager.lua
@@ -0,0 +1,79 @@
+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);