cleanup tests

This commit is contained in:
Dmitriy Ryajov 2022-09-19 15:53:38 -06:00
parent 4d43447ef2
commit 36655e318a
No known key found for this signature in database
GPG Key ID: DA8C680CE7C657A4

View File

@ -9,7 +9,9 @@ import pkg/stew/byteutils
import pkg/datastore/sql/sqliteds
suite "SQLiteDatastore":
import ../basictests
suite "Test Basic SQLiteDatastore":
let
(path, _, _) = instantiationInfo(-1, fullPaths = true) # get this file's name
basePath = "tests_data"
@ -20,6 +22,32 @@ suite "SQLiteDatastore":
bytes = "some bytes".toBytes
otherBytes = "some other bytes".toBytes
var
dsDb: SQLiteDatastore
setupAll:
removeDir(basePathAbs)
require(not dirExists(basePathAbs))
createDir(basePathAbs)
dsDb = SQLiteDatastore.new(path = dbPathAbs).tryGet()
teardownAll:
removeDir(basePathAbs)
require(not dirExists(basePathAbs))
basicStoreTests(dsDb, key, bytes, otherBytes)
suite "Test Read Only SQLiteDatastore":
let
(path, _, _) = instantiationInfo(-1, fullPaths = true) # get this file's name
basePath = "tests_data"
basePathAbs = path.parentDir / basePath
filename = "test_store" & DbExt
dbPathAbs = basePathAbs / filename
key = Key.init("a:b/c/d:e").tryGet()
bytes = "some bytes".toBytes
var
dsDb: SQLiteDatastore
readOnlyDb: SQLiteDatastore
@ -47,17 +75,6 @@ suite "SQLiteDatastore":
(await readOnlyDb.get(key)).tryGet() == bytes
(await dsDb.get(key)).tryGet() == bytes
test "put update":
check:
(await readOnlyDb.put(key, otherBytes)).isErr
(await dsDb.put(key, otherBytes)).tryGet()
test "get updated":
check:
(await readOnlyDb.get(key)).tryGet() == otherBytes
(await dsDb.get(key)).tryGet() == otherBytes
test "delete":
check:
(await readOnlyDb.delete(key)).isErr