aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2018-03-17 18:12:31 +0000
committerMatthew Wild <mwild1@gmail.com>2018-03-17 18:12:31 +0000
commitc2ef1d7b32863d662b4decc8176604a49f289869 (patch)
tree31e0916480ee1f00bd65085377f077121d8791f9
parentf8e818026229579e5201b6225866d8b072ad586a (diff)
downloadprosody-c2ef1d7b32863d662b4decc8176604a49f289869.tar.gz
prosody-c2ef1d7b32863d662b4decc8176604a49f289869.zip
util.async: tests: Add helper function to create mock watcher callbacks
-rw-r--r--spec/util_async_spec.lua24
1 files changed, 15 insertions, 9 deletions
diff --git a/spec/util_async_spec.lua b/spec/util_async_spec.lua
index 955e3921..7cd125b7 100644
--- a/spec/util_async_spec.lua
+++ b/spec/util_async_spec.lua
@@ -8,17 +8,23 @@ describe("util.async", function()
else
print = function () end
end
- local function new(func, name)
- local log = {};
- return async.runner(func, setmetatable({}, {
+
+ local function mock_watchers()
+ return setmetatable(mock{
+ ready = function () end;
+ waiting = function () end;
+ error = function () end;
+ }, {
__index = function (_, event)
- return function (runner, err)
- print(name or runner.id, "event", event, err)
- print "--"
- table.insert(log, { event = event, err = err });
- end;
+ -- Unexpected watcher called
+ assert(false);
end;
- })), log;
+ })
+ end
+
+ local function new(func, name)
+ local log = {};
+ return async.runner(func, mock_watchers()), log;
end
describe("#runner", function()
it("should work", function()