Software / code / prosody
Comparison
spec/core_storagemanager_spec.lua @ 9471:6798fcd25e9c
storagemanager tests: Add many more archive tests, including (failing) cases for #1200 and #1073
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2018 14:10:55 +0100 |
| parent | 9470:0d491bc98b9f |
| child | 9472:ea40fe484c38 |
comparison
equal
deleted
inserted
replaced
| 9470:0d491bc98b9f | 9471:6798fcd25e9c |
|---|---|
| 201 assert(when >= test_time, ("%d >= %d"):format(when, test_time)); | 201 assert(when >= test_time, ("%d >= %d"):format(when, test_time)); |
| 202 assert(when <= test_time+1, ("%d <= %d"):format(when, test_time+1)); | 202 assert(when <= test_time+1, ("%d <= %d"):format(when, test_time+1)); |
| 203 end | 203 end |
| 204 assert.equal(2, count); | 204 assert.equal(2, count); |
| 205 end); | 205 end); |
| 206 end); | |
| 207 | |
| 208 it("can selectively delete items", function () | |
| 209 local delete_id; | |
| 210 do | |
| 211 local data = assert(archive:find("user", {})); | |
| 212 local count = 0; | |
| 213 for id, item, when in data do --luacheck: ignore 213/item 213/when | |
| 214 count = count + 1; | |
| 215 if count == 2 then | |
| 216 delete_id = id; | |
| 217 end | |
| 218 assert.truthy(id); | |
| 219 end | |
| 220 assert.equal(#test_data, count); | |
| 221 end | |
| 222 | |
| 223 assert(archive:delete("user", { key = delete_id })); | |
| 224 | |
| 225 do | |
| 226 local data = assert(archive:find("user", {})); | |
| 227 local count = 0; | |
| 228 for id, item, when in data do --luacheck: ignore 213/item 213/when | |
| 229 count = count + 1; | |
| 230 assert.truthy(id); | |
| 231 assert.not_equal(delete_id, id); | |
| 232 end | |
| 233 assert.equal(#test_data-1, count); | |
| 234 end | |
| 206 end); | 235 end); |
| 207 | 236 |
| 208 it("can be purged", function () | 237 it("can be purged", function () |
| 209 local ok, err = archive:delete("user"); | 238 local ok, err = archive:delete("user"); |
| 210 assert.truthy(ok); | 239 assert.truthy(ok); |
| 216 for id, item, when in data do -- luacheck: ignore id item when | 245 for id, item, when in data do -- luacheck: ignore id item when |
| 217 count = count + 1; | 246 count = count + 1; |
| 218 end | 247 end |
| 219 assert.equal(0, count); | 248 assert.equal(0, count); |
| 220 end); | 249 end); |
| 250 | |
| 251 it("can truncate the oldest items", function () | |
| 252 local username = "user-truncate"; | |
| 253 for i = 1, 10 do | |
| 254 assert(archive:append(username, nil, test_stanza, i, "contact@example.com")); | |
| 255 end | |
| 256 assert(archive:delete(username, { truncate = 3 })); | |
| 257 | |
| 258 do | |
| 259 local data = assert(archive:find(username, {})); | |
| 260 local count = 0; | |
| 261 for id, item, when in data do --luacheck: ignore 213/when | |
| 262 count = count + 1; | |
| 263 assert.truthy(id); | |
| 264 assert(st.is_stanza(item)); | |
| 265 assert(when > 7, ("%d > 7"):format(when)); | |
| 266 end | |
| 267 assert.equal(3, count); | |
| 268 end | |
| 269 end); | |
| 270 | |
| 271 it("overwrites existing keys with new data", function () | |
| 272 local prefix = ("a"):rep(50); | |
| 273 local username = "user-overwrite"; | |
| 274 assert(archive:append(username, prefix.."-1", test_stanza, test_time, "contact@example.com")); | |
| 275 assert(archive:append(username, prefix.."-2", test_stanza, test_time, "contact@example.com")); | |
| 276 | |
| 277 do | |
| 278 local data = assert(archive:find(username, {})); | |
| 279 local count = 0; | |
| 280 for id, item, when in data do --luacheck: ignore 213/when | |
| 281 count = count + 1; | |
| 282 assert.truthy(id); | |
| 283 assert.equals(("%s-%d"):format(prefix, count), id); | |
| 284 assert(st.is_stanza(item)); | |
| 285 end | |
| 286 assert.equal(2, count); | |
| 287 end | |
| 288 | |
| 289 local new_stanza = st.clone(test_stanza); | |
| 290 new_stanza.attr.foo = "bar"; | |
| 291 assert(archive:append(username, prefix.."-2", new_stanza, test_time+1, "contact2@example.com")); | |
| 292 | |
| 293 do | |
| 294 local data = assert(archive:find(username, {})); | |
| 295 local count = 0; | |
| 296 for id, item, when in data do | |
| 297 count = count + 1; | |
| 298 assert.truthy(id); | |
| 299 assert.equals(("%s-%d"):format(prefix, count), id); | |
| 300 assert(st.is_stanza(item)); | |
| 301 if count == 2 then | |
| 302 assert.equals(test_time+1, when); | |
| 303 assert.equals("bar", item.attr.foo); | |
| 304 end | |
| 305 end | |
| 306 assert.equal(2, count); | |
| 307 end | |
| 308 end); | |
| 309 | |
| 310 it("can contain multiple long unique keys #issue1073", function () | |
| 311 local prefix = ("a"):rep(50); | |
| 312 assert(archive:append("user-issue1073", prefix.."-1", test_stanza, test_time, "contact@example.com")); | |
| 313 assert(archive:append("user-issue1073", prefix.."-2", test_stanza, test_time, "contact@example.com")); | |
| 314 | |
| 315 local data = assert(archive:find("user-issue1073", {})); | |
| 316 local count = 0; | |
| 317 for id, item, when in data do --luacheck: ignore 213/when | |
| 318 print(id) | |
| 319 count = count + 1; | |
| 320 assert.truthy(id); | |
| 321 assert(st.is_stanza(item)); | |
| 322 end | |
| 323 assert.equal(2, count); | |
| 324 assert(archive:delete("user-issue1073")); | |
| 325 end); | |
| 221 end); | 326 end); |
| 222 end); | 327 end); |
| 223 end | 328 end |
| 224 end); | 329 end); |