Software /
code /
prosody
Comparison
spec/core_storagemanager_spec.lua @ 11739:e0d0680e04cc
core.storagemanager: Respect archive ids issued by storage drivers in tests
Storage drivers may issue their own IDs tho none of the included ones do
this atm, but the 3rd party module mod_storage_xmlarchive has its
special format.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 15 Aug 2021 12:28:58 +0200 |
parent | 11424:2358299bc928 |
child | 12589:39ae08180c81 |
child | 12598:a2624315d30e |
comparison
equal
deleted
inserted
replaced
11738:3f1450ec37f4 | 11739:e0d0680e04cc |
---|---|
495 end); | 495 end); |
496 | 496 |
497 it("overwrites existing keys with new data", function () | 497 it("overwrites existing keys with new data", function () |
498 local prefix = ("a"):rep(50); | 498 local prefix = ("a"):rep(50); |
499 local username = "user-overwrite"; | 499 local username = "user-overwrite"; |
500 assert(archive:append(username, prefix.."-1", test_stanza, test_time, "contact@example.com")); | 500 local a1 = assert(archive:append(username, prefix.."-1", test_stanza, test_time, "contact@example.com")); |
501 assert(archive:append(username, prefix.."-2", test_stanza, test_time, "contact@example.com")); | 501 local a2 = assert(archive:append(username, prefix.."-2", test_stanza, test_time, "contact@example.com")); |
502 local ids = { a1, a2, }; | |
502 | 503 |
503 do | 504 do |
504 local data = assert(archive:find(username, {})); | 505 local data = assert(archive:find(username, {})); |
505 local count = 0; | 506 local count = 0; |
506 for id, item, when in data do --luacheck: ignore 213/when | 507 for id, item, when in data do --luacheck: ignore 213/when |
507 count = count + 1; | 508 count = count + 1; |
508 assert.truthy(id); | 509 assert.truthy(id); |
509 assert.equals(("%s-%d"):format(prefix, count), id); | 510 assert.equals(ids[count], id); |
510 assert(st.is_stanza(item)); | 511 assert(st.is_stanza(item)); |
511 end | 512 end |
512 assert.equal(2, count); | 513 assert.equal(2, count); |
513 end | 514 end |
514 | 515 |
515 local new_stanza = st.clone(test_stanza); | 516 local new_stanza = st.clone(test_stanza); |
516 new_stanza.attr.foo = "bar"; | 517 new_stanza.attr.foo = "bar"; |
517 assert(archive:append(username, prefix.."-2", new_stanza, test_time+1, "contact2@example.com")); | 518 assert(archive:append(username, a2, new_stanza, test_time+1, "contact2@example.com")); |
518 | 519 |
519 do | 520 do |
520 local data = assert(archive:find(username, {})); | 521 local data = assert(archive:find(username, {})); |
521 local count = 0; | 522 local count = 0; |
522 for id, item, when in data do | 523 for id, item, when in data do |
523 count = count + 1; | 524 count = count + 1; |
524 assert.truthy(id); | 525 assert.truthy(id); |
525 assert.equals(("%s-%d"):format(prefix, count), id); | 526 assert.equals(ids[count], id); |
526 assert(st.is_stanza(item)); | 527 assert(st.is_stanza(item)); |
527 if count == 2 then | 528 if count == 2 then |
528 assert.equals(test_time+1, when); | 529 assert.equals(test_time+1, when); |
529 assert.equals("bar", item.attr.foo); | 530 assert.equals("bar", item.attr.foo); |
530 end | 531 end |