Changeset

9004:50a0f405e6c9

util_pubsub_spec: Add test for #1082
author Kim Alvefur <zash@zash.se>
date Tue, 10 Jul 2018 00:22:05 +0200
parents 9003:a971023e9b6e
children 9005:7203a1b65d1b
files spec/util_pubsub_spec.lua
diffstat 1 files changed, 53 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/spec/util_pubsub_spec.lua	Mon Jul 09 17:46:23 2018 +0100
+++ b/spec/util_pubsub_spec.lua	Tue Jul 10 00:22:05 2018 +0200
@@ -64,4 +64,57 @@
 		end);
 
 	end);
+
+	describe("#issue1082", function ()
+		local service = pubsub.new();
+
+		it("creates a node with max_items = 1", function ()
+			assert.truthy(service:create("node", true, { max_items = 1 }));
+		end);
+
+		it("changes max_items to 2", function ()
+			assert.truthy(service:set_node_config("node", true, { max_items = 2 }));
+		end);
+
+		it("publishes one item", function ()
+			assert.truthy(service:publish("node", true, "1", "item 1"));
+		end);
+
+		it("should return one item", function ()
+			local ok, ret = service:get_items("node", true);
+			assert.truthy(ok);
+			assert.same({ "1", ["1"] = "item 1" }, ret);
+		end);
+
+		it("publishes another item", function ()
+			assert.truthy(service:publish("node", true, "2", "item 2"));
+		end);
+
+		it("should return two items", function ()
+			local ok, ret = service:get_items("node", true);
+			assert.truthy(ok);
+			assert.same({
+				"2",
+				"1",
+				["1"] = "item 1",
+				["2"] = "item 2",
+			}, ret);
+		end);
+
+		it("publishes yet another item", function ()
+			assert.truthy(service:publish("node", true, "3", "item 3"));
+		end);
+
+		it("should still return only two items", function ()
+			local ok, ret = service:get_items("node", true);
+			assert.truthy(ok);
+			assert.same({
+				"3",
+				"2",
+				["2"] = "item 2",
+				["3"] = "item 3",
+			}, ret);
+		end);
+
+	end);
 end);