commit b1c6115: [Test] Add a simple config helper for the unit tests

Vsevolod Stakhov vsevolod at highsecure.ru
Wed Nov 24 20:49:04 UTC 2021


Author: Vsevolod Stakhov
Date: 2021-11-24 09:45:52 +0000
URL: https://github.com/rspamd/rspamd/commit/b1c611505e3e0bac95570fd76dcfaad21814f319

[Test] Add a simple config helper for the unit tests

---
 test/lua/rspamd_test_helper.lua                  | 28 ++++++++++++++++++++++++
 test/lua/unit/lua_util.extract_specific_urls.lua | 27 +++--------------------
 2 files changed, 31 insertions(+), 24 deletions(-)

diff --git a/test/lua/rspamd_test_helper.lua b/test/lua/rspamd_test_helper.lua
index 80ca2c8f7..4d58d261a 100644
--- a/test/lua/rspamd_test_helper.lua
+++ b/test/lua/rspamd_test_helper.lua
@@ -15,4 +15,32 @@ function exports.init_url_parser(file)
   ffi.C.rspamd_url_init(file)
 end
 
+function exports.default_config()
+  local test_dir = string.gsub(debug.getinfo(1).source, "^@(.+/)[^/]+$", "%1")
+  local tld_file = string.format('%s/%s', test_dir, "test_tld.dat")
+
+  local config = {
+    options = {
+      filters = {'spf', 'dkim', 'regexp'},
+      url_tld = tld_file,
+      dns = {
+        nameserver = {'8.8.8.8'}
+      },
+    },
+    logging = {
+      type = 'console',
+      level = 'debug'
+    },
+    metric = {
+      name = 'default',
+      actions = {
+        reject = 100500,
+      },
+      unknown_weight = 1
+    }
+  }
+
+  return config
+end
+
 return exports
\ No newline at end of file
diff --git a/test/lua/unit/lua_util.extract_specific_urls.lua b/test/lua/unit/lua_util.extract_specific_urls.lua
index b1a9b07d2..a8471ae23 100644
--- a/test/lua/unit/lua_util.extract_specific_urls.lua
+++ b/test/lua/unit/lua_util.extract_specific_urls.lua
@@ -203,31 +203,10 @@ end)
 context("Lua util - extract_specific_urls message", function()
 
 --[[ ******************* kinda functional *************************************** ]]
-  local test_dir = string.gsub(debug.getinfo(1).source, "^@(.+/)[^/]+$", "%1")
-  local tld_file = string.format('%s/%s', test_dir, "test_tld.dat")
-
-  local config = {
-    options = {
-      filters = {'spf', 'dkim', 'regexp'},
-      url_tld = tld_file,
-      dns = {
-        nameserver = {'8.8.8.8'}
-      },
-    },
-    logging = {
-      type = 'console',
-      level = 'debug'
-    },
-    metric = {
-      name = 'default',
-      actions = {
-        reject = 100500,
-      },
-      unknown_weight = 1
-    }
-  }
 
-  local cfg = rspamd_util.config_from_ucl(config, "INIT_URL,INIT_LIBS,INIT_SYMCACHE,INIT_VALIDATE,INIT_PRELOAD_MAPS")
+
+  local cfg = rspamd_util.config_from_ucl(rspamd_test_helper.default_config(),
+      "INIT_URL,INIT_LIBS,INIT_SYMCACHE,INIT_VALIDATE,INIT_PRELOAD_MAPS")
   local res,task = rspamd_task.load_from_string(msg, cfg)
 
   if not res then


More information about the Commits mailing list