spec/util_pubsub_spec.lua
changeset 9211 d3bb59ec0173
parent 9209 33ee40dc3e25
child 9212 69e17edf8796
--- a/spec/util_pubsub_spec.lua	Sat Aug 18 15:26:35 2018 +0100
+++ b/spec/util_pubsub_spec.lua	Sat Aug 18 15:28:08 2018 +0100
@@ -310,5 +310,33 @@
 				assert.equal("bye", item);
 			end);
 		end);
+		describe("get_items()", function ()
+			it("fails on non-existent nodes", function ()
+				local ok, err = service:get_items("no-node", true);
+				assert.is_falsy(ok);
+				assert.equal("item-not-found", err);
+			end);
+			it("returns no items on an empty node", function ()
+				local ok, items = service:get_items("test", true);
+				assert.is_true(ok);
+				assert.equal(0, #items);
+				assert.is_nil(next(items));				
+			end);
+			it("returns no items on an empty node", function ()
+				local ok, items = service:get_items("test", true);
+				assert.is_true(ok);
+				assert.equal(0, #items);
+				assert.is_nil((next(items)));
+			end);
+			it("returns all published items", function ()
+				service:publish("test", true, "one", "hello world");
+				service:publish("test", true, "two", "hello again");
+				service:publish("test", true, "three", "hey");
+				service:publish("test", true, "one", "bye");
+				local ok, items = service:get_items("test", true);
+				assert.is_true(ok);
+				assert.same({ "one", "three", "two", two = "hello again", three = "hey", one = "bye" }, items);
+			end);
+		end);
 	end);
 end);