get rid of null datastore

This commit is contained in:
Dmitriy Ryajov 2022-09-19 17:12:52 -06:00
parent 2680789884
commit 60e0ea5573
No known key found for this signature in database
GPG Key ID: DA8C680CE7C657A4
2 changed files with 0 additions and 90 deletions

View File

@ -1,47 +0,0 @@
import pkg/chronos
import pkg/questionable
import pkg/questionable/results
import pkg/upraises
import ./datastore
export datastore
push: {.upraises: [].}
type
NullDatastore* = ref object of Datastore
proc new*(T: type NullDatastore): T =
T()
method contains*(
self: NullDatastore,
key: Key): Future[?!bool] {.async, locks: "unknown".} =
return success false
method delete*(
self: NullDatastore,
key: Key): Future[?!void] {.async, locks: "unknown".} =
return success()
method get*(
self: NullDatastore,
key: Key): Future[?!(?seq[byte])] {.async, locks: "unknown".} =
return success seq[byte].none
method put*(
self: NullDatastore,
key: Key,
data: seq[byte]): Future[?!void] {.async, locks: "unknown".} =
return success()
iterator query*(
self: NullDatastore,
query: Query): Future[QueryResponse] =
discard

View File

@ -1,43 +0,0 @@
import std/options
import pkg/asynctest/unittest2
import pkg/chronos
import pkg/stew/results
import pkg/datastore/nullds
suite "NullDatastore":
let
key = Key.init("a").get
ds = NullDatastore.new()
test "new":
check: not ds.isNil
test "put":
check: (await ds.put(key, @[1.byte])).isOk
test "delete":
check: (await ds.delete(key)).isOk
test "contains":
check:
(await ds.contains(key)).isOk
(await ds.contains(key)).get == false
test "get":
check:
(await ds.get(key)).isOk
(await ds.get(key)).get.isNone
test "query":
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