mirror of
https://github.com/codex-storage/nim-json-rpc.git
synced 2025-02-23 16:38:22 +00:00
Re-added malformed json error
This commit is contained in:
parent
9945228bf0
commit
a79351cbd7
@ -19,12 +19,6 @@ proc testMissingRpc: Future[Response] {.async.} =
|
||||
var fut = client.call("phantomRpc", %[])
|
||||
result = await fut
|
||||
|
||||
proc testMalformed: Future[Response] {.async.} =
|
||||
let malformedJson = "{field: 2, \"field: 3}"
|
||||
var fut = client.rawCall("rpc", malformedJson)
|
||||
await fut or sleepAsync(10000)
|
||||
if fut.finished: result = fut.read()
|
||||
|
||||
proc testInvalidJsonVer: Future[Response] {.async.} =
|
||||
let json =
|
||||
$ %{"jsonrpc": %"3.99", "method": %"rpc", "params": %[],
|
||||
@ -32,24 +26,29 @@ proc testInvalidJsonVer: Future[Response] {.async.} =
|
||||
var fut = client.rawCall("rpc", json)
|
||||
result = await fut
|
||||
|
||||
proc testMalformed: Future[Response] {.async.} =
|
||||
let malformedJson = "{field: 2, \"field: 3}"
|
||||
var fut = client.rawCall("rpc", malformedJson)
|
||||
await fut or sleepAsync(1000)
|
||||
if fut.finished: result = fut.read()
|
||||
else: result = (true, %"Timeout")
|
||||
|
||||
suite "RPC Errors":
|
||||
# Note: We don't expect a exceptions for most of the tests,
|
||||
# because the server should respond with the error in json
|
||||
test "Missing RPC":
|
||||
let res = waitFor testMissingRpc()
|
||||
echo res
|
||||
check res.error == true and
|
||||
res.result["message"] == %"Method not found" and
|
||||
res.result["data"] == %"phantomRpc is not a registered method."
|
||||
|
||||
test "Incorrect json version":
|
||||
# Note: We don't expect an exception here, because the server should
|
||||
# respond with the correct json version
|
||||
let res = waitFor testInvalidJsonVer()
|
||||
check res.error == true and res.result["message"] == %"JSON 2.0 required"
|
||||
|
||||
# TODO: Missing ID causes client await to not return next call
|
||||
# For now we can use curl for this test
|
||||
#[test "Malformed json":
|
||||
expect ValueError:
|
||||
let res = waitFor testMalformed()
|
||||
echo res
|
||||
]#
|
||||
test "Malformed json":
|
||||
# TODO: We time out here because the server won't be able to
|
||||
# find an id to return to us, so we cannot complete the future.
|
||||
let res = waitFor testMalformed()
|
||||
check res.error == true and res.result == %"Timeout"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user