Software /
code /
prosody
Annotate
spec/core_storagemanager_spec.lua @ 13129:7039d0ec11c3
doc/hgrc: Some useful Mercurial settings
Some useful settings that might benefit new contributors and get them up
to speed with Modern Mercurial™ faster :)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 07 Jun 2023 16:42:59 +0200 |
parent | 12956:52fcdfe710ca |
child | 13133:3692265becb7 |
rev | line source |
---|---|
12589
39ae08180c81
compat: Remove handling of Lua 5.1 location of 'unpack' function
Kim Alvefur <zash@zash.se>
parents:
11739
diff
changeset
|
1 local unpack = table.unpack; |
9389
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 local server = require "net.server_select"; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 package.loaded["net.server"] = server; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 |
9466
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
5 local st = require "util.stanza"; |
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
6 |
9389
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 local function mock_prosody() |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 _G.prosody = { |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 core_post_stanza = function () end; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 events = require "util.events".new(); |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 hosts = {}; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 paths = { |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 data = "./data"; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 }; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 }; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 end |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 local configs = { |
9491
89e4cbd1a564
storagemanager tests: Also cover memory driver
Kim Alvefur <zash@zash.se>
parents:
9472
diff
changeset
|
19 memory = { |
89e4cbd1a564
storagemanager tests: Also cover memory driver
Kim Alvefur <zash@zash.se>
parents:
9472
diff
changeset
|
20 storage = "memory"; |
89e4cbd1a564
storagemanager tests: Also cover memory driver
Kim Alvefur <zash@zash.se>
parents:
9472
diff
changeset
|
21 }; |
9389
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 internal = { |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 storage = "internal"; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 }; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 sqlite = { |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 storage = "sql"; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 sql = { driver = "SQLite3", database = "prosody-tests.sqlite" }; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 }; |
9452
9d892b2415bf
Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents:
9389
diff
changeset
|
29 mysql = { |
9d892b2415bf
Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents:
9389
diff
changeset
|
30 storage = "sql"; |
9d892b2415bf
Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents:
9389
diff
changeset
|
31 sql = { driver = "MySQL", database = "prosody", username = "prosody", password = "secret", host = "localhost" }; |
9d892b2415bf
Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents:
9389
diff
changeset
|
32 }; |
9d892b2415bf
Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents:
9389
diff
changeset
|
33 postgres = { |
9d892b2415bf
Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents:
9389
diff
changeset
|
34 storage = "sql"; |
9d892b2415bf
Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents:
9389
diff
changeset
|
35 sql = { driver = "PostgreSQL", database = "prosody", username = "prosody", password = "secret", host = "localhost" }; |
9d892b2415bf
Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents:
9389
diff
changeset
|
36 }; |
9389
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 }; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 local test_host = "storage-unit-tests.invalid"; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 describe("storagemanager", function () |
9452
9d892b2415bf
Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents:
9389
diff
changeset
|
42 for backend, backend_config in pairs(configs) do |
9389
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 local tagged_name = "#"..backend; |
9452
9d892b2415bf
Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents:
9389
diff
changeset
|
44 if backend ~= backend_config.storage then |
9d892b2415bf
Fix storage tests so they run, but not by default
Matthew Wild <mwild1@gmail.com>
parents:
9389
diff
changeset
|
45 tagged_name = tagged_name.." #"..backend_config.storage; |
9389
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 end |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 insulate(tagged_name.." #storage backend", function () |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 mock_prosody(); |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 local config = require "core.configmanager"; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 local sm = require "core.storagemanager"; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 local hm = require "core.hostmanager"; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 local mm = require "core.modulemanager"; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 -- Simple check to ensure insulation is working correctly |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 assert.is_nil(config.get(test_host, "storage")); |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 for k, v in pairs(backend_config) do |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 config.set(test_host, k, v); |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 end |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 assert(hm.activate(test_host, {})); |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 sm.initialize_host(test_host); |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 assert(mm.load(test_host, "storage_"..backend_config.storage)); |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 |
9466
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
65 describe("key-value stores", function () |
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
66 -- These tests rely on being executed in order, disable any order |
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
67 -- randomization for this block |
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
68 randomize(false); |
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
69 |
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
70 local store; |
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
71 it("may be opened", function () |
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
72 store = assert(sm.open(test_host, "test")); |
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
73 end); |
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
74 |
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
75 local simple_data = { foo = "bar" }; |
9389
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 |
9466
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
77 it("may set data for a user", function () |
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
78 assert(store:set("user9999", simple_data)); |
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
79 end); |
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
80 |
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
81 it("may get data for a user", function () |
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
82 assert.same(simple_data, assert(store:get("user9999"))); |
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
83 end); |
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
84 |
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
85 it("may remove data for a user", function () |
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
86 assert(store:set("user9999", nil)); |
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
87 local ret, err = store:get("user9999"); |
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
88 assert.is_nil(ret); |
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
89 assert.is_nil(err); |
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
90 end); |
9389
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 end); |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 |
10676
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
93 describe("map stores", function () |
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
94 -- These tests rely on being executed in order, disable any order |
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
95 -- randomization for this block |
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
96 randomize(false); |
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
97 |
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
98 local store, kv_store; |
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
99 it("may be opened", function () |
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
100 store = assert(sm.open(test_host, "test-map", "map")); |
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
101 end); |
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
102 |
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
103 it("may be opened as a keyval store", function () |
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
104 kv_store = assert(sm.open(test_host, "test-map", "keyval")); |
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
105 end); |
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
106 |
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
107 it("may set a specific key for a user", function () |
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
108 assert(store:set("user9999", "foo", "bar")); |
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
109 assert.same(kv_store:get("user9999"), { foo = "bar" }); |
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
110 end); |
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
111 |
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
112 it("may get a specific key for a user", function () |
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
113 assert.equal("bar", store:get("user9999", "foo")); |
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
114 end); |
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
115 |
10679
b50b1eae711c
storagemanager: Add support for :find_key() and :delete_key() to map store shim
Matthew Wild <mwild1@gmail.com>
parents:
10678
diff
changeset
|
116 it("may find all users with a specific key", function () |
10680
19692fc5c106
storagemanager, mod_storage_sql: Rename methods to :get_all() and :delete_all()
Matthew Wild <mwild1@gmail.com>
parents:
10679
diff
changeset
|
117 assert.is_function(store.get_all); |
10677
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
118 assert(store:set("user9999b", "bar", "bar")); |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
119 assert(store:set("user9999c", "foo", "blah")); |
10680
19692fc5c106
storagemanager, mod_storage_sql: Rename methods to :get_all() and :delete_all()
Matthew Wild <mwild1@gmail.com>
parents:
10679
diff
changeset
|
120 local ret, err = store:get_all("foo"); |
10677
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
121 assert.is_nil(err); |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
122 assert.same({ user9999 = "bar", user9999c = "blah" }, ret); |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
123 end); |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
124 |
10680
19692fc5c106
storagemanager, mod_storage_sql: Rename methods to :get_all() and :delete_all()
Matthew Wild <mwild1@gmail.com>
parents:
10679
diff
changeset
|
125 it("rejects empty or non-string keys to get_all", function () |
19692fc5c106
storagemanager, mod_storage_sql: Rename methods to :get_all() and :delete_all()
Matthew Wild <mwild1@gmail.com>
parents:
10679
diff
changeset
|
126 assert.is_function(store.get_all); |
10677
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
127 do |
10680
19692fc5c106
storagemanager, mod_storage_sql: Rename methods to :get_all() and :delete_all()
Matthew Wild <mwild1@gmail.com>
parents:
10679
diff
changeset
|
128 local ret, err = store:get_all(""); |
10677
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
129 assert.is_nil(ret); |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
130 assert.is_not_nil(err); |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
131 end |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
132 do |
10680
19692fc5c106
storagemanager, mod_storage_sql: Rename methods to :get_all() and :delete_all()
Matthew Wild <mwild1@gmail.com>
parents:
10679
diff
changeset
|
133 local ret, err = store:get_all(true); |
10677
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
134 assert.is_nil(ret); |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
135 assert.is_not_nil(err); |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
136 end |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
137 end); |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
138 |
10680
19692fc5c106
storagemanager, mod_storage_sql: Rename methods to :get_all() and :delete_all()
Matthew Wild <mwild1@gmail.com>
parents:
10679
diff
changeset
|
139 it("rejects empty or non-string keys to delete_all", function () |
19692fc5c106
storagemanager, mod_storage_sql: Rename methods to :get_all() and :delete_all()
Matthew Wild <mwild1@gmail.com>
parents:
10679
diff
changeset
|
140 assert.is_function(store.delete_all); |
10677
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
141 do |
10680
19692fc5c106
storagemanager, mod_storage_sql: Rename methods to :get_all() and :delete_all()
Matthew Wild <mwild1@gmail.com>
parents:
10679
diff
changeset
|
142 local ret, err = store:delete_all(""); |
10677
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
143 assert.is_nil(ret); |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
144 assert.is_not_nil(err); |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
145 end |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
146 do |
10680
19692fc5c106
storagemanager, mod_storage_sql: Rename methods to :get_all() and :delete_all()
Matthew Wild <mwild1@gmail.com>
parents:
10679
diff
changeset
|
147 local ret, err = store:delete_all(true); |
10677
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
148 assert.is_nil(ret); |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
149 assert.is_not_nil(err); |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
150 end |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
151 end); |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
152 |
10679
b50b1eae711c
storagemanager: Add support for :find_key() and :delete_key() to map store shim
Matthew Wild <mwild1@gmail.com>
parents:
10678
diff
changeset
|
153 it("may delete all instances of a specific key", function () |
10680
19692fc5c106
storagemanager, mod_storage_sql: Rename methods to :get_all() and :delete_all()
Matthew Wild <mwild1@gmail.com>
parents:
10679
diff
changeset
|
154 assert.is_function(store.delete_all); |
10677
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
155 assert(store:set("user9999b", "foo", "hello")); |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
156 |
10680
19692fc5c106
storagemanager, mod_storage_sql: Rename methods to :get_all() and :delete_all()
Matthew Wild <mwild1@gmail.com>
parents:
10679
diff
changeset
|
157 assert(store:delete_all("bar")); |
10677
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
158 -- Ensure key was deleted |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
159 do |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
160 local ret, err = store:get("user9999b", "bar"); |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
161 assert.is_nil(ret); |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
162 assert.is_nil(err); |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
163 end |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
164 -- Ensure other users/keys are intact |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
165 do |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
166 local ret, err = store:get("user9999", "foo"); |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
167 assert.equal("bar", ret); |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
168 assert.is_nil(err); |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
169 end |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
170 do |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
171 local ret, err = store:get("user9999b", "foo"); |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
172 assert.equal("hello", ret); |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
173 assert.is_nil(err); |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
174 end |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
175 do |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
176 local ret, err = store:get("user9999c", "foo"); |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
177 assert.equal("blah", ret); |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
178 assert.is_nil(err); |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
179 end |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
180 end); |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
181 |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
182 it("may remove data for a specific key for a user", function () |
10676
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
183 assert(store:set("user9999", "foo", nil)); |
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
184 do |
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
185 local ret, err = store:get("user9999", "foo"); |
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
186 assert.is_nil(ret); |
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
187 assert.is_nil(err); |
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
188 end |
10677
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
189 |
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
190 assert(store:set("user9999b", "foo", nil)); |
10676
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
191 do |
10677
0054aec3e8c5
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Matthew Wild <mwild1@gmail.com>
parents:
10676
diff
changeset
|
192 local ret, err = store:get("user9999b", "foo"); |
10676
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
193 assert.is_nil(ret); |
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
194 assert.is_nil(err); |
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
195 end |
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
196 end); |
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
197 end); |
33c7e4920591
storagemanager: Add tests for map stores
Matthew Wild <mwild1@gmail.com>
parents:
10541
diff
changeset
|
198 |
12956
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
199 describe("keyval+ stores", function () |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
200 -- These tests rely on being executed in order, disable any order |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
201 -- randomization for this block |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
202 randomize(false); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
203 |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
204 local store, kv_store, map_store; |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
205 it("may be opened", function () |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
206 store = assert(sm.open(test_host, "test-kv+", "keyval+")); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
207 end); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
208 |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
209 local simple_data = { foo = "bar" }; |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
210 |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
211 it("may set data for a user", function () |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
212 assert(store:set("user9999", simple_data)); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
213 end); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
214 |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
215 it("may get data for a user", function () |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
216 assert.same(simple_data, assert(store:get("user9999"))); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
217 end); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
218 |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
219 it("may be opened as a keyval store", function () |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
220 kv_store = assert(sm.open(test_host, "test-kv+", "keyval")); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
221 assert.same(simple_data, assert(kv_store:get("user9999"))); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
222 end); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
223 |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
224 it("may be opened as a map store", function () |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
225 map_store = assert(sm.open(test_host, "test-kv+", "map")); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
226 assert.same("bar", assert(map_store:get("user9999", "foo"))); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
227 end); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
228 |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
229 it("may remove data for a user", function () |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
230 assert(store:set("user9999", nil)); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
231 local ret, err = store:get("user9999"); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
232 assert.is_nil(ret); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
233 assert.is_nil(err); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
234 end); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
235 |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
236 |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
237 it("may set a specific key for a user", function () |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
238 assert(store:set_key("user9999", "foo", "bar")); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
239 assert.same(kv_store:get("user9999"), { foo = "bar" }); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
240 end); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
241 |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
242 it("may get a specific key for a user", function () |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
243 assert.equal("bar", store:get_key("user9999", "foo")); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
244 end); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
245 |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
246 it("may find all users with a specific key", function () |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
247 assert.is_function(store.get_key_from_all); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
248 assert(store:set_key("user9999b", "bar", "bar")); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
249 assert(store:set_key("user9999c", "foo", "blah")); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
250 local ret, err = store:get_key_from_all("foo"); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
251 assert.is_nil(err); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
252 assert.same({ user9999 = "bar", user9999c = "blah" }, ret); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
253 end); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
254 |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
255 it("rejects empty or non-string keys to get_all", function () |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
256 assert.is_function(store.get_key_from_all); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
257 do |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
258 local ret, err = store:get_key_from_all(""); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
259 assert.is_nil(ret); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
260 assert.is_not_nil(err); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
261 end |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
262 do |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
263 local ret, err = store:get_key_from_all(true); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
264 assert.is_nil(ret); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
265 assert.is_not_nil(err); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
266 end |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
267 end); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
268 |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
269 it("rejects empty or non-string keys to delete_all", function () |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
270 assert.is_function(store.delete_key_from_all); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
271 do |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
272 local ret, err = store:delete_key_from_all(""); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
273 assert.is_nil(ret); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
274 assert.is_not_nil(err); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
275 end |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
276 do |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
277 local ret, err = store:delete_key_from_all(true); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
278 assert.is_nil(ret); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
279 assert.is_not_nil(err); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
280 end |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
281 end); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
282 |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
283 it("may delete all instances of a specific key", function () |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
284 assert.is_function(store.delete_key_from_all); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
285 assert(store:set_key("user9999b", "foo", "hello")); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
286 |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
287 assert(store:delete_key_from_all("bar")); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
288 -- Ensure key was deleted |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
289 do |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
290 local ret, err = store:get_key("user9999b", "bar"); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
291 assert.is_nil(ret); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
292 assert.is_nil(err); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
293 end |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
294 -- Ensure other users/keys are intact |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
295 do |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
296 local ret, err = store:get_key("user9999", "foo"); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
297 assert.equal("bar", ret); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
298 assert.is_nil(err); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
299 end |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
300 do |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
301 local ret, err = store:get_key("user9999b", "foo"); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
302 assert.equal("hello", ret); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
303 assert.is_nil(err); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
304 end |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
305 do |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
306 local ret, err = store:get_key("user9999c", "foo"); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
307 assert.equal("blah", ret); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
308 assert.is_nil(err); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
309 end |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
310 end); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
311 |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
312 it("may remove data for a specific key for a user", function () |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
313 assert(store:set_key("user9999", "foo", nil)); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
314 do |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
315 local ret, err = store:get_key("user9999", "foo"); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
316 assert.is_nil(ret); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
317 assert.is_nil(err); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
318 end |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
319 |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
320 assert(store:set_key("user9999b", "foo", nil)); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
321 do |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
322 local ret, err = store:get_key("user9999b", "foo"); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
323 assert.is_nil(ret); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
324 assert.is_nil(err); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
325 end |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
326 end); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
327 end); |
52fcdfe710ca
storagemanager: Add keyval+ (combined keyval + map) store type
Matthew Wild <mwild1@gmail.com>
parents:
12600
diff
changeset
|
328 |
9466
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
329 describe("archive stores", function () |
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
330 randomize(false); |
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
331 |
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
332 local archive; |
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
333 it("can be opened", function () |
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
334 archive = assert(sm.open(test_host, "test-archive", "archive")); |
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
335 end); |
9389
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
336 |
9466
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
337 local test_stanza = st.stanza("test", { xmlns = "urn:example:foo" }) |
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
338 :tag("foo"):up() |
10836
93019f3edd68
spec/storage: Reset build context of test stanza make comparisons easier
Kim Alvefur <zash@zash.se>
parents:
10680
diff
changeset
|
339 :tag("foo"):up() |
93019f3edd68
spec/storage: Reset build context of test stanza make comparisons easier
Kim Alvefur <zash@zash.se>
parents:
10680
diff
changeset
|
340 :reset(); |
9466
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
341 local test_time = 1539204123; |
9470
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
342 |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
343 local test_data = { |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
344 { nil, test_stanza, test_time, "contact@example.com" }; |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
345 { nil, test_stanza, test_time+1, "contact2@example.com" }; |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
346 { nil, test_stanza, test_time+2, "contact2@example.com" }; |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
347 { nil, test_stanza, test_time-1, "contact2@example.com" }; |
10927
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
348 { nil, test_stanza, test_time-1, "contact3@example.com" }; |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
349 { nil, test_stanza, test_time+0, "contact3@example.com" }; |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
350 { nil, test_stanza, test_time+1, "contact3@example.com" }; |
9470
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
351 }; |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
352 |
9466
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
353 it("can be added to", function () |
9470
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
354 for _, data_item in ipairs(test_data) do |
10927
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
355 local id = archive:append("user", unpack(data_item, 1, 4)); |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
356 assert.truthy(id); |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
357 data_item[1] = id; |
9470
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
358 end |
9466
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
359 end); |
9389
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
360 |
9470
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
361 describe("can be queried", function () |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
362 it("for all items", function () |
10541
6c6ff4509082
tests: Silence [luacheck] warnings
Kim Alvefur <zash@zash.se>
parents:
9691
diff
changeset
|
363 -- luacheck: ignore 211/err |
9470
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
364 local data, err = archive:find("user", {}); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
365 assert.truthy(data); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
366 local count = 0; |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
367 for id, item, when in data do |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
368 count = count + 1; |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
369 assert.truthy(id); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
370 assert(st.is_stanza(item)); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
371 assert.equal("test", item.name); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
372 assert.equal("urn:example:foo", item.attr.xmlns); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
373 assert.equal(2, #item.tags); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
374 assert.equal(test_data[count][3], when); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
375 end |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
376 assert.equal(#test_data, count); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
377 end); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
378 |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
379 it("by JID", function () |
10541
6c6ff4509082
tests: Silence [luacheck] warnings
Kim Alvefur <zash@zash.se>
parents:
9691
diff
changeset
|
380 -- luacheck: ignore 211/err |
9470
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
381 local data, err = archive:find("user", { |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
382 with = "contact@example.com"; |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
383 }); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
384 assert.truthy(data); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
385 local count = 0; |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
386 for id, item, when in data do |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
387 count = count + 1; |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
388 assert.truthy(id); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
389 assert(st.is_stanza(item)); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
390 assert.equal("test", item.name); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
391 assert.equal("urn:example:foo", item.attr.xmlns); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
392 assert.equal(2, #item.tags); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
393 assert.equal(test_time, when); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
394 end |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
395 assert.equal(1, count); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
396 end); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
397 |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
398 it("by time (end)", function () |
10541
6c6ff4509082
tests: Silence [luacheck] warnings
Kim Alvefur <zash@zash.se>
parents:
9691
diff
changeset
|
399 -- luacheck: ignore 211/err |
9470
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
400 local data, err = archive:find("user", { |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
401 ["end"] = test_time; |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
402 }); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
403 assert.truthy(data); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
404 local count = 0; |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
405 for id, item, when in data do |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
406 count = count + 1; |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
407 assert.truthy(id); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
408 assert(st.is_stanza(item)); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
409 assert.equal("test", item.name); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
410 assert.equal("urn:example:foo", item.attr.xmlns); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
411 assert.equal(2, #item.tags); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
412 assert(test_time >= when); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
413 end |
10927
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
414 assert.equal(4, count); |
9470
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
415 end); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
416 |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
417 it("by time (start)", function () |
10541
6c6ff4509082
tests: Silence [luacheck] warnings
Kim Alvefur <zash@zash.se>
parents:
9691
diff
changeset
|
418 -- luacheck: ignore 211/err |
9470
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
419 local data, err = archive:find("user", { |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
420 ["start"] = test_time; |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
421 }); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
422 assert.truthy(data); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
423 local count = 0; |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
424 for id, item, when in data do |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
425 count = count + 1; |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
426 assert.truthy(id); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
427 assert(st.is_stanza(item)); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
428 assert.equal("test", item.name); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
429 assert.equal("urn:example:foo", item.attr.xmlns); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
430 assert.equal(2, #item.tags); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
431 assert(test_time <= when); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
432 end |
10927
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
433 assert.equal(#test_data - 2, count); |
9470
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
434 end); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
435 |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
436 it("by time (start+end)", function () |
10541
6c6ff4509082
tests: Silence [luacheck] warnings
Kim Alvefur <zash@zash.se>
parents:
9691
diff
changeset
|
437 -- luacheck: ignore 211/err |
9470
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
438 local data, err = archive:find("user", { |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
439 ["start"] = test_time; |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
440 ["end"] = test_time+1; |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
441 }); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
442 assert.truthy(data); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
443 local count = 0; |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
444 for id, item, when in data do |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
445 count = count + 1; |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
446 assert.truthy(id); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
447 assert(st.is_stanza(item)); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
448 assert.equal("test", item.name); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
449 assert.equal("urn:example:foo", item.attr.xmlns); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
450 assert.equal(2, #item.tags); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
451 assert(when >= test_time, ("%d >= %d"):format(when, test_time)); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
452 assert(when <= test_time+1, ("%d <= %d"):format(when, test_time+1)); |
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
453 end |
10927
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
454 assert.equal(4, count); |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
455 end); |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
456 |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
457 it("by id (after)", function () |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
458 -- luacheck: ignore 211/err |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
459 local data, err = archive:find("user", { |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
460 ["after"] = test_data[2][1]; |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
461 }); |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
462 assert.truthy(data); |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
463 local count = 0; |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
464 for id, item in data do |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
465 count = count + 1; |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
466 assert.truthy(id); |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
467 assert.equal(test_data[2+count][1], id); |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
468 assert(st.is_stanza(item)); |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
469 assert.equal("test", item.name); |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
470 assert.equal("urn:example:foo", item.attr.xmlns); |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
471 assert.equal(2, #item.tags); |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
472 end |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
473 assert.equal(5, count); |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
474 end); |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
475 |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
476 it("by id (before)", function () |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
477 -- luacheck: ignore 211/err |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
478 local data, err = archive:find("user", { |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
479 ["before"] = test_data[4][1]; |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
480 }); |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
481 assert.truthy(data); |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
482 local count = 0; |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
483 for id, item in data do |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
484 count = count + 1; |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
485 assert.truthy(id); |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
486 assert.equal(test_data[count][1], id); |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
487 assert(st.is_stanza(item)); |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
488 assert.equal("test", item.name); |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
489 assert.equal("urn:example:foo", item.attr.xmlns); |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
490 assert.equal(2, #item.tags); |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
491 end |
470602a8b633
storage tests: Add tests for archive queries before/after specific ids
Matthew Wild <mwild1@gmail.com>
parents:
10842
diff
changeset
|
492 assert.equal(3, count); |
9470
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
493 end); |
11273
9f1355689648
storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents:
10927
diff
changeset
|
494 |
9f1355689648
storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents:
10927
diff
changeset
|
495 it("by id (before and after) #full_id_range", function () |
9f1355689648
storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents:
10927
diff
changeset
|
496 assert.truthy(archive.caps and archive.caps.full_id_range, "full ID range support") |
9f1355689648
storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents:
10927
diff
changeset
|
497 local data, err = archive:find("user", { |
9f1355689648
storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents:
10927
diff
changeset
|
498 ["after"] = test_data[1][1]; |
9f1355689648
storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents:
10927
diff
changeset
|
499 ["before"] = test_data[4][1]; |
9f1355689648
storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents:
10927
diff
changeset
|
500 }); |
9f1355689648
storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents:
10927
diff
changeset
|
501 assert.truthy(data, err); |
9f1355689648
storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents:
10927
diff
changeset
|
502 local count = 0; |
9f1355689648
storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents:
10927
diff
changeset
|
503 for id, item in data do |
9f1355689648
storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents:
10927
diff
changeset
|
504 count = count + 1; |
9f1355689648
storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents:
10927
diff
changeset
|
505 assert.truthy(id); |
9f1355689648
storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents:
10927
diff
changeset
|
506 assert.equal(test_data[1+count][1], id); |
9f1355689648
storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents:
10927
diff
changeset
|
507 assert(st.is_stanza(item)); |
9f1355689648
storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents:
10927
diff
changeset
|
508 assert.equal("test", item.name); |
9f1355689648
storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents:
10927
diff
changeset
|
509 assert.equal("urn:example:foo", item.attr.xmlns); |
9f1355689648
storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents:
10927
diff
changeset
|
510 assert.equal(2, #item.tags); |
9f1355689648
storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents:
10927
diff
changeset
|
511 end |
9f1355689648
storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents:
10927
diff
changeset
|
512 assert.equal(2, count); |
9f1355689648
storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents:
10927
diff
changeset
|
513 end); |
9f1355689648
storage tests: Test querys with both before and after IDs
Kim Alvefur <zash@zash.se>
parents:
10927
diff
changeset
|
514 |
11276
7b2ee8995af9
storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents:
11273
diff
changeset
|
515 it("by multiple ids", function () |
11424
2358299bc928
core.storagemanager: s/Multilpe/Multiple/ [codespell]
Kim Alvefur <zash@zash.se>
parents:
11354
diff
changeset
|
516 assert.truthy(archive.caps and archive.caps.ids, "Multiple ID query") |
11276
7b2ee8995af9
storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents:
11273
diff
changeset
|
517 local data, err = archive:find("user", { |
7b2ee8995af9
storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents:
11273
diff
changeset
|
518 ["ids"] = { |
7b2ee8995af9
storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents:
11273
diff
changeset
|
519 test_data[2][1]; |
7b2ee8995af9
storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents:
11273
diff
changeset
|
520 test_data[4][1]; |
7b2ee8995af9
storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents:
11273
diff
changeset
|
521 }; |
7b2ee8995af9
storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents:
11273
diff
changeset
|
522 }); |
7b2ee8995af9
storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents:
11273
diff
changeset
|
523 assert.truthy(data, err); |
7b2ee8995af9
storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents:
11273
diff
changeset
|
524 local count = 0; |
7b2ee8995af9
storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents:
11273
diff
changeset
|
525 for id, item in data do |
7b2ee8995af9
storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents:
11273
diff
changeset
|
526 count = count + 1; |
7b2ee8995af9
storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents:
11273
diff
changeset
|
527 assert.truthy(id); |
7b2ee8995af9
storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents:
11273
diff
changeset
|
528 assert.equal(test_data[count==1 and 2 or 4][1], id); |
7b2ee8995af9
storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents:
11273
diff
changeset
|
529 assert(st.is_stanza(item)); |
7b2ee8995af9
storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents:
11273
diff
changeset
|
530 assert.equal("test", item.name); |
7b2ee8995af9
storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents:
11273
diff
changeset
|
531 assert.equal("urn:example:foo", item.attr.xmlns); |
7b2ee8995af9
storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents:
11273
diff
changeset
|
532 assert.equal(2, #item.tags); |
7b2ee8995af9
storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents:
11273
diff
changeset
|
533 end |
7b2ee8995af9
storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents:
11273
diff
changeset
|
534 assert.equal(2, count); |
7b2ee8995af9
storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents:
11273
diff
changeset
|
535 |
7b2ee8995af9
storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents:
11273
diff
changeset
|
536 end); |
7b2ee8995af9
storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents:
11273
diff
changeset
|
537 |
7b2ee8995af9
storage tests: Add test for querying a set of IDs
Kim Alvefur <zash@zash.se>
parents:
11273
diff
changeset
|
538 |
11353
367e6beaf8ab
storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents:
11276
diff
changeset
|
539 it("can be queried in reverse", function () |
367e6beaf8ab
storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents:
11276
diff
changeset
|
540 |
367e6beaf8ab
storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents:
11276
diff
changeset
|
541 local data, err = archive:find("user", { |
367e6beaf8ab
storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents:
11276
diff
changeset
|
542 reverse = true; |
367e6beaf8ab
storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents:
11276
diff
changeset
|
543 limit = 3; |
367e6beaf8ab
storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents:
11276
diff
changeset
|
544 }); |
367e6beaf8ab
storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents:
11276
diff
changeset
|
545 assert.truthy(data, err); |
367e6beaf8ab
storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents:
11276
diff
changeset
|
546 |
367e6beaf8ab
storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents:
11276
diff
changeset
|
547 local i = #test_data; |
367e6beaf8ab
storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents:
11276
diff
changeset
|
548 for id, item in data do |
367e6beaf8ab
storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents:
11276
diff
changeset
|
549 assert.truthy(id); |
367e6beaf8ab
storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents:
11276
diff
changeset
|
550 assert.equal(test_data[i][1], id); |
367e6beaf8ab
storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents:
11276
diff
changeset
|
551 assert(st.is_stanza(item)); |
367e6beaf8ab
storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents:
11276
diff
changeset
|
552 assert.equal("test", item.name); |
367e6beaf8ab
storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents:
11276
diff
changeset
|
553 assert.equal("urn:example:foo", item.attr.xmlns); |
367e6beaf8ab
storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents:
11276
diff
changeset
|
554 assert.equal(2, #item.tags); |
367e6beaf8ab
storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents:
11276
diff
changeset
|
555 i = i - 1; |
367e6beaf8ab
storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents:
11276
diff
changeset
|
556 end |
367e6beaf8ab
storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents:
11276
diff
changeset
|
557 |
367e6beaf8ab
storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents:
11276
diff
changeset
|
558 end); |
367e6beaf8ab
storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents:
11276
diff
changeset
|
559 |
367e6beaf8ab
storage: Test reverse-ordered queries
Kim Alvefur <zash@zash.se>
parents:
11276
diff
changeset
|
560 |
9466
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
561 end); |
9470
0d491bc98b9f
storagemanager tests: Add additional archive query tests
Matthew Wild <mwild1@gmail.com>
parents:
9467
diff
changeset
|
562 |
9471
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
563 it("can selectively delete items", function () |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
564 local delete_id; |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
565 do |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
566 local data = assert(archive:find("user", {})); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
567 local count = 0; |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
568 for id, item, when in data do --luacheck: ignore 213/item 213/when |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
569 count = count + 1; |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
570 if count == 2 then |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
571 delete_id = id; |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
572 end |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
573 assert.truthy(id); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
574 end |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
575 assert.equal(#test_data, count); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
576 end |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
577 |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
578 assert(archive:delete("user", { key = delete_id })); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
579 |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
580 do |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
581 local data = assert(archive:find("user", {})); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
582 local count = 0; |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
583 for id, item, when in data do --luacheck: ignore 213/item 213/when |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
584 count = count + 1; |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
585 assert.truthy(id); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
586 assert.not_equal(delete_id, id); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
587 end |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
588 assert.equal(#test_data-1, count); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
589 end |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
590 end); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
591 |
9466
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
592 it("can be purged", function () |
10541
6c6ff4509082
tests: Silence [luacheck] warnings
Kim Alvefur <zash@zash.se>
parents:
9691
diff
changeset
|
593 -- luacheck: ignore 211/err |
9466
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
594 local ok, err = archive:delete("user"); |
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
595 assert.truthy(ok); |
9467
2098794ac866
storagemanager tests: Add some additional checks
Matthew Wild <mwild1@gmail.com>
parents:
9466
diff
changeset
|
596 local data, err = archive:find("user", { |
2098794ac866
storagemanager tests: Add some additional checks
Matthew Wild <mwild1@gmail.com>
parents:
9466
diff
changeset
|
597 with = "contact@example.com"; |
2098794ac866
storagemanager tests: Add some additional checks
Matthew Wild <mwild1@gmail.com>
parents:
9466
diff
changeset
|
598 }); |
2098794ac866
storagemanager tests: Add some additional checks
Matthew Wild <mwild1@gmail.com>
parents:
9466
diff
changeset
|
599 assert.truthy(data); |
2098794ac866
storagemanager tests: Add some additional checks
Matthew Wild <mwild1@gmail.com>
parents:
9466
diff
changeset
|
600 local count = 0; |
2098794ac866
storagemanager tests: Add some additional checks
Matthew Wild <mwild1@gmail.com>
parents:
9466
diff
changeset
|
601 for id, item, when in data do -- luacheck: ignore id item when |
2098794ac866
storagemanager tests: Add some additional checks
Matthew Wild <mwild1@gmail.com>
parents:
9466
diff
changeset
|
602 count = count + 1; |
2098794ac866
storagemanager tests: Add some additional checks
Matthew Wild <mwild1@gmail.com>
parents:
9466
diff
changeset
|
603 end |
2098794ac866
storagemanager tests: Add some additional checks
Matthew Wild <mwild1@gmail.com>
parents:
9466
diff
changeset
|
604 assert.equal(0, count); |
9466
b70ce39d366f
storagemanager tests: Add initial basic tests for archive stores
Matthew Wild <mwild1@gmail.com>
parents:
9452
diff
changeset
|
605 end); |
9471
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
606 |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
607 it("can truncate the oldest items", function () |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
608 local username = "user-truncate"; |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
609 for i = 1, 10 do |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
610 assert(archive:append(username, nil, test_stanza, i, "contact@example.com")); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
611 end |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
612 assert(archive:delete(username, { truncate = 3 })); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
613 |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
614 do |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
615 local data = assert(archive:find(username, {})); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
616 local count = 0; |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
617 for id, item, when in data do --luacheck: ignore 213/when |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
618 count = count + 1; |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
619 assert.truthy(id); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
620 assert(st.is_stanza(item)); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
621 assert(when > 7, ("%d > 7"):format(when)); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
622 end |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
623 assert.equal(3, count); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
624 end |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
625 end); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
626 |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
627 it("overwrites existing keys with new data", function () |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
628 local prefix = ("a"):rep(50); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
629 local username = "user-overwrite"; |
11739
e0d0680e04cc
core.storagemanager: Respect archive ids issued by storage drivers in tests
Kim Alvefur <zash@zash.se>
parents:
11424
diff
changeset
|
630 local a1 = assert(archive:append(username, prefix.."-1", test_stanza, test_time, "contact@example.com")); |
e0d0680e04cc
core.storagemanager: Respect archive ids issued by storage drivers in tests
Kim Alvefur <zash@zash.se>
parents:
11424
diff
changeset
|
631 local a2 = assert(archive:append(username, prefix.."-2", test_stanza, test_time, "contact@example.com")); |
e0d0680e04cc
core.storagemanager: Respect archive ids issued by storage drivers in tests
Kim Alvefur <zash@zash.se>
parents:
11424
diff
changeset
|
632 local ids = { a1, a2, }; |
9471
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
633 |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
634 do |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
635 local data = assert(archive:find(username, {})); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
636 local count = 0; |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
637 for id, item, when in data do --luacheck: ignore 213/when |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
638 count = count + 1; |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
639 assert.truthy(id); |
11739
e0d0680e04cc
core.storagemanager: Respect archive ids issued by storage drivers in tests
Kim Alvefur <zash@zash.se>
parents:
11424
diff
changeset
|
640 assert.equals(ids[count], id); |
9471
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
641 assert(st.is_stanza(item)); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
642 end |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
643 assert.equal(2, count); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
644 end |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
645 |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
646 local new_stanza = st.clone(test_stanza); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
647 new_stanza.attr.foo = "bar"; |
11739
e0d0680e04cc
core.storagemanager: Respect archive ids issued by storage drivers in tests
Kim Alvefur <zash@zash.se>
parents:
11424
diff
changeset
|
648 assert(archive:append(username, a2, new_stanza, test_time+1, "contact2@example.com")); |
9471
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
649 |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
650 do |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
651 local data = assert(archive:find(username, {})); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
652 local count = 0; |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
653 for id, item, when in data do |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
654 count = count + 1; |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
655 assert.truthy(id); |
11739
e0d0680e04cc
core.storagemanager: Respect archive ids issued by storage drivers in tests
Kim Alvefur <zash@zash.se>
parents:
11424
diff
changeset
|
656 assert.equals(ids[count], id); |
9471
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
657 assert(st.is_stanza(item)); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
658 if count == 2 then |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
659 assert.equals(test_time+1, when); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
660 assert.equals("bar", item.attr.foo); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
661 end |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
662 end |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
663 assert.equal(2, count); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
664 end |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
665 end); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
666 |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
667 it("can contain multiple long unique keys #issue1073", function () |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
668 local prefix = ("a"):rep(50); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
669 assert(archive:append("user-issue1073", prefix.."-1", test_stanza, test_time, "contact@example.com")); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
670 assert(archive:append("user-issue1073", prefix.."-2", test_stanza, test_time, "contact@example.com")); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
671 |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
672 local data = assert(archive:find("user-issue1073", {})); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
673 local count = 0; |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
674 for id, item, when in data do --luacheck: ignore 213/when |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
675 count = count + 1; |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
676 assert.truthy(id); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
677 assert(st.is_stanza(item)); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
678 end |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
679 assert.equal(2, count); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
680 assert(archive:delete("user-issue1073")); |
6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
Matthew Wild <mwild1@gmail.com>
parents:
9470
diff
changeset
|
681 end); |
10837
f23363380599
mod_storage_internal: Implement key-value API
Kim Alvefur <zash@zash.se>
parents:
10836
diff
changeset
|
682 |
f23363380599
mod_storage_internal: Implement key-value API
Kim Alvefur <zash@zash.se>
parents:
10836
diff
changeset
|
683 it("can be treated as a map store", function () |
f23363380599
mod_storage_internal: Implement key-value API
Kim Alvefur <zash@zash.se>
parents:
10836
diff
changeset
|
684 assert.falsy(archive:get("mapuser", "no-such-id")); |
f23363380599
mod_storage_internal: Implement key-value API
Kim Alvefur <zash@zash.se>
parents:
10836
diff
changeset
|
685 assert.falsy(archive:set("mapuser", "no-such-id", test_stanza)); |
f23363380599
mod_storage_internal: Implement key-value API
Kim Alvefur <zash@zash.se>
parents:
10836
diff
changeset
|
686 |
f23363380599
mod_storage_internal: Implement key-value API
Kim Alvefur <zash@zash.se>
parents:
10836
diff
changeset
|
687 local id = archive:append("mapuser", nil, test_stanza, test_time, "contact@example.com"); |
10842
5a6ba2f38e2b
mod_storage_internal: Fix keeping old timestamp in archive map API
Kim Alvefur <zash@zash.se>
parents:
10837
diff
changeset
|
688 do |
5a6ba2f38e2b
mod_storage_internal: Fix keeping old timestamp in archive map API
Kim Alvefur <zash@zash.se>
parents:
10837
diff
changeset
|
689 local stanza_roundtrip, when, with = archive:get("mapuser", id); |
11354
10fba62332c5
mod_storage_sql: Implement map-like API for archives
Kim Alvefur <zash@zash.se>
parents:
11353
diff
changeset
|
690 assert.same(tostring(test_stanza), tostring(stanza_roundtrip), "same stanza is returned"); |
10842
5a6ba2f38e2b
mod_storage_internal: Fix keeping old timestamp in archive map API
Kim Alvefur <zash@zash.se>
parents:
10837
diff
changeset
|
691 assert.equal(test_time, when, "same 'when' is returned"); |
5a6ba2f38e2b
mod_storage_internal: Fix keeping old timestamp in archive map API
Kim Alvefur <zash@zash.se>
parents:
10837
diff
changeset
|
692 assert.equal("contact@example.com", with, "same 'with' is returned"); |
5a6ba2f38e2b
mod_storage_internal: Fix keeping old timestamp in archive map API
Kim Alvefur <zash@zash.se>
parents:
10837
diff
changeset
|
693 end |
10837
f23363380599
mod_storage_internal: Implement key-value API
Kim Alvefur <zash@zash.se>
parents:
10836
diff
changeset
|
694 |
f23363380599
mod_storage_internal: Implement key-value API
Kim Alvefur <zash@zash.se>
parents:
10836
diff
changeset
|
695 local replacement_stanza = st.stanza("test", { xmlns = "urn:example:foo" }) |
f23363380599
mod_storage_internal: Implement key-value API
Kim Alvefur <zash@zash.se>
parents:
10836
diff
changeset
|
696 :tag("bar"):up() |
f23363380599
mod_storage_internal: Implement key-value API
Kim Alvefur <zash@zash.se>
parents:
10836
diff
changeset
|
697 :reset(); |
10842
5a6ba2f38e2b
mod_storage_internal: Fix keeping old timestamp in archive map API
Kim Alvefur <zash@zash.se>
parents:
10837
diff
changeset
|
698 assert(archive:set("mapuser", id, replacement_stanza, test_time+1)); |
5a6ba2f38e2b
mod_storage_internal: Fix keeping old timestamp in archive map API
Kim Alvefur <zash@zash.se>
parents:
10837
diff
changeset
|
699 |
5a6ba2f38e2b
mod_storage_internal: Fix keeping old timestamp in archive map API
Kim Alvefur <zash@zash.se>
parents:
10837
diff
changeset
|
700 do |
5a6ba2f38e2b
mod_storage_internal: Fix keeping old timestamp in archive map API
Kim Alvefur <zash@zash.se>
parents:
10837
diff
changeset
|
701 local replaced, when, with = archive:get("mapuser", id); |
11354
10fba62332c5
mod_storage_sql: Implement map-like API for archives
Kim Alvefur <zash@zash.se>
parents:
11353
diff
changeset
|
702 assert.same(tostring(replacement_stanza), tostring(replaced), "replaced stanza is returned"); |
10842
5a6ba2f38e2b
mod_storage_internal: Fix keeping old timestamp in archive map API
Kim Alvefur <zash@zash.se>
parents:
10837
diff
changeset
|
703 assert.equal(test_time+1, when, "modified 'when' is returned"); |
5a6ba2f38e2b
mod_storage_internal: Fix keeping old timestamp in archive map API
Kim Alvefur <zash@zash.se>
parents:
10837
diff
changeset
|
704 assert.equal("contact@example.com", with, "original 'with' is returned"); |
5a6ba2f38e2b
mod_storage_internal: Fix keeping old timestamp in archive map API
Kim Alvefur <zash@zash.se>
parents:
10837
diff
changeset
|
705 end |
10837
f23363380599
mod_storage_internal: Implement key-value API
Kim Alvefur <zash@zash.se>
parents:
10836
diff
changeset
|
706 end); |
f23363380599
mod_storage_internal: Implement key-value API
Kim Alvefur <zash@zash.se>
parents:
10836
diff
changeset
|
707 |
12598
a2624315d30e
storage tests: Add test for the archive:summary API
Kim Alvefur <zash@zash.se>
parents:
11739
diff
changeset
|
708 it("the summary api works", function() |
a2624315d30e
storage tests: Add test for the archive:summary API
Kim Alvefur <zash@zash.se>
parents:
11739
diff
changeset
|
709 assert.truthy(archive:delete("summary-user")); |
a2624315d30e
storage tests: Add test for the archive:summary API
Kim Alvefur <zash@zash.se>
parents:
11739
diff
changeset
|
710 local first_sid = archive:append("summary-user", nil, test_stanza, test_time, "contact@example.com"); |
a2624315d30e
storage tests: Add test for the archive:summary API
Kim Alvefur <zash@zash.se>
parents:
11739
diff
changeset
|
711 local second_sid = archive:append("summary-user", nil, test_stanza, test_time+1, "contact@example.com"); |
a2624315d30e
storage tests: Add test for the archive:summary API
Kim Alvefur <zash@zash.se>
parents:
11739
diff
changeset
|
712 assert.truthy(first_sid and second_sid, "preparations failed") |
a2624315d30e
storage tests: Add test for the archive:summary API
Kim Alvefur <zash@zash.se>
parents:
11739
diff
changeset
|
713 --- |
a2624315d30e
storage tests: Add test for the archive:summary API
Kim Alvefur <zash@zash.se>
parents:
11739
diff
changeset
|
714 |
a2624315d30e
storage tests: Add test for the archive:summary API
Kim Alvefur <zash@zash.se>
parents:
11739
diff
changeset
|
715 local user_summary, err = archive:summary("summary-user"); |
a2624315d30e
storage tests: Add test for the archive:summary API
Kim Alvefur <zash@zash.se>
parents:
11739
diff
changeset
|
716 assert.is_table(user_summary, err); |
a2624315d30e
storage tests: Add test for the archive:summary API
Kim Alvefur <zash@zash.se>
parents:
11739
diff
changeset
|
717 assert.same({ ["contact@example.com"] = 2 }, user_summary.counts, "summary.counts matches"); |
a2624315d30e
storage tests: Add test for the archive:summary API
Kim Alvefur <zash@zash.se>
parents:
11739
diff
changeset
|
718 assert.same({ ["contact@example.com"] = test_time }, user_summary.earliest, "summary.earliest matches"); |
a2624315d30e
storage tests: Add test for the archive:summary API
Kim Alvefur <zash@zash.se>
parents:
11739
diff
changeset
|
719 assert.same({ ["contact@example.com"] = test_time+1 }, user_summary.latest, "summary.latest matches"); |
a2624315d30e
storage tests: Add test for the archive:summary API
Kim Alvefur <zash@zash.se>
parents:
11739
diff
changeset
|
720 if user_summary.body then |
a2624315d30e
storage tests: Add test for the archive:summary API
Kim Alvefur <zash@zash.se>
parents:
11739
diff
changeset
|
721 assert.same({ ["contact@example.com"] = test_stanza:get_child_text("body") }, user_summary.body, "summary.body matches"); |
a2624315d30e
storage tests: Add test for the archive:summary API
Kim Alvefur <zash@zash.se>
parents:
11739
diff
changeset
|
722 end |
a2624315d30e
storage tests: Add test for the archive:summary API
Kim Alvefur <zash@zash.se>
parents:
11739
diff
changeset
|
723 end); |
a2624315d30e
storage tests: Add test for the archive:summary API
Kim Alvefur <zash@zash.se>
parents:
11739
diff
changeset
|
724 |
9389
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
725 end); |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
726 end); |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
727 end |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
728 end); |