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