mirror of
https://github.com/codex-storage/nim-json-rpc.git
synced 2025-02-24 00:48:12 +00:00
Test errors WIP
This commit is contained in:
parent
49afd6ee76
commit
6b619472f3
@ -3,7 +3,7 @@
|
|||||||
allow unchecked and unformatted calls.
|
allow unchecked and unformatted calls.
|
||||||
]#
|
]#
|
||||||
|
|
||||||
import unittest, debugclient, ../rpcstreamservers
|
import unittest, debugclient, ../rpcserver
|
||||||
import strformat, chronicles
|
import strformat, chronicles
|
||||||
|
|
||||||
var server = newRpcStreamServer("localhost", 8547.Port)
|
var server = newRpcStreamServer("localhost", 8547.Port)
|
||||||
@ -15,6 +15,10 @@ waitFor client.connect("localhost", Port(8547))
|
|||||||
server.rpc("rpc") do(a: int, b: int):
|
server.rpc("rpc") do(a: int, b: int):
|
||||||
result = %(&"a: {a}, b: {b}")
|
result = %(&"a: {a}, b: {b}")
|
||||||
|
|
||||||
|
server.rpc("makeError"):
|
||||||
|
if true:
|
||||||
|
raise newException(ValueError, "Test")
|
||||||
|
|
||||||
proc testMissingRpc: Future[Response] {.async.} =
|
proc testMissingRpc: Future[Response] {.async.} =
|
||||||
var fut = client.call("phantomRpc", %[])
|
var fut = client.call("phantomRpc", %[])
|
||||||
result = await fut
|
result = await fut
|
||||||
@ -33,18 +37,28 @@ proc testMalformed: Future[Response] {.async.} =
|
|||||||
if fut.finished: result = fut.read()
|
if fut.finished: result = fut.read()
|
||||||
else: result = (true, %"Timeout")
|
else: result = (true, %"Timeout")
|
||||||
|
|
||||||
|
proc testRaise: Future[Response] {.async.} =
|
||||||
|
var fut = client.call("rpcMakeError", %[])
|
||||||
|
result = await fut
|
||||||
|
|
||||||
suite "RPC Errors":
|
suite "RPC Errors":
|
||||||
# Note: We don't expect a exceptions for most of the tests,
|
# Note: We don't expect a exceptions for most of the tests,
|
||||||
# because the server should respond with the error in json
|
# because the server should respond with the error in json
|
||||||
test "Missing RPC":
|
test "Missing RPC":
|
||||||
let res = waitFor testMissingRpc()
|
expect ValueError:
|
||||||
check res.error == true and
|
let res = waitFor testMissingRpc()
|
||||||
res.result["message"] == %"Method not found" and
|
check res.error == true and
|
||||||
res.result["data"] == %"phantomRpc is not a registered method."
|
res.result["message"] == %"Method not found" and
|
||||||
|
res.result["data"] == %"phantomRpc is not a registered method."
|
||||||
|
|
||||||
test "Incorrect json version":
|
test "Incorrect json version":
|
||||||
let res = waitFor testInvalidJsonVer()
|
expect ValueError:
|
||||||
check res.error == true and res.result["message"] == %"JSON 2.0 required"
|
let res = waitFor testInvalidJsonVer()
|
||||||
|
check res.error == true and res.result["message"] == %"JSON 2.0 required"
|
||||||
|
|
||||||
|
test "Raising exceptions":
|
||||||
|
expect ValueError:
|
||||||
|
let res = waitFor testRaise()
|
||||||
|
|
||||||
test "Malformed json":
|
test "Malformed json":
|
||||||
# TODO: We time out here because the server won't be able to
|
# TODO: We time out here because the server won't be able to
|
||||||
|
Loading…
x
Reference in New Issue
Block a user