nim-datastore/tests/datastore/testnullds.nim

44 lines
834 B
Nim
Raw Normal View History

2022-05-11 10:50:05 -05:00
import std/options
import pkg/asynctest/unittest2
import pkg/chronos
2022-05-11 10:50:05 -05:00
import pkg/stew/results
2022-09-19 15:54:19 -06:00
import pkg/datastore/nullds
2022-05-11 10:50:05 -05:00
suite "NullDatastore":
let
key = Key.init("a").get
ds = NullDatastore.new()
2022-05-11 10:50:05 -05:00
2022-09-19 15:54:19 -06:00
test "new":
2022-05-11 10:50:05 -05:00
check: not ds.isNil
2022-09-19 15:54:19 -06:00
test "put":
check: (await ds.put(key, @[1.byte])).isOk
2022-05-11 10:50:05 -05:00
2022-09-19 15:54:19 -06:00
test "delete":
check: (await ds.delete(key)).isOk
2022-05-11 10:50:05 -05:00
2022-09-19 15:54:19 -06:00
test "contains":
2022-05-11 10:50:05 -05:00
check:
(await ds.contains(key)).isOk
(await ds.contains(key)).get == false
2022-05-11 10:50:05 -05:00
2022-09-19 15:54:19 -06:00
test "get":
2022-05-11 10:50:05 -05:00
check:
(await ds.get(key)).isOk
(await ds.get(key)).get.isNone
2022-05-11 10:50:05 -05:00
2022-09-19 15:54:19 -06:00
test "query":
2022-07-15 15:28:42 -05:00
var
x = true
for n in ds.query(Query.init(key)):
# `iterator query` for NullDatastore never yields so the following lines
# are not run (else the test would hang)
x = false
discard (await n)
check: x