| 1 |
context("Memory pool unit tests", function() |
| 2 |
test("Mempool variables", function() |
| 3 |
local mempool = require "rspamd_mempool" |
| 4 |
|
| 5 |
local pool = mempool.create() |
| 6 |
|
| 7 |
assert_not_nil(pool) |
| 8 |
|
| 9 |
-- string |
| 10 |
pool:set_variable('a', 'bcd') |
| 11 |
local var = pool:get_variable('a') |
| 12 |
assert_equal(var, 'bcd') |
| 13 |
|
| 14 |
-- integer |
| 15 |
pool:set_variable('a', 1) |
| 16 |
var = pool:get_variable('a', 'double') |
| 17 |
assert_equal(var, 1) |
| 18 |
|
| 19 |
-- float |
| 20 |
pool:set_variable('a', 1.01) |
| 21 |
var = pool:get_variable('a', 'double') |
| 22 |
assert_equal(var, 1.01) |
| 23 |
|
| 24 |
-- boolean |
| 25 |
pool:set_variable('a', false) |
| 26 |
var = pool:get_variable('a', 'bool') |
| 27 |
assert_equal(var, false) |
| 28 |
|
| 29 |
-- multiple |
| 30 |
pool:set_variable('a', 'bcd', 1, 1.01, false) |
| 31 |
local v1, v2, v3, v4 = pool:get_variable('a', 'string,double,double,bool') |
| 32 |
assert_equal(v1, 'bcd') |
| 33 |
assert_equal(v2, 1) |
| 34 |
assert_equal(v3, 1.01) |
| 35 |
assert_equal(v4, false) |
| 36 |
|
| 37 |
local t = {1,2,3,4,5} |
| 38 |
pool:set_variable('a', t) |
| 39 |
local bucket = pool:get_variable('a', 'bucket') |
| 40 |
assert_rspamd_table_eq({ |
| 41 |
expect = t, |
| 42 |
actual = bucket |
| 43 |
}) |
| 44 |
|
| 45 |
pool:destroy() |
| 46 |
end) |
| 47 |
end) |