Annotate

spec/util_pubsub_spec.lua @ 9159:a0fd7064f4ac

util.pubsub: Drop now redundant capabilities from tests
author Kim Alvefur <zash@zash.se>
date Wed, 08 Aug 2018 21:49:41 +0200
parent 9004:50a0f405e6c9
child 9169:3ec013185c15
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8564
fd41dc4a78e9 util_pubsub_spec: Move util.pubsub import into a setup block
Kim Alvefur <zash@zash.se>
parents: 8558
diff changeset
1 local pubsub;
fd41dc4a78e9 util_pubsub_spec: Move util.pubsub import into a setup block
Kim Alvefur <zash@zash.se>
parents: 8558
diff changeset
2 setup(function ()
fd41dc4a78e9 util_pubsub_spec: Move util.pubsub import into a setup block
Kim Alvefur <zash@zash.se>
parents: 8558
diff changeset
3 pubsub = require "util.pubsub";
fd41dc4a78e9 util_pubsub_spec: Move util.pubsub import into a setup block
Kim Alvefur <zash@zash.se>
parents: 8558
diff changeset
4 end);
fd41dc4a78e9 util_pubsub_spec: Move util.pubsub import into a setup block
Kim Alvefur <zash@zash.se>
parents: 8558
diff changeset
5
8558
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 describe("util.pubsub", function ()
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 describe("simple node creation and deletion", function ()
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 -- Roughly a port of scansion/scripts/pubsub_createdelete.scs
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 local service = pubsub.new();
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 describe("#create", function ()
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 it("creates a new node", function ()
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 assert.truthy(service:create("princely_musings", true));
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 end);
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 it("fails to create the same node again", function ()
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 assert.falsy(service:create("princely_musings", true));
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 end);
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 end);
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 describe("#delete", function ()
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 it("deletes the node", function ()
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 assert.truthy(service:delete("princely_musings", true));
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 end);
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 it("can't delete an already deleted node", function ()
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 assert.falsy(service:delete("princely_musings", true));
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 end);
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 end);
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 end);
8647
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
31
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
32 describe("simple publishing", function ()
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
33 local broadcaster = spy.new(function () end);
8817
9a3066a580ad spec/util_pubsub: Test whether someone can subscribe to a node
Kim Alvefur <zash@zash.se>
parents: 8647
diff changeset
34 local service = pubsub.new({
9a3066a580ad spec/util_pubsub: Test whether someone can subscribe to a node
Kim Alvefur <zash@zash.se>
parents: 8647
diff changeset
35 broadcaster = broadcaster;
9a3066a580ad spec/util_pubsub: Test whether someone can subscribe to a node
Kim Alvefur <zash@zash.se>
parents: 8647
diff changeset
36 });
8647
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
37
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
38 it("creates a node", function ()
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
39 assert.truthy(service:create("node", true));
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
40 end);
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
41
8817
9a3066a580ad spec/util_pubsub: Test whether someone can subscribe to a node
Kim Alvefur <zash@zash.se>
parents: 8647
diff changeset
42 it("lets someone subscribe", function ()
9a3066a580ad spec/util_pubsub: Test whether someone can subscribe to a node
Kim Alvefur <zash@zash.se>
parents: 8647
diff changeset
43 assert.truthy(service:add_subscription("node", true, "someone"));
9a3066a580ad spec/util_pubsub: Test whether someone can subscribe to a node
Kim Alvefur <zash@zash.se>
parents: 8647
diff changeset
44 end);
9a3066a580ad spec/util_pubsub: Test whether someone can subscribe to a node
Kim Alvefur <zash@zash.se>
parents: 8647
diff changeset
45
8647
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
46 it("publishes an item", function ()
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
47 assert.truthy(service:publish("node", true, "1", "item 1"));
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
48 end);
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
49
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
50 it("called the broadcaster", function ()
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
51 assert.spy(broadcaster).was_called();
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
52 end);
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
53
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
54 it("should return one item", function ()
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
55 local ok, ret = service:get_items("node", true);
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
56 assert.truthy(ok);
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
57 assert.same({ "1", ["1"] = "item 1" }, ret);
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
58 end);
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
59
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
60 end);
9004
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
61
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
62 describe("#issue1082", function ()
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
63 local service = pubsub.new();
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
64
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
65 it("creates a node with max_items = 1", function ()
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
66 assert.truthy(service:create("node", true, { max_items = 1 }));
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
67 end);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
68
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
69 it("changes max_items to 2", function ()
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
70 assert.truthy(service:set_node_config("node", true, { max_items = 2 }));
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
71 end);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
72
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
73 it("publishes one item", function ()
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
74 assert.truthy(service:publish("node", true, "1", "item 1"));
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
75 end);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
76
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
77 it("should return one item", function ()
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
78 local ok, ret = service:get_items("node", true);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
79 assert.truthy(ok);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
80 assert.same({ "1", ["1"] = "item 1" }, ret);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
81 end);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
82
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
83 it("publishes another item", function ()
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
84 assert.truthy(service:publish("node", true, "2", "item 2"));
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
85 end);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
86
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
87 it("should return two items", function ()
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
88 local ok, ret = service:get_items("node", true);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
89 assert.truthy(ok);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
90 assert.same({
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
91 "2",
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
92 "1",
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
93 ["1"] = "item 1",
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
94 ["2"] = "item 2",
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
95 }, ret);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
96 end);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
97
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
98 it("publishes yet another item", function ()
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
99 assert.truthy(service:publish("node", true, "3", "item 3"));
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
100 end);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
101
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
102 it("should still return only two items", function ()
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
103 local ok, ret = service:get_items("node", true);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
104 assert.truthy(ok);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
105 assert.same({
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
106 "3",
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
107 "2",
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
108 ["2"] = "item 2",
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
109 ["3"] = "item 3",
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
110 }, ret);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
111 end);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
112
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
113 end);
8558
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
114 end);