# HG changeset patch # User Matthew Wild # Date 1534070045 -3600 # Node ID c53663e13b51dfc570bc6c5d69e89fdfa35b5c1f # Parent 822e9c5ff4a43d66143cec2306d86c081acbd54f util.pubsub tests: Extend publishing tests to check for correct notification behaviour on subscribe/unsubscribe diff -r 822e9c5ff4a4 -r c53663e13b51 spec/util_pubsub_spec.lua --- a/spec/util_pubsub_spec.lua Sun Aug 12 11:33:22 2018 +0100 +++ b/spec/util_pubsub_spec.lua Sun Aug 12 11:34:05 2018 +0100 @@ -30,7 +30,10 @@ end); describe("simple publishing", function () - local broadcaster = spy.new(function () end); + local notified; + local broadcaster = spy.new(function (notif_type, node_name, subscribers, item) + notified = subscribers; + end); local service = pubsub.new({ broadcaster = broadcaster; }); @@ -45,6 +48,7 @@ it("publishes an item", function () assert.truthy(service:publish("node", true, "1", "item 1")); + assert.truthy(notified["someone"]); end); it("called the broadcaster", function () @@ -57,6 +61,14 @@ assert.same({ "1", ["1"] = "item 1" }, ret); end); + it("lets someone unsubscribe", function () + assert.truthy(service:remove_subscription("node", true, "someone")); + end); + + it("does not send notifications after subscription is removed", function () + assert.truthy(service:publish("node", true, "1", "item 1")); + assert.is_nil(notified["someone"]); + end); end); describe("#issue1082", function ()