Mercurial > prosody-hg
comparison spec/util_error_spec.lua @ 11100:3aa06cdd2dc8
util.error: Add a "compact mode" for registries
Inspired by the older registry in pubsub.lib.lua
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Mon, 28 Sep 2020 18:39:51 +0200 |
| parents | f23cf8e2e2ff |
| children | 2288d206b14b |
comparison
equal
deleted
inserted
replaced
| 11099:6fbfe2af4b4f | 11100:3aa06cdd2dc8 |
|---|---|
| 92 local nope = reg.new("nope"); | 92 local nope = reg.new("nope"); |
| 93 assert.equal("auth", nope.type); | 93 assert.equal("auth", nope.type); |
| 94 assert.equal("not-authorized", nope.condition); | 94 assert.equal("not-authorized", nope.condition); |
| 95 assert.equal("Can't let you do that Dave", nope.text); | 95 assert.equal("Can't let you do that Dave", nope.text); |
| 96 end); | 96 end); |
| 97 | |
| 98 it("compact mode works", function() | |
| 99 local reg = errors.init("test", { | |
| 100 namespace = "spec"; | |
| 101 broke = {"cancel"; "internal-server-error"; "It broke :("}; | |
| 102 nope = {"auth"; "not-authorized"; "Can't let you do that Dave"; "sorry-dave"}; | |
| 103 }); | |
| 104 | |
| 105 local broke = reg.new("broke"); | |
| 106 assert.equal("cancel", broke.type); | |
| 107 assert.equal("internal-server-error", broke.condition); | |
| 108 assert.equal("It broke :(", broke.text); | |
| 109 assert.is_nil(broke.extra); | |
| 110 | |
| 111 local nope = reg.new("nope"); | |
| 112 assert.equal("auth", nope.type); | |
| 113 assert.equal("not-authorized", nope.condition); | |
| 114 assert.equal("Can't let you do that Dave", nope.text); | |
| 115 assert.equal("spec", nope.extra.namespace); | |
| 116 assert.equal("sorry-dave", nope.extra.condition); | |
| 117 end); | |
| 97 end); | 118 end); |
| 98 | 119 |
| 99 end); | 120 end); |
| 100 | 121 |
