summaryrefslogtreecommitdiffstats
path: root/test/lua/unit/sqlite3.lua
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 21:30:40 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 21:30:40 +0000
commit133a45c109da5310add55824db21af5239951f93 (patch)
treeba6ac4c0a950a0dda56451944315d66409923918 /test/lua/unit/sqlite3.lua
parentInitial commit. (diff)
downloadrspamd-133a45c109da5310add55824db21af5239951f93.tar.xz
rspamd-133a45c109da5310add55824db21af5239951f93.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/sqlite3.lua')
-rw-r--r--test/lua/unit/sqlite3.lua50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/lua/unit/sqlite3.lua b/test/lua/unit/sqlite3.lua
new file mode 100644
index 0000000..c431258
--- /dev/null
+++ b/test/lua/unit/sqlite3.lua
@@ -0,0 +1,50 @@
+context("Sqlite3 API", function()
+ local sqlite3 = require "rspamd_sqlite3"
+ local tmpdir = os.getenv("TMPDIR") or "/tmp"
+
+ test("Sqlite3 open", function()
+ os.remove(tmpdir .. '/rspamd_unit_test_sqlite3.sqlite')
+ local db = sqlite3.open(tmpdir .. '/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(tmpdir .. '/rspamd_unit_test_sqlite3.sqlite')
+ end)
+
+ test("Sqlite3 query", function()
+ os.remove(tmpdir .. '/rspamd_unit_test_sqlite3-1.sqlite')
+ local db = sqlite3.open(tmpdir .. '/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(tmpdir .. '/rspamd_unit_test_sqlite3-1.sqlite')
+ end)
+
+ test("Sqlite3 rows", function()
+ os.remove(tmpdir .. '/rspamd_unit_test_sqlite3-2.sqlite')
+ local db = sqlite3.open(tmpdir .. '/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(tmpdir .. '/rspamd_unit_test_sqlite3-2.sqlite')
+ end)
+end) \ No newline at end of file