summaryrefslogtreecommitdiffstats
path: root/test/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2022-11-22 23:50:55 +0000
committerVsevolod Stakhov <vsevolod@rspamd.com>2022-11-22 23:50:55 +0000
commitde2f7aa04e13e3691d91dfa4cf4d15fe744819ea (patch)
tree3421df4c796e891073422e1a9c5de7c4fd63d68b /test/lua
parent5858739fec90975fb2067374b06999dc8344597d (diff)
downloadrspamd-de2f7aa04e13e3691d91dfa4cf4d15fe744819ea.tar.gz
rspamd-de2f7aa04e13e3691d91dfa4cf4d15fe744819ea.zip
[Minor] Add tests and fix some minor issues
Diffstat (limited to 'test/lua')
-rw-r--r--test/lua/unit/selectors.lua35
1 files changed, 30 insertions, 5 deletions
diff --git a/test/lua/unit/selectors.lua b/test/lua/unit/selectors.lua
index c2fe4d7bd..6362e5cde 100644
--- a/test/lua/unit/selectors.lua
+++ b/test/lua/unit/selectors.lua
@@ -34,14 +34,21 @@ context("Selectors test", function()
end
end)
- local function check_selector(selector_string)
+ local function check_selector_plain(selector_string)
local sels = lua_selectors.create_selector_closure_fn(nil, cfg, selector_string, nil,
function(_, res, _) return res end)
local elts = sels(task)
return elts
end
- local cases = {
+ local function check_selector_kv(selector_string)
+ local sels = lua_selectors.create_selector_closure_fn(nil, cfg, selector_string, nil,
+ lua_selectors.kv_table_from_pairs)
+ local elts = sels(task)
+ return elts
+ end
+
+ local cases_plain = {
["ip"] = {
selector = "ip",
expect = {"198.172.22.91"}
@@ -379,9 +386,27 @@ context("Selectors test", function()
},
}
- for case_name, case in lua_util.spairs(cases) do
- test("case " .. case_name, function()
- local elts = check_selector(case.selector)
+ for case_name, case in lua_util.spairs(cases_plain) do
+ test("plain case " .. case_name, function()
+ local elts = check_selector_plain(case.selector)
+ assert_not_nil(elts)
+ assert_rspamd_table_eq_sorted({actual = elts, expect = case.expect})
+ end)
+ end
+
+ local cases_kv = {
+ ["ip"] = {
+ selector = "id('ip');ip",
+ expect = { ip = "198.172.22.91" }
+ },
+ ["ip+words"] = {
+ selector = "id('ip');ip;id('words');words('full'):2",
+ expect = { ip = "198.172.22.91", words = {'hello', 'world', '', 'mail', 'me'} }
+ },
+ }
+ for case_name, case in lua_util.spairs(cases_kv) do
+ test("kv case " .. case_name, function()
+ local elts = check_selector_kv(case.selector)
assert_not_nil(elts)
assert_rspamd_table_eq_sorted({actual = elts, expect = case.expect})
end)