[wip] experiments with when..is re: #210

This commit is contained in:
Michael Bradley, Jr 2022-08-15 10:56:50 -05:00
parent 1dc1b97950
commit 7f076e1451
No known key found for this signature in database
GPG Key ID: 9FCA591DA4CE7D0D
4 changed files with 57 additions and 17 deletions

View File

@ -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

View File

@ -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)

View File

@ -1,5 +1,5 @@
import ./stores/testcachestore
import ./stores/testfsstore
# import ./stores/testcachestore
# import ./stores/testfsstore
import ./stores/testsqlitestore
{.warning[UnusedImport]: off.}

View File

@ -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.}