Software /
code /
prosody
Comparison
spec/core_storagemanager_spec.lua @ 9466:b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 10 Oct 2018 22:00:37 +0100 |
parent | 9452:9d892b2415bf |
child | 9467:2098794ac866 |
comparison
equal
deleted
inserted
replaced
9465:876171084ea3 | 9466:b70ce39d366f |
---|---|
1 local server = require "net.server_select"; | 1 local server = require "net.server_select"; |
2 package.loaded["net.server"] = server; | 2 package.loaded["net.server"] = server; |
3 | |
4 local st = require "util.stanza"; | |
3 | 5 |
4 local function mock_prosody() | 6 local function mock_prosody() |
5 _G.prosody = { | 7 _G.prosody = { |
6 core_post_stanza = function () end; | 8 core_post_stanza = function () end; |
7 events = require "util.events".new(); | 9 events = require "util.events".new(); |
54 end | 56 end |
55 assert(hm.activate(test_host, {})); | 57 assert(hm.activate(test_host, {})); |
56 sm.initialize_host(test_host); | 58 sm.initialize_host(test_host); |
57 assert(mm.load(test_host, "storage_"..backend_config.storage)); | 59 assert(mm.load(test_host, "storage_"..backend_config.storage)); |
58 | 60 |
59 -- These tests rely on being executed in order, disable any order | 61 describe("key-value stores", function () |
60 -- randomization for this block | 62 -- These tests rely on being executed in order, disable any order |
61 randomize(false); | 63 -- randomization for this block |
64 randomize(false); | |
62 | 65 |
63 local store; | 66 local store; |
64 it("may open a store", function () | 67 it("may be opened", function () |
65 store = assert(sm.open(test_host, "test")); | 68 store = assert(sm.open(test_host, "test")); |
69 end); | |
70 | |
71 local simple_data = { foo = "bar" }; | |
72 | |
73 it("may set data for a user", function () | |
74 assert(store:set("user9999", simple_data)); | |
75 end); | |
76 | |
77 it("may get data for a user", function () | |
78 assert.same(simple_data, assert(store:get("user9999"))); | |
79 end); | |
80 | |
81 it("may remove data for a user", function () | |
82 assert(store:set("user9999", nil)); | |
83 local ret, err = store:get("user9999"); | |
84 assert.is_nil(ret); | |
85 assert.is_nil(err); | |
86 end); | |
66 end); | 87 end); |
67 | 88 |
68 local simple_data = { foo = "bar" }; | 89 describe("archive stores", function () |
90 randomize(false); | |
69 | 91 |
70 it("may set data for a user", function () | 92 local archive; |
71 assert(store:set("user9999", simple_data)); | 93 it("can be opened", function () |
72 end); | 94 archive = assert(sm.open(test_host, "test-archive", "archive")); |
95 end); | |
73 | 96 |
74 it("may get data for a user", function () | 97 local test_stanza = st.stanza("test", { xmlns = "urn:example:foo" }) |
75 assert.same(simple_data, assert(store:get("user9999"))); | 98 :tag("foo"):up() |
76 end); | 99 :tag("foo"):up(); |
100 local test_time = 1539204123; | |
101 it("can be added to", function () | |
102 local ok = archive:append("user", nil, test_stanza, 1539204123, "contact@example.com"); | |
103 assert.truthy(ok); | |
104 end); | |
77 | 105 |
78 it("may remove data for a user", function () | 106 it("can be queried", function () |
79 assert(store:set("user9999", nil)); | 107 local data, err = archive:find("user", { |
80 local ret, err = store:get("user9999"); | 108 with = "contact@example.com"; |
81 assert.is_nil(ret); | 109 }); |
82 assert.is_nil(err); | 110 assert.truthy(data); |
111 for id, item, when in data do | |
112 assert.truthy(id); | |
113 assert(st.is_stanza(item)); | |
114 assert.equal("test", item.name); | |
115 assert.equal("urn:example:foo", item.attr.xmlns); | |
116 assert.equal(2, #item.tags); | |
117 assert.equal(test_time, when); | |
118 end | |
119 end); | |
120 it("can be purged", function () | |
121 local ok, err = archive:delete("user"); | |
122 assert.truthy(ok); | |
123 end); | |
83 end); | 124 end); |
84 end); | 125 end); |
85 end | 126 end |
86 end); | 127 end); |