aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-09-05 16:21:10 +0200
committerKim Alvefur <zash@zash.se>2021-09-05 16:21:10 +0200
commit1546e59310f4eb2888227a0f09a4554cc7da145d (patch)
tree2cf3abe2e38a012381c77a000efb42bdbb5bfa7d /spec
parente3c0a877bf2eaf1f5c3f150ad66de0af331e885b (diff)
downloadprosody-1546e59310f4eb2888227a0f09a4554cc7da145d.tar.gz
prosody-1546e59310f4eb2888227a0f09a4554cc7da145d.zip
util.pubsub: Add support for limiting number of items to retrieve
Hopefully this will eventually be upgraded to RSM, which is why the argument is called 'resultspec' and is a table.
Diffstat (limited to 'spec')
-rw-r--r--spec/util_pubsub_spec.lua57
1 files changed, 57 insertions, 0 deletions
diff --git a/spec/util_pubsub_spec.lua b/spec/util_pubsub_spec.lua
index 8476cb50..2dc5ca60 100644
--- a/spec/util_pubsub_spec.lua
+++ b/spec/util_pubsub_spec.lua
@@ -528,4 +528,61 @@ describe("util.pubsub", function ()
end);
end)
+
+ describe("max_items", function ()
+ it("works", function ()
+ local service = pubsub.new { };
+
+ local ok = service:create("node", true)
+ assert.truthy(ok);
+
+ for i = 1, 20 do
+ assert.truthy(service:publish("node", true, "item"..tostring(i), "data"..tostring(i)));
+ end
+
+ do
+ local ok, items = service:get_items("node", true, nil, { max = 3 });
+ assert.truthy(ok, items);
+ assert.equal(3, #items);
+ assert.same({
+ "item20",
+ "item19",
+ "item18",
+ item20 = "data20",
+ item19 = "data19",
+ item18 = "data18",
+ }, items, "items should be ordered by oldest first");
+ end
+
+ do
+ local ok, items = service:get_items("node", true, nil, { max = 10 });
+ assert.truthy(ok, items);
+ assert.equal(10, #items);
+ assert.same({
+ "item20",
+ "item19",
+ "item18",
+ "item17",
+ "item16",
+ "item15",
+ "item14",
+ "item13",
+ "item12",
+ "item11",
+ item20 = "data20",
+ item19 = "data19",
+ item18 = "data18",
+ item17 = "data17",
+ item16 = "data16",
+ item15 = "data15",
+ item14 = "data14",
+ item13 = "data13",
+ item12 = "data12",
+ item11 = "data11",
+ }, items, "items should be ordered by oldest first");
+ end
+
+ end);
+
+ end)
end);