util.hashring: Support associating arbitrary data with nodes
In this API, a 'node' is always a simple text string. Sometimes the caller may
have a more complex structure representing a node, but the hash ring is really
only concerned with the node's name.
This API change allows :add_nodes() to take a table of `node_name = value`
pairs, as well as the simple array of node names previously accepted.
The 'value' of the selected node is returned as a new second result from
:get_node().
If no value is passed when a node is added, it defaults to `true` (as before,
but this was never previously exposed).
local muc_util;
local st = require "util.stanza";
do
-- XXX Hack for lack of a mock moduleapi
local env = setmetatable({
module = {
_shared = {};
-- Close enough to the real module:shared() for our purposes here
shared = function (self, name)
local t = self._shared[name];
if t == nil then
t = {};
self._shared[name] = t;
end
return t;
end;
}
}, { __index = _ENV or _G });
muc_util = require "util.envload".envloadfile("plugins/muc/util.lib.lua", env)();
end
describe("muc/util", function ()
describe("filter_muc_x()", function ()
it("correctly filters muc#user", function ()
local stanza = st.message({ to = "to", from = "from", id = "foo" })
:tag("x", { xmlns = "http://jabber.org/protocol/muc#user" })
:tag("invite", { to = "user@example.com" });
assert.equal(1, #stanza.tags);
assert.equal(stanza, muc_util.filter_muc_x(stanza));
assert.equal(0, #stanza.tags);
end);
it("correctly filters muc#user on a cloned stanza", function ()
local stanza = st.message({ to = "to", from = "from", id = "foo" })
:tag("x", { xmlns = "http://jabber.org/protocol/muc#user" })
:tag("invite", { to = "user@example.com" });
assert.equal(1, #stanza.tags);
local filtered = muc_util.filter_muc_x(st.clone(stanza));
assert.equal(1, #stanza.tags);
assert.equal(0, #filtered.tags);
end);
end);
end);