mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-25 16:53:46 +01:00
SQLite3 persistence test: Don't leave file in CWD
This commit is contained in:
parent
f7bb444f78
commit
5b9cfa16a1
28
test.lua
28
test.lua
@ -424,7 +424,8 @@ test_logfile(false)
|
||||
-- SQLite3
|
||||
do
|
||||
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:rewrite()
|
||||
p:set_root("key", "value")
|
||||
@ -432,14 +433,14 @@ do
|
||||
p:set_root("other key", "other value")
|
||||
p:set_root("key", "other value")
|
||||
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("x2", x)
|
||||
p:set_root("x2", 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", {a = 1, b = 2, c = 3})
|
||||
p:set_root("key", { a = 1, b = 2, c = 3 })
|
||||
local cyclic = {}
|
||||
cyclic.cycle = cyclic
|
||||
p:set_root("cyclic", cyclic)
|
||||
@ -447,24 +448,25 @@ do
|
||||
p:collectgarbage()
|
||||
p:defragment_ids()
|
||||
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)
|
||||
end
|
||||
assert(modlib.table.equals(rows, {
|
||||
{1, 3, "key", 4, 2},
|
||||
{1, 3, "other key", 3, "other value"},
|
||||
{2, 3, "a", 2, 1},
|
||||
{2, 3, "b", 2, 2},
|
||||
{2, 3, "c", 2, 3}
|
||||
{ 1, 3, "key", 4, 2 },
|
||||
{ 1, 3, "other key", 3, "other value" },
|
||||
{ 2, 3, "a", 2, 1 },
|
||||
{ 2, 3, "b", 2, 2 },
|
||||
{ 2, 3, "c", 2, 3 },
|
||||
}))
|
||||
p:close()
|
||||
p = sqlite3.new("database.test.sqlite3", {})
|
||||
p = sqlite3.new(path, {})
|
||||
p:init()
|
||||
assert(modlib.table.equals(p.root, {
|
||||
key = {a = 1, b = 2, c = 3},
|
||||
["other key"] = "other value"
|
||||
key = { a = 1, b = 2, c = 3 },
|
||||
["other key"] = "other value",
|
||||
}))
|
||||
p:close()
|
||||
os.remove(path)
|
||||
end
|
||||
|
||||
-- in-game tests & b3d testing
|
||||
|
Loading…
Reference in New Issue
Block a user