aboutsummaryrefslogtreecommitdiffstats
path: root/test/lua/busted/modules/configuration_loader.lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-02-27 15:55:46 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-02-27 15:55:46 +0000
commit349bc58cf6d025e4e50a325bda48d318b23b55fb (patch)
tree04681b3f213983ce8fc4335190ea9713f272510d /test/lua/busted/modules/configuration_loader.lua
parent2f20e4f7fe5cf9b40dc8781675672e69437166e3 (diff)
downloadrspamd-349bc58cf6d025e4e50a325bda48d318b23b55fb.tar.gz
rspamd-349bc58cf6d025e4e50a325bda48d318b23b55fb.zip
Reorganize lua tests.
Diffstat (limited to 'test/lua/busted/modules/configuration_loader.lua')
-rw-r--r--test/lua/busted/modules/configuration_loader.lua34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/lua/busted/modules/configuration_loader.lua b/test/lua/busted/modules/configuration_loader.lua
new file mode 100644
index 000000000..f437a04cd
--- /dev/null
+++ b/test/lua/busted/modules/configuration_loader.lua
@@ -0,0 +1,34 @@
+return function()
+ local tablex = require 'pl.tablex'
+
+ -- Function to load the .busted configuration file if available
+ local loadBustedConfigurationFile = function(configFile, config, defaults)
+ if type(configFile) ~= 'table' then
+ return config, '.busted file does not return a table.'
+ end
+
+ local defaults = defaults or {}
+ local run = config.run or defaults.run
+
+ if run and run ~= '' then
+ local runConfig = configFile[run]
+
+ if type(runConfig) == 'table' then
+ config = tablex.merge(runConfig, config, true)
+ else
+ return config, 'Task `' .. run .. '` not found, or not a table.'
+ end
+ end
+
+ if type(configFile.default) == 'table' then
+ config = tablex.merge(configFile.default, config, true)
+ end
+
+ config = tablex.merge(defaults, config, true)
+
+ return config
+ end
+
+ return loadBustedConfigurationFile
+end
+