Comparison

spec/util_stanza_spec.lua @ 11086:2846b6226a8e

util.stanza: Support Application-Specific Conditions in util.error
author Kim Alvefur <zash@zash.se>
date Sat, 26 Sep 2020 18:09:10 +0200
parent 11085:5705d151ea11
child 11087:cdd4684992f1
comparison
equal deleted inserted replaced
11085:5705d151ea11 11086:2846b6226a8e
250 250
251 local gone = errors.new({ condition = "gone", extra = { uri = "file:///dev/null" } }) 251 local gone = errors.new({ condition = "gone", extra = { uri = "file:///dev/null" } })
252 local gonner = st.error_reply(s, gone); 252 local gonner = st.error_reply(s, gone);
253 assert.are.equal("gone", gonner.tags[1].tags[1].name); 253 assert.are.equal("gone", gonner.tags[1].tags[1].name);
254 assert.are.equal("file:///dev/null", gonner.tags[1].tags[1][1]); 254 assert.are.equal("file:///dev/null", gonner.tags[1].tags[1][1]);
255 end); 255
256 256 local e = errors.new({ condition = "internal-server-error", text = "Namespaced thing happened",
257 extra = {namespace="xmpp:example.test", condition="this-happened"} })
258 local r = st.error_reply(s, e);
259 assert.are.equal("xmpp:example.test", r.tags[1].tags[3].attr.xmlns);
260 assert.are.equal("this-happened", r.tags[1].tags[3].name);
261
262 local e2 = errors.new({ condition = "internal-server-error", text = "Namespaced thing happened",
263 extra = {tag=st.stanza("that-happened", { xmlns = "xmpp:example.test", ["another-attribute"] = "here" })} })
264 local r2 = st.error_reply(s, e2);
265 assert.are.equal("xmpp:example.test", r2.tags[1].tags[3].attr.xmlns);
266 assert.are.equal("that-happened", r2.tags[1].tags[3].name);
267 assert.are.equal("here", r2.tags[1].tags[3].attr["another-attribute"]);
268 end);
257 end); 269 end);
258 270
259 describe("should reject #invalid", function () 271 describe("should reject #invalid", function ()
260 local invalid_names = { 272 local invalid_names = {
261 ["empty string"] = "", ["characters"] = "<>"; 273 ["empty string"] = "", ["characters"] = "<>";