aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-04-23 15:27:03 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-04-23 15:27:03 +0100
commit88b2b5b24f1b70be17a1ede3d70fd4b96959d569 (patch)
treef59261db9b09bcbc39ecab29d3fbf67f3425cfbb /test
parent43c18e6f521ff51cb60b1e502a5e00ce027752cd (diff)
downloadrspamd-88b2b5b24f1b70be17a1ede3d70fd4b96959d569.tar.gz
rspamd-88b2b5b24f1b70be17a1ede3d70fd4b96959d569.zip
[Test] Fix unit tests
Diffstat (limited to 'test')
-rw-r--r--test/lua/unit/regxep.lua2
-rw-r--r--test/lua/unit/sqlite3.lua2
-rw-r--r--test/lua/unit/trie.lua34
-rw-r--r--test/lua/unit/url.lua7
4 files changed, 29 insertions, 16 deletions
diff --git a/test/lua/unit/regxep.lua b/test/lua/unit/regxep.lua
index 0bb4db935..a27e7b363 100644
--- a/test/lua/unit/regxep.lua
+++ b/test/lua/unit/regxep.lua
@@ -9,13 +9,13 @@ context("Regexp unit tests", function()
end)
test("Regexp match", function()
local cases = {
+ {'/Тест/iu', 'тест', true},
{'/test$/m', '123test', true},
{'/^test$/m', '123test', false},
{'m,test,', 'test', true},
{'m,test,', 'test123', false},
{'m{https?://[^/?\\s]+?:\\d+(?<!:80)(?<!:443)(?<!:8080)(?:/|\\s|$)}', '', false},
{'/test/i', 'TeSt123', true},
- {'/ТесТ/iu', 'тест', true},
-- Raw regexp
{'/\\S<[-\\w\\.]+\\@[-\\w\\.]+>/r', 'some<example@example.com>', true},
-- Cyrillic utf8 letter
diff --git a/test/lua/unit/sqlite3.lua b/test/lua/unit/sqlite3.lua
index 9fec2b694..15dc3d3fb 100644
--- a/test/lua/unit/sqlite3.lua
+++ b/test/lua/unit/sqlite3.lua
@@ -41,7 +41,7 @@ context("Sqlite3 API", function()
assert_true(ret, "should be able to insert row")
for row in db:rows([[SELECT * FROM x;]]) do
- assert_equal(row.id, 1)
+ assert_equal(row.id, '1')
assert_equal(row.value, 'test')
end
os.remove('/tmp/rspamd_unit_test_sqlite3-2.sqlite')
diff --git a/test/lua/unit/trie.lua b/test/lua/unit/trie.lua
index 5191d9e26..e37d40e36 100644
--- a/test/lua/unit/trie.lua
+++ b/test/lua/unit/trie.lua
@@ -2,7 +2,8 @@
context("Trie search functions", function()
local t = require "rspamd_trie"
-
+ local logger = require "rspamd_logger"
+
test("Trie search", function()
local patterns = {
'test',
@@ -11,47 +12,52 @@ context("Trie search functions", function()
'she',
'str\0ing'
}
-
+
local trie = t.create(patterns)
assert_not_nil(trie, "cannot create trie")
-
+
local cases = {
{'test', true, {{4, 1}, {4, 2}}},
{'she test test', true, {{3, 4}, {3, 3}, {8, 1}, {8, 2}, {13, 1}, {13, 2}}},
{'non-existent', false},
{'str\0ing test', true, {{7, 5}, {12, 1}, {12, 2}}},
}
-
+
local function comparetables(t1, t2)
if #t1 ~= #t2 then return false end
for i=1,#t1 do
if type(t1[i]) ~= type(t2[i]) then return false
elseif type(t1[i]) == 'table' then
if not comparetables(t1[i], t2[i]) then return false end
- elseif t1[i] ~= t2[i] then
- return false
+ elseif t1[i] ~= t2[i] then
+ return false
end
end
return true
end
-
+
for _,c in ipairs(cases) do
local res = {}
local function cb(idx, pos)
table.insert(res, {pos, idx})
-
+
return 0
end
-
+
ret = trie:match(c[1], cb)
-
+
assert_equal(c[2], ret, tostring(c[2]) .. ' while matching ' .. c[1])
-
+
if ret then
+ table.sort(res, function(a, b) return a[2] > b[2] end)
+ table.sort(c[3], function(a, b) return a[2] > b[2] end)
local cmp = comparetables(res, c[3])
- assert_true(cmp, 'valid results for case: ' .. c[1])
+ assert_true(cmp, 'valid results for case: ' .. c[1] ..
+ ' got: ' .. logger.slog('%s', res) .. ' expected: ' ..
+ logger.slog('%s', c[3])
+ )
end
end
-
+
end)
-end) \ No newline at end of file
+end)
diff --git a/test/lua/unit/url.lua b/test/lua/unit/url.lua
index 0b385c063..06082afe0 100644
--- a/test/lua/unit/url.lua
+++ b/test/lua/unit/url.lua
@@ -18,6 +18,8 @@ context("URL check functions", function()
local pool = mpool.create()
local cases = {
{"test.com text", {"test.com", nil}},
+ {" test.com text", {"test.com", nil}},
+ {"<test.com> text", {"test.com", nil}},
{"test.com. text", {"test.com", nil}},
{"mailto:A.User@example.com text", {"example.com", "A.User"}},
{"http://Тест.Рф:18 text", {"тест.рф", nil}},
@@ -60,6 +62,11 @@ context("URL check functions", function()
host = 'www.google.com', path = 'foo', query = 'bar=baz', tld = 'google.com'
}},
{"http://[www.google.com]/", false},
+ {"<test.com", true, {
+ host = 'test.com', tld = 'test.com',
+ }},
+ {"test.com>", false},
+ {",test.com text", false},
{"ht\ttp:@www.google.com:80/;p?#", false},
{"http://user:pass@/", false},
{"http://foo:-80/", false},