Software /
code /
prosody
Comparison
spec/core_storagemanager_spec.lua @ 12956:52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
This combines the two most common store types, which modules often end up
opening with both interfaces separately anyway.
As well as combining them, I've taken the opportunity to improve some of the
method names to make them clearer.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 27 Sep 2022 17:46:27 +0100 |
parent | 12600:3d3a0c4e2662 |
child | 13133:3692265becb7 |
comparison
equal
deleted
inserted
replaced
12955:d32926897ca4 | 12956:52fcdfe710ca |
---|---|
194 assert.is_nil(err); | 194 assert.is_nil(err); |
195 end | 195 end |
196 end); | 196 end); |
197 end); | 197 end); |
198 | 198 |
199 describe("keyval+ stores", function () | |
200 -- These tests rely on being executed in order, disable any order | |
201 -- randomization for this block | |
202 randomize(false); | |
203 | |
204 local store, kv_store, map_store; | |
205 it("may be opened", function () | |
206 store = assert(sm.open(test_host, "test-kv+", "keyval+")); | |
207 end); | |
208 | |
209 local simple_data = { foo = "bar" }; | |
210 | |
211 it("may set data for a user", function () | |
212 assert(store:set("user9999", simple_data)); | |
213 end); | |
214 | |
215 it("may get data for a user", function () | |
216 assert.same(simple_data, assert(store:get("user9999"))); | |
217 end); | |
218 | |
219 it("may be opened as a keyval store", function () | |
220 kv_store = assert(sm.open(test_host, "test-kv+", "keyval")); | |
221 assert.same(simple_data, assert(kv_store:get("user9999"))); | |
222 end); | |
223 | |
224 it("may be opened as a map store", function () | |
225 map_store = assert(sm.open(test_host, "test-kv+", "map")); | |
226 assert.same("bar", assert(map_store:get("user9999", "foo"))); | |
227 end); | |
228 | |
229 it("may remove data for a user", function () | |
230 assert(store:set("user9999", nil)); | |
231 local ret, err = store:get("user9999"); | |
232 assert.is_nil(ret); | |
233 assert.is_nil(err); | |
234 end); | |
235 | |
236 | |
237 it("may set a specific key for a user", function () | |
238 assert(store:set_key("user9999", "foo", "bar")); | |
239 assert.same(kv_store:get("user9999"), { foo = "bar" }); | |
240 end); | |
241 | |
242 it("may get a specific key for a user", function () | |
243 assert.equal("bar", store:get_key("user9999", "foo")); | |
244 end); | |
245 | |
246 it("may find all users with a specific key", function () | |
247 assert.is_function(store.get_key_from_all); | |
248 assert(store:set_key("user9999b", "bar", "bar")); | |
249 assert(store:set_key("user9999c", "foo", "blah")); | |
250 local ret, err = store:get_key_from_all("foo"); | |
251 assert.is_nil(err); | |
252 assert.same({ user9999 = "bar", user9999c = "blah" }, ret); | |
253 end); | |
254 | |
255 it("rejects empty or non-string keys to get_all", function () | |
256 assert.is_function(store.get_key_from_all); | |
257 do | |
258 local ret, err = store:get_key_from_all(""); | |
259 assert.is_nil(ret); | |
260 assert.is_not_nil(err); | |
261 end | |
262 do | |
263 local ret, err = store:get_key_from_all(true); | |
264 assert.is_nil(ret); | |
265 assert.is_not_nil(err); | |
266 end | |
267 end); | |
268 | |
269 it("rejects empty or non-string keys to delete_all", function () | |
270 assert.is_function(store.delete_key_from_all); | |
271 do | |
272 local ret, err = store:delete_key_from_all(""); | |
273 assert.is_nil(ret); | |
274 assert.is_not_nil(err); | |
275 end | |
276 do | |
277 local ret, err = store:delete_key_from_all(true); | |
278 assert.is_nil(ret); | |
279 assert.is_not_nil(err); | |
280 end | |
281 end); | |
282 | |
283 it("may delete all instances of a specific key", function () | |
284 assert.is_function(store.delete_key_from_all); | |
285 assert(store:set_key("user9999b", "foo", "hello")); | |
286 | |
287 assert(store:delete_key_from_all("bar")); | |
288 -- Ensure key was deleted | |
289 do | |
290 local ret, err = store:get_key("user9999b", "bar"); | |
291 assert.is_nil(ret); | |
292 assert.is_nil(err); | |
293 end | |
294 -- Ensure other users/keys are intact | |
295 do | |
296 local ret, err = store:get_key("user9999", "foo"); | |
297 assert.equal("bar", ret); | |
298 assert.is_nil(err); | |
299 end | |
300 do | |
301 local ret, err = store:get_key("user9999b", "foo"); | |
302 assert.equal("hello", ret); | |
303 assert.is_nil(err); | |
304 end | |
305 do | |
306 local ret, err = store:get_key("user9999c", "foo"); | |
307 assert.equal("blah", ret); | |
308 assert.is_nil(err); | |
309 end | |
310 end); | |
311 | |
312 it("may remove data for a specific key for a user", function () | |
313 assert(store:set_key("user9999", "foo", nil)); | |
314 do | |
315 local ret, err = store:get_key("user9999", "foo"); | |
316 assert.is_nil(ret); | |
317 assert.is_nil(err); | |
318 end | |
319 | |
320 assert(store:set_key("user9999b", "foo", nil)); | |
321 do | |
322 local ret, err = store:get_key("user9999b", "foo"); | |
323 assert.is_nil(ret); | |
324 assert.is_nil(err); | |
325 end | |
326 end); | |
327 end); | |
328 | |
199 describe("archive stores", function () | 329 describe("archive stores", function () |
200 randomize(false); | 330 randomize(false); |
201 | 331 |
202 local archive; | 332 local archive; |
203 it("can be opened", function () | 333 it("can be opened", function () |