Annotate

spec/util_pubsub_spec.lua @ 12968:efdb7f2cd578

mod_debug_reset: New module to "reset" a running server (e.g. for testing) Plan to use this for integration tests.
author Matthew Wild <mwild1@gmail.com>
date Thu, 23 Mar 2023 14:40:51 +0000
parent 12153:26af75c20163
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
9176
1068f9b82e2b util.pubsub tests: Add TODO
Matthew Wild <mwild1@gmail.com>
parents: 9175
diff changeset
6 --[[TODO:
1068f9b82e2b util.pubsub tests: Add TODO
Matthew Wild <mwild1@gmail.com>
parents: 9175
diff changeset
7 Retract
1068f9b82e2b util.pubsub tests: Add TODO
Matthew Wild <mwild1@gmail.com>
parents: 9175
diff changeset
8 Purge
1068f9b82e2b util.pubsub tests: Add TODO
Matthew Wild <mwild1@gmail.com>
parents: 9175
diff changeset
9 auto-create/auto-subscribe
1068f9b82e2b util.pubsub tests: Add TODO
Matthew Wild <mwild1@gmail.com>
parents: 9175
diff changeset
10 Item store/node store
1068f9b82e2b util.pubsub tests: Add TODO
Matthew Wild <mwild1@gmail.com>
parents: 9175
diff changeset
11 resize on max_items change
1068f9b82e2b util.pubsub tests: Add TODO
Matthew Wild <mwild1@gmail.com>
parents: 9175
diff changeset
12 service creation config provides alternative node_defaults
1068f9b82e2b util.pubsub tests: Add TODO
Matthew Wild <mwild1@gmail.com>
parents: 9175
diff changeset
13 get subscriptions
1068f9b82e2b util.pubsub tests: Add TODO
Matthew Wild <mwild1@gmail.com>
parents: 9175
diff changeset
14 ]]
1068f9b82e2b util.pubsub tests: Add TODO
Matthew Wild <mwild1@gmail.com>
parents: 9175
diff changeset
15
8558
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 describe("util.pubsub", function ()
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 describe("simple node creation and deletion", function ()
9451
db82b096b842 util.pubsub tests: Ensure necessary tests run in the defined order
Matthew Wild <mwild1@gmail.com>
parents: 9209
diff changeset
18 randomize(false); -- These tests are ordered
db82b096b842 util.pubsub tests: Ensure necessary tests run in the defined order
Matthew Wild <mwild1@gmail.com>
parents: 9209
diff changeset
19
8558
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 -- 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
21 local service = pubsub.new();
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 describe("#create", function ()
9451
db82b096b842 util.pubsub tests: Ensure necessary tests run in the defined order
Matthew Wild <mwild1@gmail.com>
parents: 9209
diff changeset
24 randomize(false); -- These tests are ordered
8558
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 it("creates a new node", function ()
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 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
27 end);
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 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
30 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
31 end);
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 end);
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 describe("#delete", function ()
9451
db82b096b842 util.pubsub tests: Ensure necessary tests run in the defined order
Matthew Wild <mwild1@gmail.com>
parents: 9209
diff changeset
35 randomize(false); -- These tests are ordered
8558
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 it("deletes the node", function ()
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 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
38 end);
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 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
41 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
42 end);
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43 end);
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44 end);
8647
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
45
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
46 describe("simple publishing", function ()
9451
db82b096b842 util.pubsub tests: Ensure necessary tests run in the defined order
Matthew Wild <mwild1@gmail.com>
parents: 9209
diff changeset
47 randomize(false); -- These tests are ordered
db82b096b842 util.pubsub tests: Ensure necessary tests run in the defined order
Matthew Wild <mwild1@gmail.com>
parents: 9209
diff changeset
48
9173
c53663e13b51 util.pubsub tests: Extend publishing tests to check for correct notification behaviour on subscribe/unsubscribe
Matthew Wild <mwild1@gmail.com>
parents: 9171
diff changeset
49 local notified;
9178
f226b7b5486b util.pubsub: Silence warnings in tests [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9176
diff changeset
50 local broadcaster = spy.new(function (notif_type, node_name, subscribers, item) -- luacheck: ignore 212
9173
c53663e13b51 util.pubsub tests: Extend publishing tests to check for correct notification behaviour on subscribe/unsubscribe
Matthew Wild <mwild1@gmail.com>
parents: 9171
diff changeset
51 notified = subscribers;
c53663e13b51 util.pubsub tests: Extend publishing tests to check for correct notification behaviour on subscribe/unsubscribe
Matthew Wild <mwild1@gmail.com>
parents: 9171
diff changeset
52 end);
8817
9a3066a580ad spec/util_pubsub: Test whether someone can subscribe to a node
Kim Alvefur <zash@zash.se>
parents: 8647
diff changeset
53 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
54 broadcaster = broadcaster;
9a3066a580ad spec/util_pubsub: Test whether someone can subscribe to a node
Kim Alvefur <zash@zash.se>
parents: 8647
diff changeset
55 });
8647
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
56
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
57 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
58 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
59 end);
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
60
8817
9a3066a580ad spec/util_pubsub: Test whether someone can subscribe to a node
Kim Alvefur <zash@zash.se>
parents: 8647
diff changeset
61 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
62 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
63 end);
9a3066a580ad spec/util_pubsub: Test whether someone can subscribe to a node
Kim Alvefur <zash@zash.se>
parents: 8647
diff changeset
64
8647
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
65 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
66 assert.truthy(service:publish("node", true, "1", "item 1"));
9173
c53663e13b51 util.pubsub tests: Extend publishing tests to check for correct notification behaviour on subscribe/unsubscribe
Matthew Wild <mwild1@gmail.com>
parents: 9171
diff changeset
67 assert.truthy(notified["someone"]);
8647
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
68 end);
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
69
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
70 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
71 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
72 end);
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
73
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
74 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
75 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
76 assert.truthy(ok);
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
77 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
78 end);
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
79
9173
c53663e13b51 util.pubsub tests: Extend publishing tests to check for correct notification behaviour on subscribe/unsubscribe
Matthew Wild <mwild1@gmail.com>
parents: 9171
diff changeset
80 it("lets someone unsubscribe", function ()
c53663e13b51 util.pubsub tests: Extend publishing tests to check for correct notification behaviour on subscribe/unsubscribe
Matthew Wild <mwild1@gmail.com>
parents: 9171
diff changeset
81 assert.truthy(service:remove_subscription("node", true, "someone"));
c53663e13b51 util.pubsub tests: Extend publishing tests to check for correct notification behaviour on subscribe/unsubscribe
Matthew Wild <mwild1@gmail.com>
parents: 9171
diff changeset
82 end);
c53663e13b51 util.pubsub tests: Extend publishing tests to check for correct notification behaviour on subscribe/unsubscribe
Matthew Wild <mwild1@gmail.com>
parents: 9171
diff changeset
83
c53663e13b51 util.pubsub tests: Extend publishing tests to check for correct notification behaviour on subscribe/unsubscribe
Matthew Wild <mwild1@gmail.com>
parents: 9171
diff changeset
84 it("does not send notifications after subscription is removed", function ()
c53663e13b51 util.pubsub tests: Extend publishing tests to check for correct notification behaviour on subscribe/unsubscribe
Matthew Wild <mwild1@gmail.com>
parents: 9171
diff changeset
85 assert.truthy(service:publish("node", true, "1", "item 1"));
c53663e13b51 util.pubsub tests: Extend publishing tests to check for correct notification behaviour on subscribe/unsubscribe
Matthew Wild <mwild1@gmail.com>
parents: 9171
diff changeset
86 assert.is_nil(notified["someone"]);
c53663e13b51 util.pubsub tests: Extend publishing tests to check for correct notification behaviour on subscribe/unsubscribe
Matthew Wild <mwild1@gmail.com>
parents: 9171
diff changeset
87 end);
8647
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
88 end);
9004
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
89
9516
038446c50630 util.pubsub: Allow publishing with a config that should be used as defaults only
Matthew Wild <mwild1@gmail.com>
parents: 9451
diff changeset
90 describe("publish with config", function ()
038446c50630 util.pubsub: Allow publishing with a config that should be used as defaults only
Matthew Wild <mwild1@gmail.com>
parents: 9451
diff changeset
91 randomize(false); -- These tests are ordered
038446c50630 util.pubsub: Allow publishing with a config that should be used as defaults only
Matthew Wild <mwild1@gmail.com>
parents: 9451
diff changeset
92
038446c50630 util.pubsub: Allow publishing with a config that should be used as defaults only
Matthew Wild <mwild1@gmail.com>
parents: 9451
diff changeset
93 local broadcaster = spy.new(function (notif_type, node_name, subscribers, item) -- luacheck: ignore 212
038446c50630 util.pubsub: Allow publishing with a config that should be used as defaults only
Matthew Wild <mwild1@gmail.com>
parents: 9451
diff changeset
94 end);
038446c50630 util.pubsub: Allow publishing with a config that should be used as defaults only
Matthew Wild <mwild1@gmail.com>
parents: 9451
diff changeset
95 local service = pubsub.new({
038446c50630 util.pubsub: Allow publishing with a config that should be used as defaults only
Matthew Wild <mwild1@gmail.com>
parents: 9451
diff changeset
96 broadcaster = broadcaster;
038446c50630 util.pubsub: Allow publishing with a config that should be used as defaults only
Matthew Wild <mwild1@gmail.com>
parents: 9451
diff changeset
97 autocreate_on_publish = true;
038446c50630 util.pubsub: Allow publishing with a config that should be used as defaults only
Matthew Wild <mwild1@gmail.com>
parents: 9451
diff changeset
98 });
038446c50630 util.pubsub: Allow publishing with a config that should be used as defaults only
Matthew Wild <mwild1@gmail.com>
parents: 9451
diff changeset
99
038446c50630 util.pubsub: Allow publishing with a config that should be used as defaults only
Matthew Wild <mwild1@gmail.com>
parents: 9451
diff changeset
100 it("automatically creates node with requested config", function ()
038446c50630 util.pubsub: Allow publishing with a config that should be used as defaults only
Matthew Wild <mwild1@gmail.com>
parents: 9451
diff changeset
101 assert(service:publish("node", true, "1", "item 1", { myoption = true }));
038446c50630 util.pubsub: Allow publishing with a config that should be used as defaults only
Matthew Wild <mwild1@gmail.com>
parents: 9451
diff changeset
102
038446c50630 util.pubsub: Allow publishing with a config that should be used as defaults only
Matthew Wild <mwild1@gmail.com>
parents: 9451
diff changeset
103 local ok, config = assert(service:get_node_config("node", true));
10541
6c6ff4509082 tests: Silence [luacheck] warnings
Kim Alvefur <zash@zash.se>
parents: 10356
diff changeset
104 assert.truthy(ok);
9516
038446c50630 util.pubsub: Allow publishing with a config that should be used as defaults only
Matthew Wild <mwild1@gmail.com>
parents: 9451
diff changeset
105 assert.equals(true, config.myoption);
038446c50630 util.pubsub: Allow publishing with a config that should be used as defaults only
Matthew Wild <mwild1@gmail.com>
parents: 9451
diff changeset
106 end);
038446c50630 util.pubsub: Allow publishing with a config that should be used as defaults only
Matthew Wild <mwild1@gmail.com>
parents: 9451
diff changeset
107
038446c50630 util.pubsub: Allow publishing with a config that should be used as defaults only
Matthew Wild <mwild1@gmail.com>
parents: 9451
diff changeset
108 it("fails to publish to a node with differing config", function ()
038446c50630 util.pubsub: Allow publishing with a config that should be used as defaults only
Matthew Wild <mwild1@gmail.com>
parents: 9451
diff changeset
109 local ok, err = service:publish("node", true, "1", "item 2", { myoption = false });
038446c50630 util.pubsub: Allow publishing with a config that should be used as defaults only
Matthew Wild <mwild1@gmail.com>
parents: 9451
diff changeset
110 assert.falsy(ok);
10356
0a2d7efca039 util.pubsub, pubsub.lib and tests: Add text to precondition-not-met error (fixes #1455)
Matthew Wild <mwild1@gmail.com>
parents: 9840
diff changeset
111 assert.equals("precondition-not-met", err.pubsub_condition);
9516
038446c50630 util.pubsub: Allow publishing with a config that should be used as defaults only
Matthew Wild <mwild1@gmail.com>
parents: 9451
diff changeset
112 end);
038446c50630 util.pubsub: Allow publishing with a config that should be used as defaults only
Matthew Wild <mwild1@gmail.com>
parents: 9451
diff changeset
113
038446c50630 util.pubsub: Allow publishing with a config that should be used as defaults only
Matthew Wild <mwild1@gmail.com>
parents: 9451
diff changeset
114 it("allows to publish to a node with differing config when only defaults are suggested", function ()
038446c50630 util.pubsub: Allow publishing with a config that should be used as defaults only
Matthew Wild <mwild1@gmail.com>
parents: 9451
diff changeset
115 assert(service:publish("node", true, "1", "item 2", { _defaults_only = true, myoption = false }));
038446c50630 util.pubsub: Allow publishing with a config that should be used as defaults only
Matthew Wild <mwild1@gmail.com>
parents: 9451
diff changeset
116 end);
038446c50630 util.pubsub: Allow publishing with a config that should be used as defaults only
Matthew Wild <mwild1@gmail.com>
parents: 9451
diff changeset
117 end);
038446c50630 util.pubsub: Allow publishing with a config that should be used as defaults only
Matthew Wild <mwild1@gmail.com>
parents: 9451
diff changeset
118
9004
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
119 describe("#issue1082", function ()
9451
db82b096b842 util.pubsub tests: Ensure necessary tests run in the defined order
Matthew Wild <mwild1@gmail.com>
parents: 9209
diff changeset
120 randomize(false); -- These tests are ordered
db82b096b842 util.pubsub tests: Ensure necessary tests run in the defined order
Matthew Wild <mwild1@gmail.com>
parents: 9209
diff changeset
121
9004
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
122 local service = pubsub.new();
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
123
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
124 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
125 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
126 end);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
127
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
128 it("changes max_items to 2", function ()
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
129 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
130 end);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
131
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
132 it("publishes one item", function ()
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
133 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
134 end);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
135
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
136 it("should return one item", function ()
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
137 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
138 assert.truthy(ok);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
139 assert.same({ "1", ["1"] = "item 1" }, ret);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
140 end);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
141
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
142 it("publishes another item", function ()
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
143 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
144 end);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
145
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
146 it("should return two items", function ()
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
147 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
148 assert.truthy(ok);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
149 assert.same({
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
150 "2",
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
151 "1",
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
152 ["1"] = "item 1",
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
153 ["2"] = "item 2",
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
154 }, ret);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
155 end);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
156
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
157 it("publishes yet another item", function ()
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
158 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
159 end);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
160
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
161 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
162 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
163 assert.truthy(ok);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
164 assert.same({
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
165 "3",
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
166 "2",
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
167 ["2"] = "item 2",
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
168 ["3"] = "item 3",
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
169 }, ret);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
170 end);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
171
12153
26af75c20163 util.pubsub: Fix item store resize to "max"
Kim Alvefur <zash@zash.se>
parents: 11767
diff changeset
172 it("has a default max_items", function ()
26af75c20163 util.pubsub: Fix item store resize to "max"
Kim Alvefur <zash@zash.se>
parents: 11767
diff changeset
173 assert.truthy(service.config.max_items);
26af75c20163 util.pubsub: Fix item store resize to "max"
Kim Alvefur <zash@zash.se>
parents: 11767
diff changeset
174 end)
26af75c20163 util.pubsub: Fix item store resize to "max"
Kim Alvefur <zash@zash.se>
parents: 11767
diff changeset
175
26af75c20163 util.pubsub: Fix item store resize to "max"
Kim Alvefur <zash@zash.se>
parents: 11767
diff changeset
176 it("changes max_items to max", function ()
26af75c20163 util.pubsub: Fix item store resize to "max"
Kim Alvefur <zash@zash.se>
parents: 11767
diff changeset
177 assert.truthy(service:set_node_config("node", true, { max_items = "max" }));
26af75c20163 util.pubsub: Fix item store resize to "max"
Kim Alvefur <zash@zash.se>
parents: 11767
diff changeset
178 end);
26af75c20163 util.pubsub: Fix item store resize to "max"
Kim Alvefur <zash@zash.se>
parents: 11767
diff changeset
179
26af75c20163 util.pubsub: Fix item store resize to "max"
Kim Alvefur <zash@zash.se>
parents: 11767
diff changeset
180 it("publishes some more items", function()
26af75c20163 util.pubsub: Fix item store resize to "max"
Kim Alvefur <zash@zash.se>
parents: 11767
diff changeset
181 for i = 4, service.config.max_items + 5 do
26af75c20163 util.pubsub: Fix item store resize to "max"
Kim Alvefur <zash@zash.se>
parents: 11767
diff changeset
182 assert.truthy(service:publish("node", true, tostring(i), "item " .. tostring(i)));
26af75c20163 util.pubsub: Fix item store resize to "max"
Kim Alvefur <zash@zash.se>
parents: 11767
diff changeset
183 end
26af75c20163 util.pubsub: Fix item store resize to "max"
Kim Alvefur <zash@zash.se>
parents: 11767
diff changeset
184 end);
26af75c20163 util.pubsub: Fix item store resize to "max"
Kim Alvefur <zash@zash.se>
parents: 11767
diff changeset
185
26af75c20163 util.pubsub: Fix item store resize to "max"
Kim Alvefur <zash@zash.se>
parents: 11767
diff changeset
186 it("should still return only two items", function ()
26af75c20163 util.pubsub: Fix item store resize to "max"
Kim Alvefur <zash@zash.se>
parents: 11767
diff changeset
187 local ok, ret = service:get_items("node", true);
26af75c20163 util.pubsub: Fix item store resize to "max"
Kim Alvefur <zash@zash.se>
parents: 11767
diff changeset
188 assert.truthy(ok);
26af75c20163 util.pubsub: Fix item store resize to "max"
Kim Alvefur <zash@zash.se>
parents: 11767
diff changeset
189 assert.same(service.config.max_items, #ret);
26af75c20163 util.pubsub: Fix item store resize to "max"
Kim Alvefur <zash@zash.se>
parents: 11767
diff changeset
190 end);
26af75c20163 util.pubsub: Fix item store resize to "max"
Kim Alvefur <zash@zash.se>
parents: 11767
diff changeset
191
9004
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
192 end);
9169
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
193
9816
7f84d7f77a00 util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents: 9742
diff changeset
194 describe("the thing", function ()
7f84d7f77a00 util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents: 9742
diff changeset
195 randomize(false); -- These tests are ordered
7f84d7f77a00 util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents: 9742
diff changeset
196
7f84d7f77a00 util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents: 9742
diff changeset
197 local service = pubsub.new();
7f84d7f77a00 util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents: 9742
diff changeset
198
7f84d7f77a00 util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents: 9742
diff changeset
199 it("creates a node with some items", function ()
7f84d7f77a00 util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents: 9742
diff changeset
200 assert.truthy(service:create("node", true, { max_items = 3 }));
7f84d7f77a00 util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents: 9742
diff changeset
201 assert.truthy(service:publish("node", true, "1", "item 1"));
7f84d7f77a00 util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents: 9742
diff changeset
202 assert.truthy(service:publish("node", true, "2", "item 2"));
7f84d7f77a00 util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents: 9742
diff changeset
203 assert.truthy(service:publish("node", true, "3", "item 3"));
7f84d7f77a00 util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents: 9742
diff changeset
204 end);
7f84d7f77a00 util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents: 9742
diff changeset
205
7f84d7f77a00 util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents: 9742
diff changeset
206 it("should return the requested item", function ()
7f84d7f77a00 util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents: 9742
diff changeset
207 local ok, ret = service:get_items("node", true, "1");
7f84d7f77a00 util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents: 9742
diff changeset
208 assert.truthy(ok);
7f84d7f77a00 util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents: 9742
diff changeset
209 assert.same({ "1", ["1"] = "item 1" }, ret);
7f84d7f77a00 util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents: 9742
diff changeset
210 end);
7f84d7f77a00 util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents: 9742
diff changeset
211
7f84d7f77a00 util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents: 9742
diff changeset
212 it("should return multiple requested items", function ()
7f84d7f77a00 util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents: 9742
diff changeset
213 local ok, ret = service:get_items("node", true, { "1", "2" });
7f84d7f77a00 util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents: 9742
diff changeset
214 assert.truthy(ok);
7f84d7f77a00 util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents: 9742
diff changeset
215 assert.same({
7f84d7f77a00 util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents: 9742
diff changeset
216 "1",
7f84d7f77a00 util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents: 9742
diff changeset
217 "2",
7f84d7f77a00 util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents: 9742
diff changeset
218 ["1"] = "item 1",
7f84d7f77a00 util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents: 9742
diff changeset
219 ["2"] = "item 2",
7f84d7f77a00 util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents: 9742
diff changeset
220 }, ret);
7f84d7f77a00 util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents: 9742
diff changeset
221 end);
7f84d7f77a00 util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents: 9742
diff changeset
222 end);
7f84d7f77a00 util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents: 9742
diff changeset
223
7f84d7f77a00 util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents: 9742
diff changeset
224
9174
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
225 describe("node config", function ()
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
226 local service;
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
227 before_each(function ()
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
228 service = pubsub.new();
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
229 service:create("test", true);
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
230 end);
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
231 it("access is forbidden for unaffiliated entities", function ()
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
232 local ok, err = service:get_node_config("test", "stranger");
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
233 assert.is_falsy(ok);
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
234 assert.equals("forbidden", err);
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
235 end);
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
236 it("returns an error for nodes that do not exist", function ()
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
237 local ok, err = service:get_node_config("nonexistent", true);
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
238 assert.is_falsy(ok);
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
239 assert.equals("item-not-found", err);
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
240 end);
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
241 end);
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
242
9169
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
243 describe("access model", function ()
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
244 describe("open", function ()
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
245 local service;
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
246 before_each(function ()
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
247 service = pubsub.new();
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
248 -- Do not supply any config, 'open' should be default
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
249 service:create("test", true);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
250 end);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
251 it("should be the default", function ()
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
252 local ok, config = service:get_node_config("test", true);
10541
6c6ff4509082 tests: Silence [luacheck] warnings
Kim Alvefur <zash@zash.se>
parents: 10356
diff changeset
253 assert.truthy(ok);
9169
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
254 assert.equal("open", config.access_model);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
255 end);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
256 it("should allow anyone to subscribe", function ()
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
257 local ok = service:add_subscription("test", "stranger", "stranger");
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
258 assert.is_true(ok);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
259 end);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
260 it("should still reject outcast-affiliated entities", function ()
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
261 assert(service:set_affiliation("test", true, "enemy", "outcast"));
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
262 local ok, err = service:add_subscription("test", "enemy", "enemy");
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
263 assert.is_falsy(ok);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
264 assert.equal("forbidden", err);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
265 end);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
266 end);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
267 describe("whitelist", function ()
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
268 local service;
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
269 before_each(function ()
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
270 service = assert(pubsub.new());
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
271 assert.is_true(service:create("test", true, { access_model = "whitelist" }));
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
272 end);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
273 it("should be present in the configuration", function ()
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
274 local ok, config = service:get_node_config("test", true);
10541
6c6ff4509082 tests: Silence [luacheck] warnings
Kim Alvefur <zash@zash.se>
parents: 10356
diff changeset
275 assert.truthy(ok);
9169
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
276 assert.equal("whitelist", config.access_model);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
277 end);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
278 it("should not allow anyone to subscribe", function ()
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
279 local ok, err = service:add_subscription("test", "stranger", "stranger");
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
280 assert.is_false(ok);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
281 assert.equals("forbidden", err);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
282 end);
9171
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
283 end);
9175
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
284 describe("change", function ()
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
285 local service;
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
286 before_each(function ()
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
287 service = pubsub.new();
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
288 service:create("test", true, { access_model = "open" });
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
289 end);
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
290 it("affects existing subscriptions", function ()
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
291 do
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
292 local ok = service:add_subscription("test", "stranger", "stranger");
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
293 assert.is_true(ok);
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
294 end
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
295 do
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
296 local ok, sub = service:get_subscription("test", "stranger", "stranger");
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
297 assert.is_true(ok);
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
298 assert.is_true(sub);
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
299 end
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
300 assert(service:set_node_config("test", true, { access_model = "whitelist" }));
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
301 do
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
302 local ok, sub = service:get_subscription("test", "stranger", "stranger");
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
303 assert.is_true(ok);
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
304 assert.is_nil(sub);
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
305 end
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
306 end);
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
307 end);
9171
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
308 end);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
309
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
310 describe("publish model", function ()
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
311 describe("publishers", function ()
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
312 local service;
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
313 before_each(function ()
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
314 service = pubsub.new();
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
315 -- Do not supply any config, 'publishers' should be default
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
316 service:create("test", true);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
317 end);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
318 it("should be the default", function ()
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
319 local ok, config = service:get_node_config("test", true);
10541
6c6ff4509082 tests: Silence [luacheck] warnings
Kim Alvefur <zash@zash.se>
parents: 10356
diff changeset
320 assert.truthy(ok);
9171
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
321 assert.equal("publishers", config.publish_model);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
322 end);
9169
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
323 it("should not allow anyone to publish", function ()
9171
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
324 assert.is_true(service:add_subscription("test", "stranger", "stranger"));
9169
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
325 local ok, err = service:publish("test", "stranger", "item1", "foo");
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
326 assert.is_falsy(ok);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
327 assert.equals("forbidden", err);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
328 end);
9171
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
329 it("should allow publishers to publish", function ()
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
330 assert(service:set_affiliation("test", true, "mypublisher", "publisher"));
10541
6c6ff4509082 tests: Silence [luacheck] warnings
Kim Alvefur <zash@zash.se>
parents: 10356
diff changeset
331 -- luacheck: ignore 211/err
9171
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
332 local ok, err = service:publish("test", "mypublisher", "item1", "foo");
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
333 assert.is_true(ok);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
334 end);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
335 it("should allow owners to publish", function ()
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
336 assert(service:set_affiliation("test", true, "myowner", "owner"));
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
337 local ok = service:publish("test", "myowner", "item1", "foo");
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
338 assert.is_true(ok);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
339 end);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
340 end);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
341 describe("open", function ()
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
342 local service;
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
343 before_each(function ()
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
344 service = pubsub.new();
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
345 service:create("test", true, { publish_model = "open" });
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
346 end);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
347 it("should allow anyone to publish", function ()
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
348 local ok = service:publish("test", "stranger", "item1", "foo");
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
349 assert.is_true(ok);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
350 end);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
351 end);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
352 describe("subscribers", function ()
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
353 local service;
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
354 before_each(function ()
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
355 service = pubsub.new();
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
356 service:create("test", true, { publish_model = "subscribers" });
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
357 end);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
358 it("should not allow non-subscribers to publish", function ()
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
359 local ok, err = service:publish("test", "stranger", "item1", "foo");
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
360 assert.is_falsy(ok);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
361 assert.equals("forbidden", err);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
362 end);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
363 it("should allow subscribers to publish without an affiliation", function ()
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
364 assert.is_true(service:add_subscription("test", "stranger", "stranger"));
9209
69e17edf8796 util.pubsub tests: Fix whitespace
Kim Alvefur <zash@zash.se>
parents: 9208
diff changeset
365 local ok = service:publish("test", "stranger", "item1", "foo");
9171
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
366 assert.is_true(ok);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
367 end);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
368 it("should allow publishers to publish without a subscription", function ()
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
369 assert(service:set_affiliation("test", true, "mypublisher", "publisher"));
10541
6c6ff4509082 tests: Silence [luacheck] warnings
Kim Alvefur <zash@zash.se>
parents: 10356
diff changeset
370 -- luacheck: ignore 211/err
9171
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
371 local ok, err = service:publish("test", "mypublisher", "item1", "foo");
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
372 assert.is_true(ok);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
373 end);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
374 it("should allow owners to publish without a subscription", function ()
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
375 assert(service:set_affiliation("test", true, "myowner", "owner"));
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
376 local ok = service:publish("test", "myowner", "item1", "foo");
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
377 assert.is_true(ok);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
378 end);
9169
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
379 end);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
380 end);
9206
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
381
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
382 describe("item API", function ()
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
383 local service;
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
384 before_each(function ()
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
385 service = pubsub.new();
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
386 service:create("test", true, { publish_model = "subscribers" });
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
387 end);
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
388 describe("get_last_item()", function ()
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
389 it("succeeds with nil on empty nodes", function ()
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
390 local ok, id, item = service:get_last_item("test", true);
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
391 assert.is_true(ok);
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
392 assert.is_nil(id);
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
393 assert.is_nil(item);
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
394 end);
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
395 it("succeeds and returns the last item", function ()
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
396 service:publish("test", true, "one", "hello world");
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
397 service:publish("test", true, "two", "hello again");
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
398 service:publish("test", true, "three", "hey");
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
399 service:publish("test", true, "one", "bye");
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
400 local ok, id, item = service:get_last_item("test", true);
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
401 assert.is_true(ok);
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
402 assert.equal("one", id);
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
403 assert.equal("bye", item);
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
404 end);
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
405 end);
9208
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
406 describe("get_items()", function ()
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
407 it("fails on non-existent nodes", function ()
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
408 local ok, err = service:get_items("no-node", true);
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
409 assert.is_falsy(ok);
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
410 assert.equal("item-not-found", err);
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
411 end);
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
412 it("returns no items on an empty node", function ()
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
413 local ok, items = service:get_items("test", true);
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
414 assert.is_true(ok);
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
415 assert.equal(0, #items);
9209
69e17edf8796 util.pubsub tests: Fix whitespace
Kim Alvefur <zash@zash.se>
parents: 9208
diff changeset
416 assert.is_nil(next(items));
9208
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
417 end);
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
418 it("returns no items on an empty node", function ()
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
419 local ok, items = service:get_items("test", true);
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
420 assert.is_true(ok);
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
421 assert.equal(0, #items);
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
422 assert.is_nil((next(items)));
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
423 end);
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
424 it("returns all published items", function ()
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
425 service:publish("test", true, "one", "hello world");
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
426 service:publish("test", true, "two", "hello again");
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
427 service:publish("test", true, "three", "hey");
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
428 service:publish("test", true, "one", "bye");
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
429 local ok, items = service:get_items("test", true);
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
430 assert.is_true(ok);
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
431 assert.same({ "one", "three", "two", two = "hello again", three = "hey", one = "bye" }, items);
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
432 end);
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
433 end);
9206
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
434 end);
9742
18eca6afb367 util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents: 9516
diff changeset
435
18eca6afb367 util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents: 9516
diff changeset
436 describe("restoring data from nodestore", function ()
18eca6afb367 util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents: 9516
diff changeset
437 local nodestore = {
18eca6afb367 util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents: 9516
diff changeset
438 data = {
18eca6afb367 util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents: 9516
diff changeset
439 test = {
18eca6afb367 util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents: 9516
diff changeset
440 name = "test";
18eca6afb367 util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents: 9516
diff changeset
441 config = {};
18eca6afb367 util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents: 9516
diff changeset
442 affiliations = {};
18eca6afb367 util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents: 9516
diff changeset
443 subscribers = {
18eca6afb367 util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents: 9516
diff changeset
444 ["someone"] = true;
18eca6afb367 util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents: 9516
diff changeset
445 };
18eca6afb367 util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents: 9516
diff changeset
446 }
18eca6afb367 util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents: 9516
diff changeset
447 }
18eca6afb367 util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents: 9516
diff changeset
448 };
18eca6afb367 util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents: 9516
diff changeset
449 function nodestore:users()
18eca6afb367 util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents: 9516
diff changeset
450 return pairs(self.data)
18eca6afb367 util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents: 9516
diff changeset
451 end
18eca6afb367 util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents: 9516
diff changeset
452 function nodestore:get(key)
18eca6afb367 util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents: 9516
diff changeset
453 return self.data[key];
18eca6afb367 util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents: 9516
diff changeset
454 end
18eca6afb367 util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents: 9516
diff changeset
455 local service = pubsub.new({
18eca6afb367 util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents: 9516
diff changeset
456 nodestore = nodestore;
18eca6afb367 util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents: 9516
diff changeset
457 });
18eca6afb367 util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents: 9516
diff changeset
458 it("subscriptions", function ()
18eca6afb367 util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents: 9516
diff changeset
459 local ok, ret = service:get_subscriptions(nil, true, nil)
18eca6afb367 util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents: 9516
diff changeset
460 assert.is_true(ok);
18eca6afb367 util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents: 9516
diff changeset
461 assert.same({ { node = "test", jid = "someone", subscription = true, } }, ret);
18eca6afb367 util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents: 9516
diff changeset
462 end);
18eca6afb367 util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents: 9516
diff changeset
463 end);
18eca6afb367 util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents: 9516
diff changeset
464
9840
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
465 describe("node config checking", function ()
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
466 local service;
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
467 before_each(function ()
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
468 service = pubsub.new({
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
469 check_node_config = function (node, actor, config) -- luacheck: ignore 212
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
470 return config["max_items"] <= 20;
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
471 end;
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
472 });
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
473 end);
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
474
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
475 it("defaults, then configure", function ()
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
476 local ok, err = service:create("node", true);
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
477 assert.is_true(ok, err);
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
478
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
479 local ok, err = service:set_node_config("node", true, { max_items = 10 });
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
480 assert.is_true(ok, err);
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
481
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
482 local ok, err = service:set_node_config("node", true, { max_items = 100 });
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
483 assert.falsy(ok, err);
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
484 assert.equals(err, "not-acceptable");
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
485 end);
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
486
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
487 it("create with ok config, then configure", function ()
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
488 local ok, err = service:create("node", true, { max_items = 10 });
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
489 assert.is_true(ok, err);
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
490
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
491 local ok, err = service:set_node_config("node", true, { max_items = 100 });
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
492 assert.falsy(ok, err);
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
493
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
494 local ok, err = service:set_node_config("node", true, { max_items = 10 });
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
495 assert.is_true(ok, err);
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
496 end);
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
497
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
498 it("create with unacceptable config", function ()
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
499 local ok, err = service:create("node", true, { max_items = 100 });
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
500 assert.falsy(ok, err);
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
501 end);
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
502
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
503
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
504 end);
ec353524b739 util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents: 9816
diff changeset
505
10572
d960c703e6b3 util.pubsub: Cover subscription filter in a partial test
Kim Alvefur <zash@zash.se>
parents: 10541
diff changeset
506 describe("subscriber filter", function ()
d960c703e6b3 util.pubsub: Cover subscription filter in a partial test
Kim Alvefur <zash@zash.se>
parents: 10541
diff changeset
507 it("works", function ()
10573
3b8431eed785 util.pubsub: Ignore unused argument in tests [luacheck]
Kim Alvefur <zash@zash.se>
parents: 10572
diff changeset
508 local filter = spy.new(function (subs) -- luacheck: ignore 212/subs
10572
d960c703e6b3 util.pubsub: Cover subscription filter in a partial test
Kim Alvefur <zash@zash.se>
parents: 10541
diff changeset
509 return {["modified"] = true};
d960c703e6b3 util.pubsub: Cover subscription filter in a partial test
Kim Alvefur <zash@zash.se>
parents: 10541
diff changeset
510 end);
d960c703e6b3 util.pubsub: Cover subscription filter in a partial test
Kim Alvefur <zash@zash.se>
parents: 10541
diff changeset
511 local broadcaster = spy.new(function (notif_type, node_name, subscribers, item) -- luacheck: ignore 212
d960c703e6b3 util.pubsub: Cover subscription filter in a partial test
Kim Alvefur <zash@zash.se>
parents: 10541
diff changeset
512 end);
d960c703e6b3 util.pubsub: Cover subscription filter in a partial test
Kim Alvefur <zash@zash.se>
parents: 10541
diff changeset
513 local service = pubsub.new({
d960c703e6b3 util.pubsub: Cover subscription filter in a partial test
Kim Alvefur <zash@zash.se>
parents: 10541
diff changeset
514 subscriber_filter = filter;
d960c703e6b3 util.pubsub: Cover subscription filter in a partial test
Kim Alvefur <zash@zash.se>
parents: 10541
diff changeset
515 broadcaster = broadcaster;
d960c703e6b3 util.pubsub: Cover subscription filter in a partial test
Kim Alvefur <zash@zash.se>
parents: 10541
diff changeset
516 });
d960c703e6b3 util.pubsub: Cover subscription filter in a partial test
Kim Alvefur <zash@zash.se>
parents: 10541
diff changeset
517
d960c703e6b3 util.pubsub: Cover subscription filter in a partial test
Kim Alvefur <zash@zash.se>
parents: 10541
diff changeset
518 local ok = service:create("node", true);
d960c703e6b3 util.pubsub: Cover subscription filter in a partial test
Kim Alvefur <zash@zash.se>
parents: 10541
diff changeset
519 assert.truthy(ok);
d960c703e6b3 util.pubsub: Cover subscription filter in a partial test
Kim Alvefur <zash@zash.se>
parents: 10541
diff changeset
520
d960c703e6b3 util.pubsub: Cover subscription filter in a partial test
Kim Alvefur <zash@zash.se>
parents: 10541
diff changeset
521 local ok = service:add_subscription("node", true, "someone");
d960c703e6b3 util.pubsub: Cover subscription filter in a partial test
Kim Alvefur <zash@zash.se>
parents: 10541
diff changeset
522 assert.truthy(ok);
d960c703e6b3 util.pubsub: Cover subscription filter in a partial test
Kim Alvefur <zash@zash.se>
parents: 10541
diff changeset
523
d960c703e6b3 util.pubsub: Cover subscription filter in a partial test
Kim Alvefur <zash@zash.se>
parents: 10541
diff changeset
524 local ok = service:publish("node", true, "1", "item");
d960c703e6b3 util.pubsub: Cover subscription filter in a partial test
Kim Alvefur <zash@zash.se>
parents: 10541
diff changeset
525 assert.truthy(ok);
d960c703e6b3 util.pubsub: Cover subscription filter in a partial test
Kim Alvefur <zash@zash.se>
parents: 10541
diff changeset
526 -- TODO how to match table arguments?
d960c703e6b3 util.pubsub: Cover subscription filter in a partial test
Kim Alvefur <zash@zash.se>
parents: 10541
diff changeset
527 assert.spy(filter).was_called();
d960c703e6b3 util.pubsub: Cover subscription filter in a partial test
Kim Alvefur <zash@zash.se>
parents: 10541
diff changeset
528 assert.spy(broadcaster).was_called();
d960c703e6b3 util.pubsub: Cover subscription filter in a partial test
Kim Alvefur <zash@zash.se>
parents: 10541
diff changeset
529 end);
d960c703e6b3 util.pubsub: Cover subscription filter in a partial test
Kim Alvefur <zash@zash.se>
parents: 10541
diff changeset
530 end);
d960c703e6b3 util.pubsub: Cover subscription filter in a partial test
Kim Alvefur <zash@zash.se>
parents: 10541
diff changeset
531
11721
7a77f0c05382 util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents: 10573
diff changeset
532 describe("persist_items", function()
7a77f0c05382 util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents: 10573
diff changeset
533 it("can be disabled", function()
7a77f0c05382 util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents: 10573
diff changeset
534 local broadcaster = spy.new(function(notif_type, node_name, subscribers, item) -- luacheck: ignore 212
7a77f0c05382 util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents: 10573
diff changeset
535 end);
7a77f0c05382 util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents: 10573
diff changeset
536 local service = pubsub.new { node_defaults = { persist_items = false }, broadcaster = broadcaster }
7a77f0c05382 util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents: 10573
diff changeset
537
7a77f0c05382 util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents: 10573
diff changeset
538 local ok = service:create("node", true)
7a77f0c05382 util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents: 10573
diff changeset
539 assert.truthy(ok);
7a77f0c05382 util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents: 10573
diff changeset
540
7a77f0c05382 util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents: 10573
diff changeset
541 local ok = service:publish("node", true, "1", "item");
7a77f0c05382 util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents: 10573
diff changeset
542 assert.truthy(ok);
7a77f0c05382 util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents: 10573
diff changeset
543 assert.spy(broadcaster).was_called();
7a77f0c05382 util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents: 10573
diff changeset
544
7a77f0c05382 util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents: 10573
diff changeset
545 local ok, items = service:get_items("node", true);
11723
3ead0967e04d util.pubsub: Signal that 'persistent-items' is unsupported when disabled
Kim Alvefur <zash@zash.se>
parents: 11721
diff changeset
546 assert.not_truthy(ok);
3ead0967e04d util.pubsub: Signal that 'persistent-items' is unsupported when disabled
Kim Alvefur <zash@zash.se>
parents: 11721
diff changeset
547 assert.equal(items, "persistent-items-unsupported");
11721
7a77f0c05382 util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents: 10573
diff changeset
548 end);
7a77f0c05382 util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents: 10573
diff changeset
549
7a77f0c05382 util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents: 10573
diff changeset
550 end)
11767
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
551
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
552 describe("max_items", function ()
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
553 it("works", function ()
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
554 local service = pubsub.new { };
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
555
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
556 local ok = service:create("node", true)
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
557 assert.truthy(ok);
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
558
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
559 for i = 1, 20 do
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
560 assert.truthy(service:publish("node", true, "item"..tostring(i), "data"..tostring(i)));
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
561 end
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
562
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
563 do
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
564 local ok, items = service:get_items("node", true, nil, { max = 3 });
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
565 assert.truthy(ok, items);
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
566 assert.equal(3, #items);
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
567 assert.same({
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
568 "item20",
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
569 "item19",
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
570 "item18",
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
571 item20 = "data20",
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
572 item19 = "data19",
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
573 item18 = "data18",
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
574 }, items, "items should be ordered by oldest first");
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
575 end
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
576
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
577 do
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
578 local ok, items = service:get_items("node", true, nil, { max = 10 });
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
579 assert.truthy(ok, items);
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
580 assert.equal(10, #items);
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
581 assert.same({
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
582 "item20",
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
583 "item19",
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
584 "item18",
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
585 "item17",
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
586 "item16",
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
587 "item15",
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
588 "item14",
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
589 "item13",
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
590 "item12",
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
591 "item11",
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
592 item20 = "data20",
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
593 item19 = "data19",
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
594 item18 = "data18",
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
595 item17 = "data17",
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
596 item16 = "data16",
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
597 item15 = "data15",
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
598 item14 = "data14",
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
599 item13 = "data13",
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
600 item12 = "data12",
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
601 item11 = "data11",
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
602 }, items, "items should be ordered by oldest first");
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
603 end
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
604
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
605 end);
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
606
5610f7c5b261 util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
607 end)
8558
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
608 end);