This commit is contained in:
Jaremy Creechley 2023-09-28 17:51:25 -07:00
parent 96c54f6412
commit 4739167213
No known key found for this signature in database
GPG Key ID: 4E66FB67B21D3300
6 changed files with 93 additions and 98 deletions

View File

@ -1,7 +1,7 @@
import ./datastore/datastore
import ./datastore/fsds
# import ./datastore/sql
import ./datastore/sql
import ./datastore/mountedds
import ./datastore/tieredds
export datastore, fsds, mountedds, tieredds
export datastore, fsds, sql, mountedds, tieredds

View File

@ -14,7 +14,7 @@ import ./threads/sqlbackend
import ./threads/threadproxyds
import ./datastore
export datastore, Taskpool
export datastore, keys, query, Taskpool
push: {.upraises: [].}

View File

@ -1,90 +0,0 @@
import std/options
import std/os
import std/sequtils
from std/algorithm import sort, reversed
import pkg/asynctest
import pkg/chronos
import pkg/stew/results
import pkg/stew/byteutils
import pkg/datastore/sql
import ../dscommontests
import ../querycommontests
suite "Test Basic SQLiteDatastore":
let
ds = SQLiteDatastore.new(Memory).tryGet()
key = Key.init("a:b/c/d:e").tryGet()
bytes = "some bytes".toBytes
otherBytes = "some other bytes".toBytes
teardownAll:
(await ds.close()).tryGet()
basicStoreTests(ds, key, bytes, otherBytes)
suite "Test Read Only SQLiteDatastore":
let
path = currentSourcePath() # 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
setupAll:
removeDir(basePathAbs)
require(not dirExists(basePathAbs))
createDir(basePathAbs)
dsDb = SQLiteDatastore.new(path = dbPathAbs).tryGet()
readOnlyDb = SQLiteDatastore.new(path = dbPathAbs, readOnly = true).tryGet()
teardownAll:
(await dsDb.close()).tryGet()
(await readOnlyDb.close()).tryGet()
removeDir(basePathAbs)
require(not dirExists(basePathAbs))
test "put":
check:
(await readOnlyDb.put(key, bytes)).isErr
(await dsDb.put(key, bytes)).tryGet()
test "get":
check:
(await readOnlyDb.get(key)).tryGet() == bytes
(await dsDb.get(key)).tryGet() == bytes
test "delete":
check:
(await readOnlyDb.delete(key)).isErr
(await dsDb.delete(key)).tryGet()
test "contains":
check:
not (await readOnlyDb.has(key)).tryGet()
not (await dsDb.has(key)).tryGet()
# suite "Test Query":
# var
# ds: SQLiteDatastore
# setup:
# ds = SQLiteDatastore.new(Memory).tryGet()
# teardown:
# (await ds.close()).tryGet
# queryTests(ds)

View File

@ -1,4 +1,90 @@
import ./sql/testsqlitedsdb
import ./sql/testsqliteds
import std/options
import std/os
import std/sequtils
from std/algorithm import sort, reversed
{.warning[UnusedImport]: off.}
import pkg/asynctest
import pkg/chronos
import pkg/stew/results
import pkg/stew/byteutils
import pkg/datastore/sql
import ./dscommontests
import ./querycommontests
suite "Test Basic SQLiteDatastore":
let
ds = SQLiteDatastore.new(Memory).tryGet()
key = Key.init("a:b/c/d:e").tryGet()
bytes = "some bytes".toBytes
otherBytes = "some other bytes".toBytes
teardownAll:
(await ds.close()).tryGet()
basicStoreTests(ds, key, bytes, otherBytes)
suite "Test Read Only SQLiteDatastore":
let
path = currentSourcePath() # 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
setupAll:
removeDir(basePathAbs)
require(not dirExists(basePathAbs))
createDir(basePathAbs)
dsDb = SQLiteDatastore.new(path = dbPathAbs).tryGet()
readOnlyDb = SQLiteDatastore.new(path = dbPathAbs, readOnly = true).tryGet()
teardownAll:
(await dsDb.close()).tryGet()
(await readOnlyDb.close()).tryGet()
removeDir(basePathAbs)
require(not dirExists(basePathAbs))
test "put":
check:
(await readOnlyDb.put(key, bytes)).isErr
(await dsDb.put(key, bytes)).tryGet()
test "get":
check:
(await readOnlyDb.get(key)).tryGet() == bytes
(await dsDb.get(key)).tryGet() == bytes
test "delete":
check:
(await readOnlyDb.delete(key)).isErr
(await dsDb.delete(key)).tryGet()
test "contains":
check:
not (await readOnlyDb.has(key)).tryGet()
not (await dsDb.has(key)).tryGet()
# suite "Test Query":
# var
# ds: SQLiteDatastore
# setup:
# ds = SQLiteDatastore.new(Memory).tryGet()
# teardown:
# (await ds.close()).tryGet
# queryTests(ds)

View File

@ -11,8 +11,7 @@ import pkg/stew/byteutils
import pkg/datastore/threads/sqlbackend
import pkg/datastore/key
import ../backendCommonTests
import ./backendCommonTests
suite "Test Basic SQLiteDatastore":
let