mod_storage_internal, tests: Fix before/after combined with the 'reverse' flag
authorMatthew Wild <mwild1@gmail.com>
Tue, 12 Dec 2023 13:41:14 +0000
changeset 13406 6877786d73d7
parent 13405 626ab0af83af
child 13407 0369f6986824
mod_storage_internal, tests: Fix before/after combined with the 'reverse' flag
plugins/mod_storage_internal.lua
spec/core_storagemanager_spec.lua
--- a/plugins/mod_storage_internal.lua	Sat Dec 09 21:01:49 2023 +0100
+++ b/plugins/mod_storage_internal.lua	Tue Dec 12 13:41:14 2023 +0000
@@ -180,6 +180,7 @@
 				i = i - 1
 				return list[i]
 			end
+			query.before, query.after = query.after, query.before;
 		end
 		if query.key then
 			iter = it.filter(function(item)
--- a/spec/core_storagemanager_spec.lua	Sat Dec 09 21:01:49 2023 +0100
+++ b/spec/core_storagemanager_spec.lua	Tue Dec 12 13:41:14 2023 +0000
@@ -560,6 +560,30 @@
 
 					end);
 
+					-- This tests combines the reverse flag with 'before' and 'after' to
+					-- ensure behaviour remains correct
+					it("by id (before and after) in reverse #full_id_range", function ()
+						assert.truthy(archive.caps and archive.caps.full_id_range, "full ID range support")
+						local data, err = archive:find("user", {
+								["after"] = test_data[1][1];
+								["before"] = test_data[4][1];
+								reverse = true;
+							});
+						assert.truthy(data, err);
+						local count = 0;
+						for id, item in data do
+							count = count + 1;
+							assert.truthy(id);
+							assert.equal(test_data[4-count][1], id);
+							assert(st.is_stanza(item));
+							assert.equal("test", item.name);
+							assert.equal("urn:example:foo", item.attr.xmlns);
+							assert.equal(2, #item.tags);
+						end
+						assert.equal(2, count);
+					end);
+
+
 
 				end);