aboutsummaryrefslogtreecommitdiffstats
path: root/test/lua/unit/sqlite3.lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-01-25 16:16:19 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-01-25 16:16:19 +0000
commit2a81086ec387a9a874900bceed0b0cca2032bdc9 (patch)
tree0e362571841aa0f8dd59009ad4d0b55623f896b7 /test/lua/unit/sqlite3.lua
parent0fa975e21b80eb1423d0bdbcaa825ab01025d6c5 (diff)
downloadrspamd-2a81086ec387a9a874900bceed0b0cca2032bdc9.tar.gz
rspamd-2a81086ec387a9a874900bceed0b0cca2032bdc9.zip
Add lua_sqlite3 unit tests
Diffstat (limited to 'test/lua/unit/sqlite3.lua')
-rw-r--r--test/lua/unit/sqlite3.lua49
1 files changed, 49 insertions, 0 deletions
diff --git a/test/lua/unit/sqlite3.lua b/test/lua/unit/sqlite3.lua
new file mode 100644
index 000000000..9fec2b694
--- /dev/null
+++ b/test/lua/unit/sqlite3.lua
@@ -0,0 +1,49 @@
+context("Sqlite3 API", function()
+ local sqlite3 = require "rspamd_sqlite3"
+
+ test("Sqlite3 open", function()
+ os.remove('/tmp/rspamd_unit_test_sqlite3.sqlite')
+ local db = sqlite3.open('/tmp/rspamd_unit_test_sqlite3.sqlite')
+ assert_not_nil(db, "should be able to create sqlite3 db")
+ db = sqlite3.open('/non/existent/path/rspamd_unit_test_sqlite3.sqlite')
+ assert_nil(db, "should not be able to create sqlite3 db")
+ os.remove('/tmp/rspamd_unit_test_sqlite3.sqlite')
+ end)
+
+ test("Sqlite3 query", function()
+ os.remove('/tmp/rspamd_unit_test_sqlite3-1.sqlite')
+ local db = sqlite3.open('/tmp/rspamd_unit_test_sqlite3-1.sqlite')
+ assert_not_nil(db, "should be able to create sqlite3 db")
+
+ local ret = db:sql([[
+ CREATE TABLE x (id INT, value TEXT);
+ ]])
+ assert_true(ret, "should be able to create table")
+ local ret = db:sql([[
+ INSERT INTO x VALUES (?1, ?2);
+ ]], 1, 'test')
+ assert_true(ret, "should be able to insert row")
+ os.remove('/tmp/rspamd_unit_test_sqlite3-1.sqlite')
+ end)
+
+ test("Sqlite3 rows", function()
+ os.remove('/tmp/rspamd_unit_test_sqlite3-2.sqlite')
+ local db = sqlite3.open('/tmp/rspamd_unit_test_sqlite3-2.sqlite')
+ assert_not_nil(db, "should be able to create sqlite3 db")
+
+ local ret = db:sql([[
+ CREATE TABLE x (id INT, value TEXT);
+ ]])
+ assert_true(ret, "should be able to create table")
+ local ret = db:sql([[
+ INSERT INTO x VALUES (?1, ?2);
+ ]], 1, 'test')
+ 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.value, 'test')
+ end
+ os.remove('/tmp/rspamd_unit_test_sqlite3-2.sqlite')
+ end)
+end) \ No newline at end of file