SQLite3 persistence test: Don't leave file in CWD

This commit is contained in:
Lars Mueller 2022-01-23 13:53:15 +01:00
parent f7bb444f78
commit 5b9cfa16a1

@ -424,7 +424,8 @@ test_logfile(false)
-- SQLite3 -- SQLite3
do do
local sqlite3 = persistence.sqlite3() local sqlite3 = persistence.sqlite3()
local p = sqlite3.new("database.test.sqlite3", {}) local path = modlib.mod.get_resource("modlib", "database.test.sqlite3")
local p = sqlite3.new(path, {})
p:init() p:init()
p:rewrite() p:rewrite()
p:set_root("key", "value") p:set_root("key", "value")
@ -432,14 +433,14 @@ do
p:set_root("other key", "other value") p:set_root("other key", "other value")
p:set_root("key", "other value") p:set_root("key", "other value")
p:set_root("key", nil) p:set_root("key", nil)
local x = {x = 1, y = 2} local x = { x = 1, y = 2 }
p:set_root("x1", x) p:set_root("x1", x)
p:set_root("x2", x) p:set_root("x2", x)
p:set_root("x2", nil) p:set_root("x2", nil)
p:set_root("x1", nil) p:set_root("x1", nil)
p:set_root("key", {a = 1, b = 2, c = {a = 1}}) p:set_root("key", { a = 1, b = 2, c = { a = 1 } })
p:set_root("key", nil) p:set_root("key", nil)
p:set_root("key", {a = 1, b = 2, c = 3}) p:set_root("key", { a = 1, b = 2, c = 3 })
local cyclic = {} local cyclic = {}
cyclic.cycle = cyclic cyclic.cycle = cyclic
p:set_root("cyclic", cyclic) p:set_root("cyclic", cyclic)
@ -447,24 +448,25 @@ do
p:collectgarbage() p:collectgarbage()
p:defragment_ids() p:defragment_ids()
local rows = {} local rows = {}
for row in p.database:rows"SELECT * FROM table_entries ORDER BY table_id, key_type, key" do for row in p.database:rows("SELECT * FROM table_entries ORDER BY table_id, key_type, key") do
_G.table.insert(rows, row) _G.table.insert(rows, row)
end end
assert(modlib.table.equals(rows, { assert(modlib.table.equals(rows, {
{1, 3, "key", 4, 2}, { 1, 3, "key", 4, 2 },
{1, 3, "other key", 3, "other value"}, { 1, 3, "other key", 3, "other value" },
{2, 3, "a", 2, 1}, { 2, 3, "a", 2, 1 },
{2, 3, "b", 2, 2}, { 2, 3, "b", 2, 2 },
{2, 3, "c", 2, 3} { 2, 3, "c", 2, 3 },
})) }))
p:close() p:close()
p = sqlite3.new("database.test.sqlite3", {}) p = sqlite3.new(path, {})
p:init() p:init()
assert(modlib.table.equals(p.root, { assert(modlib.table.equals(p.root, {
key = {a = 1, b = 2, c = 3}, key = { a = 1, b = 2, c = 3 },
["other key"] = "other value" ["other key"] = "other value",
})) }))
p:close() p:close()
os.remove(path)
end end
-- in-game tests & b3d testing -- in-game tests & b3d testing