2 个稳定版本
10.1.0 | 2019 年 3 月 25 日 |
---|---|
10.0.1 | 2019 年 3 月 25 日 |
#767 in 测试
93KB
2.5K SLoC
一个用于测试基于 susy-jsonrpc-core 项目的实用程序包。
use susy_jsonrpc_derive::rpc;
use susy_jsonrpc_test as test;
use susy_jsonrpc_core::{Result, Error, IoHandler};
#[rpc]
pub trait Test {
#[rpc(name = "rpc_some_method")]
fn some_method(&self, _: u64) -> Result<u64>;
}
struct Dummy;
impl Test for Dummy {
fn some_method(&self, x: u64) -> Result<u64> {
Ok(x * 2)
}
}
fn main() {
// Initialize new instance of test environment
let rpc = test::Rpc::new(Dummy.to_delegate());
// make a request and verify the response as a pretty-printed string
assert_eq!(rpc.request("rpc_some_method", &[5]), r#"10"#);
// You can also test RPC created without macros:
let rpc = {
let mut io = IoHandler::new();
io.add_method("rpc_test_method", |_| {
Err(Error::internal_error())
});
test::Rpc::from(io)
};
assert_eq!(rpc.request("rpc_test_method", &()), r#"{
"code": -32603,
"message": "Internal error"
}"#);
}
依赖项
~2–3MB
~60K SLoC