diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 21:30:40 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 21:30:40 +0000 |
commit | 133a45c109da5310add55824db21af5239951f93 (patch) | |
tree | ba6ac4c0a950a0dda56451944315d66409923918 /test/lua/unit/mempool.lua | |
parent | Initial commit. (diff) | |
download | rspamd-upstream.tar.xz rspamd-upstream.zip |
Adding upstream version 3.8.1.upstream/3.8.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/lua/unit/mempool.lua')
-rw-r--r-- | test/lua/unit/mempool.lua | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/test/lua/unit/mempool.lua b/test/lua/unit/mempool.lua new file mode 100644 index 0000000..fefd3d2 --- /dev/null +++ b/test/lua/unit/mempool.lua @@ -0,0 +1,47 @@ +context("Memory pool unit tests", function() + test("Mempool variables", function() + local mempool = require "rspamd_mempool" + + local pool = mempool.create() + + assert_not_nil(pool) + + -- string + pool:set_variable('a', 'bcd') + local var = pool:get_variable('a') + assert_equal(var, 'bcd') + + -- integer + pool:set_variable('a', 1) + var = pool:get_variable('a', 'double') + assert_equal(var, 1) + + -- float + pool:set_variable('a', 1.01) + var = pool:get_variable('a', 'double') + assert_equal(var, 1.01) + + -- boolean + pool:set_variable('a', false) + var = pool:get_variable('a', 'bool') + assert_equal(var, false) + + -- multiple + pool:set_variable('a', 'bcd', 1, 1.01, false) + local v1, v2, v3, v4 = pool:get_variable('a', 'string,double,double,bool') + assert_equal(v1, 'bcd') + assert_equal(v2, 1) + assert_equal(v3, 1.01) + assert_equal(v4, false) + + local t = {1,2,3,4,5} + pool:set_variable('a', t) + local bucket = pool:get_variable('a', 'bucket') + assert_rspamd_table_eq({ + expect = t, + actual = bucket + }) + + pool:destroy() + end) +end)
\ No newline at end of file |