util.x509: Nameprep commonName once
[prosody.git] / spec / util_error_spec.lua
blobd8534c2bd2b305750621356004c05e3ea9922d4a
1 local errors = require "util.error"
3 describe("util.error", function ()
4 describe("new()", function ()
5 it("works", function ()
6 local err = errors.new("bork", "bork bork");
7 assert.not_nil(err);
8 assert.equal("cancel", err.type);
9 assert.equal("undefined-condition", err.condition);
10 assert.same("bork bork", err.context);
11 end);
13 describe("templates", function ()
14 it("works", function ()
15 local templates = {
16 ["fail"] = {
17 type = "wait",
18 condition = "internal-server-error",
21 local err = errors.new("fail", { traceback = "in some file, somewhere" }, templates);
22 assert.equal("wait", err.type);
23 assert.equal("internal-server-error", err.condition);
24 assert.same({ traceback = "in some file, somewhere" }, err.context);
25 end);
26 end);
28 end);
30 describe("is_err()", function ()
31 it("works", function ()
32 assert.truthy(errors.is_err(errors.new()));
33 assert.falsy(errors.is_err("not an error"));
34 end);
35 end);
37 describe("coerce", function ()
38 it("works", function ()
39 local ok, err = errors.coerce(nil, "it dun goofed");
40 assert.is_nil(ok);
41 assert.truthy(errors.is_err(err))
42 end);
43 end);
45 describe("from_stanza", function ()
46 it("works", function ()
47 local st = require "util.stanza";
48 local m = st.message({ type = "chat" });
49 local e = st.error_reply(m, "modify", "bad-request");
50 local err = errors.from_stanza(e);
51 assert.truthy(errors.is_err(err));
52 assert.equal("modify", err.type);
53 assert.equal("bad-request", err.condition);
54 assert.equal(e, err.context.stanza);
55 end);
56 end);
58 describe("__tostring", function ()
59 it("doesn't throw", function ()
60 assert.has_no.errors(function ()
61 -- See 6f317e51544d
62 tostring(errors.new());
63 end);
64 end);
65 end);
67 end);