mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-04 22:43:12 +00:00
[wip] experiments with when..is re: #210
This commit is contained in:
parent
1dc1b97950
commit
7f076e1451
@ -27,6 +27,11 @@ export blockstore, sqlite_datastore
|
||||
logScope:
|
||||
topics = "codex sqlitestore"
|
||||
|
||||
import ../errors
|
||||
export errors
|
||||
type
|
||||
BlockNotFoundError* = object of CodexError
|
||||
|
||||
type
|
||||
ListBlocksQueryResponse = string
|
||||
|
||||
@ -101,7 +106,7 @@ method getBlock*(
|
||||
return failure error
|
||||
|
||||
without data =? dataOpt:
|
||||
return failure "Block not in database"
|
||||
return failure (ref BlockNotFoundError)(msg: "Block not in database")
|
||||
|
||||
without blk =? Block.new(cid, data), error:
|
||||
trace "Unable to construct block from data", cid, error = error.msg
|
||||
|
||||
@ -144,7 +144,42 @@ proc runSuite(cache: bool) =
|
||||
getRes.get == newBlock
|
||||
|
||||
test "fail getBlock":
|
||||
check: (await store.getBlock(newBlock.cid)).isErr
|
||||
let
|
||||
getRes = await store.getBlock(newBlock.cid)
|
||||
|
||||
check: getRes.isErr
|
||||
|
||||
# PASS!
|
||||
when getRes.error is (ref CatchableError):
|
||||
echo "PASS: when getRes.error is (ref CatchableError)"
|
||||
check: getRes.error.msg == "Block not in database"
|
||||
echo "NOTE: I am sure msg string is what we expect: " & getRes.error.msg
|
||||
else:
|
||||
check: false
|
||||
|
||||
# FAIL!
|
||||
when getRes.error is CatchableError:
|
||||
check: true
|
||||
else:
|
||||
echo "FAIL: when getRes.error is CatchableError"
|
||||
check: false
|
||||
echo "NOTE: this is only sanity check for ref vs. non-ref, but msg string is still what we expect: " & getRes.error.msg
|
||||
|
||||
# FAIL!
|
||||
when getRes.error is (ref CodexError):
|
||||
check: true
|
||||
else:
|
||||
echo "FAIL: when getRes.error is (ref CodexError)"
|
||||
check: false
|
||||
echo "NOTE: msg string is still what we expect: " & getRes.error.msg
|
||||
|
||||
# FAIL!
|
||||
when getRes.error is (ref BlockNotFoundError):
|
||||
check: true
|
||||
else:
|
||||
echo "FAIL: when getRes.error is (ref BlockNotFoundError)"
|
||||
check: false
|
||||
echo "NOTE: msg string is still what we expect: " & getRes.error.msg
|
||||
|
||||
test "hasBlock":
|
||||
let
|
||||
@ -213,5 +248,5 @@ proc runSuite(cache: bool) =
|
||||
delRes.isOk
|
||||
not (await newBlock.cid in store)
|
||||
|
||||
runSuite(cache = true)
|
||||
# runSuite(cache = true)
|
||||
runSuite(cache = false)
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import ./stores/testcachestore
|
||||
import ./stores/testfsstore
|
||||
# import ./stores/testcachestore
|
||||
# import ./stores/testfsstore
|
||||
import ./stores/testsqlitestore
|
||||
|
||||
{.warning[UnusedImport]: off.}
|
||||
|
||||
@ -1,17 +1,17 @@
|
||||
import ./codex/teststores
|
||||
import ./codex/testblockexchange
|
||||
import ./codex/teststorageproofs
|
||||
import ./codex/testasyncheapqueue
|
||||
import ./codex/testchunking
|
||||
import ./codex/testmanifest
|
||||
import ./codex/testnode
|
||||
import ./codex/teststorestream
|
||||
import ./codex/testpurchasing
|
||||
import ./codex/testsales
|
||||
import ./codex/testerasure
|
||||
import ./codex/testproving
|
||||
# import ./codex/testblockexchange
|
||||
# import ./codex/teststorageproofs
|
||||
# import ./codex/testasyncheapqueue
|
||||
# import ./codex/testchunking
|
||||
# import ./codex/testmanifest
|
||||
# import ./codex/testnode
|
||||
# import ./codex/teststorestream
|
||||
# import ./codex/testpurchasing
|
||||
# import ./codex/testsales
|
||||
# import ./codex/testerasure
|
||||
# import ./codex/testproving
|
||||
|
||||
# to check that everything compiles
|
||||
import ../codex
|
||||
# import ../codex
|
||||
|
||||
{.warning[UnusedImport]: off.}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user