Re-added malformed json error

This commit is contained in:
coffeepots 2018-06-13 19:31:00 +01:00
parent 9945228bf0
commit a79351cbd7

View File

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