summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2018-06-18 19:47:51 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-07-10 17:12:13 +0200
commit30de5a13f69da857e4bcaae3016d4471235d1d05 (patch)
tree55f3c0c8875a71203b673b73c0aaeeef3491ef24
parent7c4afe65e3e308e53c661ecf306a985995d727e3 (diff)
Added Not Received assert and test functions
Change-Id: Ic5bdbb9c57144acac2ca54c0c60ef202766c5704 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r--conf.d/project/lua.d/aft.lua27
1 files changed, 25 insertions, 2 deletions
diff --git a/conf.d/project/lua.d/aft.lua b/conf.d/project/lua.d/aft.lua
index 1d74c08..0c7c307 100644
--- a/conf.d/project/lua.d/aft.lua
+++ b/conf.d/project/lua.d/aft.lua
@@ -52,11 +52,11 @@ end
]]
function _AFT.addEventToMonitor(eventName, callback)
- _AFT.monitored_events[eventName] = { cb = callback }
+ _AFT.monitored_events[eventName] = { cb = callback, receivedCount = 0 }
end
function _AFT.addLogToMonitor(api, type, message, callback)
- _AFT.monitored_events[message] = { api = api, type = type, cb = callback }
+ _AFT.monitored_events[message] = { api = api, type = type, cb = callback, receivedCount = 0 }
end
function _AFT.incrementCount(dict)
@@ -125,6 +125,20 @@ end
Assert and test functions about the event part.
]]
+function _AFT.assertEvtNotReceived(eventName)
+ local count = 0
+ if _AFT.monitored_events[eventName].receivedCount then
+ count = _AFT.monitored_events[eventName].receivedCount
+ end
+
+ _AFT.assertIsTrue(count == 0, "Event '".. eventName .."' received but it shouldn't")
+
+ if _AFT.monitored_events[eventName].cb then
+ local data_n = #_AFT.monitored_events[eventName].data
+ _AFT.monitored_events[eventName].cb(eventName, _AFT.monitored_events[eventName].data[data_n])
+ end
+end
+
function _AFT.assertEvtReceived(eventName)
local count = 0
if _AFT.monitored_events[eventName].receivedCount then
@@ -139,6 +153,13 @@ function _AFT.assertEvtReceived(eventName)
end
end
+function _AFT.testEvtNotReceived(testName, eventName, timeout)
+ table.insert(_AFT.tests_list, {testName, function()
+ if timeout then sleep(timeout) end
+ _AFT.assertEvtNotReceived(eventName)
+ end})
+end
+
function _AFT.testEvtReceived(testName, eventName, timeout)
table.insert(_AFT.tests_list, {testName, function()
if timeout then sleep(timeout) end
@@ -375,6 +396,7 @@ local _AFT_list_of_funcs = {
{ 'assertVerbError', 'assertVerbResponseEqualsError' },
{ 'assertVerbError', 'assertVerbCbError' },
{ 'assertEvtReceived', 'assertLogReceived' },
+ { 'assertEvtNotReceived', 'assertLogNotReceived' },
{ 'testVerb', 'testVerbStatusSuccess' },
{ 'testVerb', 'testVerbResponseEquals' },
{ 'testVerb', 'testVerbCb' },
@@ -382,6 +404,7 @@ local _AFT_list_of_funcs = {
{ 'testVerbError', 'testVerbResponseEqualsError' },
{ 'testVerbError', 'testVerbCbError' },
{ 'testEvtReceived', 'testLogReceived' },
+ { 'testEvtNotReceived', 'testLogNotReceived' },
}
-- Import all luaunit assertion function to _AFT object