aboutsummaryrefslogtreecommitdiffstats
path: root/test/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2020-03-09 12:11:11 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2020-03-09 12:11:11 +0000
commit89a670472d1208a5c9d92d5e2259cec18da0f723 (patch)
tree5fe240fc99a802570b2817065e8afb548defbdfd /test/lua
parentd1aa388f92e78f61207cf68e12b17689867cf801 (diff)
downloadrspamd-89a670472d1208a5c9d92d5e2259cec18da0f723.tar.gz
rspamd-89a670472d1208a5c9d92d5e2259cec18da0f723.zip
[Test] Sort hash tables in tests
Diffstat (limited to 'test/lua')
-rw-r--r--test/lua/rspamd_assertions.lua7
-rw-r--r--test/lua/unit/task.lua12
2 files changed, 13 insertions, 6 deletions
diff --git a/test/lua/rspamd_assertions.lua b/test/lua/rspamd_assertions.lua
index da01356ac..ac68cfc0a 100644
--- a/test/lua/rspamd_assertions.lua
+++ b/test/lua/rspamd_assertions.lua
@@ -17,6 +17,10 @@ local function rspamd_assert_table_equals(tbl)
return util.table_cmp(tbl.expect, tbl.actual)
end
+local function rspamd_assert_table_equals_sorted(tbl)
+ return util.table_cmp(table.sort(tbl.expect), table.sort(tbl.actual))
+end
+
local function table_keys_sorted(t)
local keys = {}
@@ -123,3 +127,6 @@ end
telescope.make_assertion("rspamd_eq", rspamd_assert_equals_msg, rspamd_assert_equals)
-- telescope.make_assertion("rspamd_table_eq", rspamd_assert_equals_msg, rspamd_assert_table_equals)
telescope.make_assertion("rspamd_table_eq", rspamd_assert_table_diff_msg, rspamd_assert_table_equals)
+telescope.make_assertion("rspamd_table_eq_sorted", rspamd_assert_table_diff_msg,
+ rspamd_assert_table_equals_sorted)
+
diff --git a/test/lua/unit/task.lua b/test/lua/unit/task.lua
index e9fc9e7d5..0739a2beb 100644
--- a/test/lua/unit/task.lua
+++ b/test/lua/unit/task.lua
@@ -51,7 +51,7 @@ Thank you,
local res,task = rspamd_task.load_from_string(msg)
assert_true(res, "failed to load message")
task:process_message()
- assert_rspamd_table_eq({actual = fun.totable(fun.map(function(u)
+ assert_rspamd_table_eq_sorted({actual = fun.totable(fun.map(function(u)
return u:get_host()
end, task:get_urls())), expect = {
'evil.com', 'example.com'
@@ -65,7 +65,7 @@ Thank you,
local res,task = rspamd_task.load_from_string(msg)
assert_true(res, "failed to load message")
task:process_message()
- assert_rspamd_table_eq({
+ assert_rspamd_table_eq_sorted({
actual = fun.totable(fun.map(function(u)
return u:get_host()
end, task:get_urls())),
@@ -82,7 +82,7 @@ Thank you,
local res,task = rspamd_task.load_from_string(msg)
assert_true(res, "failed to load message")
task:process_message()
- assert_rspamd_table_eq({
+ assert_rspamd_table_eq_sorted({
actual = fun.totable(fun.map(function(u)
return u:get_host()
end, task:get_urls())),
@@ -100,7 +100,7 @@ Thank you,
local res,task = rspamd_task.load_from_string(msg)
assert_true(res, "failed to load message")
task:process_message()
- assert_rspamd_table_eq({
+ assert_rspamd_table_eq_sorted({
actual = fun.totable(fun.map(function(u)
return u:get_host()
end, task:get_urls())),
@@ -122,7 +122,7 @@ Thank you,
local res,task = rspamd_task.load_from_string(msg)
assert_true(res, "failed to load message")
task:process_message()
- assert_rspamd_table_eq({
+ assert_rspamd_table_eq_sorted({
actual = fun.totable(fun.map(function(u)
return u:get_host()
end, task:get_urls())),
@@ -148,7 +148,7 @@ Thank you,
local res,task = rspamd_task.load_from_string(msg)
assert_true(res, "failed to load message")
task:process_message()
- assert_rspamd_table_eq({
+ assert_rspamd_table_eq_sorted({
actual = fun.totable(fun.map(function(u)
return u:get_host()
end, task:get_urls())),