2022-09-19 15:54:19 -06:00
|
|
|
import std/options
|
2022-09-20 20:18:33 -04:00
|
|
|
import std/sequtils
|
2022-09-19 15:54:19 -06:00
|
|
|
import std/os
|
2022-09-20 20:18:33 -04:00
|
|
|
from std/algorithm import sort, reversed
|
2022-09-19 15:54:19 -06:00
|
|
|
|
2023-09-11 14:21:01 -06:00
|
|
|
import pkg/asynctest
|
2022-09-19 15:54:19 -06:00
|
|
|
import pkg/chronos
|
|
|
|
|
import pkg/stew/results
|
|
|
|
|
import pkg/stew/byteutils
|
|
|
|
|
|
|
|
|
|
import pkg/datastore/fsds
|
|
|
|
|
|
2022-09-20 20:18:33 -04:00
|
|
|
import ./dscommontests
|
2023-12-19 15:49:44 +01:00
|
|
|
import ./modifycommontests
|
2022-09-20 20:18:33 -04:00
|
|
|
import ./querycommontests
|
2024-05-08 14:01:00 +02:00
|
|
|
import ./typeddscommontests
|
2022-09-19 15:54:19 -06:00
|
|
|
|
|
|
|
|
suite "Test Basic FSDatastore":
|
|
|
|
|
let
|
2022-11-22 15:23:23 -06:00
|
|
|
path = currentSourcePath() # get this file's name
|
2022-09-19 15:54:19 -06:00
|
|
|
basePath = "tests_data"
|
|
|
|
|
basePathAbs = path.parentDir / basePath
|
|
|
|
|
key = Key.init("/a/b").tryGet()
|
|
|
|
|
bytes = "some bytes".toBytes
|
|
|
|
|
otherBytes = "some other bytes".toBytes
|
|
|
|
|
|
|
|
|
|
var
|
|
|
|
|
fsStore: FSDatastore
|
|
|
|
|
|
|
|
|
|
setupAll:
|
|
|
|
|
removeDir(basePathAbs)
|
|
|
|
|
require(not dirExists(basePathAbs))
|
|
|
|
|
createDir(basePathAbs)
|
|
|
|
|
|
2022-09-30 10:24:26 -04:00
|
|
|
fsStore = FSDatastore.new(root = basePathAbs, depth = 3).tryGet()
|
2022-09-19 15:54:19 -06:00
|
|
|
|
|
|
|
|
teardownAll:
|
|
|
|
|
removeDir(basePathAbs)
|
|
|
|
|
require(not dirExists(basePathAbs))
|
|
|
|
|
|
|
|
|
|
basicStoreTests(fsStore, key, bytes, otherBytes)
|
2023-12-19 15:49:44 +01:00
|
|
|
modifyTests(fsStore, key)
|
2024-05-08 14:01:00 +02:00
|
|
|
typedDsTests(fsStore, key)
|
2022-09-19 15:54:19 -06:00
|
|
|
|
|
|
|
|
suite "Test Misc FSDatastore":
|
|
|
|
|
let
|
2022-11-22 15:23:23 -06:00
|
|
|
path = currentSourcePath() # get this file's name
|
2022-09-19 15:54:19 -06:00
|
|
|
basePath = "tests_data"
|
|
|
|
|
basePathAbs = path.parentDir / basePath
|
|
|
|
|
bytes = "some bytes".toBytes
|
|
|
|
|
|
2022-09-20 20:18:33 -04:00
|
|
|
setup:
|
2022-09-19 15:54:19 -06:00
|
|
|
removeDir(basePathAbs)
|
|
|
|
|
require(not dirExists(basePathAbs))
|
|
|
|
|
createDir(basePathAbs)
|
|
|
|
|
|
2022-09-20 20:18:33 -04:00
|
|
|
teardown:
|
2022-09-19 15:54:19 -06:00
|
|
|
removeDir(basePathAbs)
|
|
|
|
|
require(not dirExists(basePathAbs))
|
|
|
|
|
|
|
|
|
|
test "Test validDepth()":
|
|
|
|
|
let
|
|
|
|
|
fs = FSDatastore.new(root = "/", depth = 3).tryGet()
|
|
|
|
|
invalid = Key.init("/a/b/c/d").tryGet()
|
|
|
|
|
valid = Key.init("/a/b/c").tryGet()
|
|
|
|
|
|
|
|
|
|
check:
|
|
|
|
|
not fs.validDepth(invalid)
|
|
|
|
|
fs.validDepth(valid)
|
|
|
|
|
|
|
|
|
|
test "Test invalid key (path) depth":
|
|
|
|
|
let
|
|
|
|
|
fs = FSDatastore.new(root = basePathAbs, depth = 3).tryGet()
|
|
|
|
|
key = Key.init("/a/b/c/d").tryGet()
|
|
|
|
|
|
|
|
|
|
check:
|
|
|
|
|
(await fs.put(key, bytes)).isErr
|
|
|
|
|
(await fs.get(key)).isErr
|
|
|
|
|
(await fs.delete(key)).isErr
|
2022-12-02 16:25:44 -06:00
|
|
|
(await fs.has(key)).isErr
|
2022-09-19 15:54:19 -06:00
|
|
|
|
|
|
|
|
test "Test valid key (path) depth":
|
|
|
|
|
let
|
|
|
|
|
fs = FSDatastore.new(root = basePathAbs, depth = 3).tryGet()
|
|
|
|
|
key = Key.init("/a/b/c").tryGet()
|
|
|
|
|
|
|
|
|
|
check:
|
|
|
|
|
(await fs.put(key, bytes)).isOk
|
|
|
|
|
(await fs.get(key)).isOk
|
|
|
|
|
(await fs.delete(key)).isOk
|
2022-12-02 16:25:44 -06:00
|
|
|
(await fs.has(key)).isOk
|
2022-09-20 20:18:33 -04:00
|
|
|
|
2022-09-29 13:56:24 -04:00
|
|
|
test "Test key cannot write outside of root":
|
|
|
|
|
let
|
|
|
|
|
fs = FSDatastore.new(root = basePathAbs, depth = 3).tryGet()
|
|
|
|
|
key = Key.init("/a/../../c").tryGet()
|
|
|
|
|
|
|
|
|
|
check:
|
|
|
|
|
(await fs.put(key, bytes)).isErr
|
|
|
|
|
(await fs.get(key)).isErr
|
|
|
|
|
(await fs.delete(key)).isErr
|
2022-12-02 16:25:44 -06:00
|
|
|
(await fs.has(key)).isErr
|
2022-09-29 13:56:24 -04:00
|
|
|
|
|
|
|
|
test "Test key cannot convert to invalid path":
|
|
|
|
|
let
|
|
|
|
|
fs = FSDatastore.new(root = basePathAbs).tryGet()
|
|
|
|
|
|
|
|
|
|
for c in invalidFilenameChars:
|
|
|
|
|
if c == ':': continue
|
|
|
|
|
if c == '/': continue
|
|
|
|
|
|
|
|
|
|
let
|
|
|
|
|
key = Key.init("/" & c).tryGet()
|
|
|
|
|
|
|
|
|
|
check:
|
|
|
|
|
(await fs.put(key, bytes)).isErr
|
|
|
|
|
(await fs.get(key)).isErr
|
|
|
|
|
(await fs.delete(key)).isErr
|
2022-12-02 16:25:44 -06:00
|
|
|
(await fs.has(key)).isErr
|
2022-09-29 13:56:24 -04:00
|
|
|
|
2022-09-20 20:18:33 -04:00
|
|
|
suite "Test Query":
|
|
|
|
|
let
|
2022-11-22 15:23:23 -06:00
|
|
|
path = currentSourcePath() # get this file's name
|
2022-09-20 20:18:33 -04:00
|
|
|
basePath = "tests_data"
|
|
|
|
|
basePathAbs = path.parentDir / basePath
|
|
|
|
|
|
|
|
|
|
var
|
|
|
|
|
ds: FSDatastore
|
|
|
|
|
|
|
|
|
|
setup:
|
|
|
|
|
removeDir(basePathAbs)
|
|
|
|
|
require(not dirExists(basePathAbs))
|
|
|
|
|
createDir(basePathAbs)
|
|
|
|
|
|
|
|
|
|
ds = FSDatastore.new(root = basePathAbs, depth = 5).tryGet()
|
|
|
|
|
|
|
|
|
|
teardown:
|
|
|
|
|
|
|
|
|
|
removeDir(basePathAbs)
|
|
|
|
|
require(not dirExists(basePathAbs))
|
|
|
|
|
|
2024-05-08 14:01:00 +02:00
|
|
|
teardownAll:
|
|
|
|
|
removeDir(basePathAbs)
|
|
|
|
|
require(not dirExists(basePathAbs))
|
|
|
|
|
|
2024-05-14 11:05:58 +02:00
|
|
|
queryTests(ds,
|
|
|
|
|
testLimitsAndOffsets = false,
|
|
|
|
|
testSortOrder = false
|
|
|
|
|
)
|
2024-05-08 14:01:00 +02:00
|
|
|
typedDsQueryTests(ds)
|