aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2018-10-10 22:00:37 +0100
committerMatthew Wild <mwild1@gmail.com>2018-10-10 22:00:37 +0100
commit038921d7e0769ab68480af75e06e70263180012d (patch)
tree11a5f529f6f81df87f7309509d47d52b4c9301e5
parent044da0478a9900467ac65e99d0177ea5b68556b6 (diff)
downloadprosody-038921d7e0769ab68480af75e06e70263180012d.tar.gz
prosody-038921d7e0769ab68480af75e06e70263180012d.zip
storagemanager tests: Add initial basic tests for archive stores
-rw-r--r--spec/core_storagemanager_spec.lua77
1 files changed, 59 insertions, 18 deletions
diff --git a/spec/core_storagemanager_spec.lua b/spec/core_storagemanager_spec.lua
index ad4150d3..ea518c62 100644
--- a/spec/core_storagemanager_spec.lua
+++ b/spec/core_storagemanager_spec.lua
@@ -1,6 +1,8 @@
local server = require "net.server_select";
package.loaded["net.server"] = server;
+local st = require "util.stanza";
+
local function mock_prosody()
_G.prosody = {
core_post_stanza = function () end;
@@ -56,30 +58,69 @@ describe("storagemanager", function ()
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);
+ describe("key-value stores", function ()
+ -- 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 store;
+ it("may be opened", function ()
+ store = assert(sm.open(test_host, "test"));
+ end);
- local simple_data = { foo = "bar" };
+ local simple_data = { foo = "bar" };
- it("may set data for a user", function ()
- assert(store:set("user9999", simple_data));
- end);
+ 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 get data for a user", function ()
- assert.same(simple_data, assert(store:get("user9999")));
+ 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);
- 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);
+ describe("archive stores", function ()
+ randomize(false);
+
+ local archive;
+ it("can be opened", function ()
+ archive = assert(sm.open(test_host, "test-archive", "archive"));
+ end);
+
+ local test_stanza = st.stanza("test", { xmlns = "urn:example:foo" })
+ :tag("foo"):up()
+ :tag("foo"):up();
+ local test_time = 1539204123;
+ it("can be added to", function ()
+ local ok = archive:append("user", nil, test_stanza, 1539204123, "contact@example.com");
+ assert.truthy(ok);
+ end);
+
+ it("can be queried", function ()
+ local data, err = archive:find("user", {
+ with = "contact@example.com";
+ });
+ assert.truthy(data);
+ for id, item, when in data do
+ assert.truthy(id);
+ assert(st.is_stanza(item));
+ assert.equal("test", item.name);
+ assert.equal("urn:example:foo", item.attr.xmlns);
+ assert.equal(2, #item.tags);
+ assert.equal(test_time, when);
+ end
+ end);
+ it("can be purged", function ()
+ local ok, err = archive:delete("user");
+ assert.truthy(ok);
+ end);
end);
end);
end