From 3c55168b72c022b618822c7993b7692f583506db Mon Sep 17 00:00:00 2001 From: hozan23 Date: Sun, 30 Jun 2024 20:03:02 +0200 Subject: jsonrpc: remove redundant macro codes in the main crate and clean up internal proc macros --- jsonrpc/tests/impl_rpc_service.rs | 30 ------------------------------ jsonrpc/tests/rpc_pubsub_impl.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 30 deletions(-) delete mode 100644 jsonrpc/tests/impl_rpc_service.rs create mode 100644 jsonrpc/tests/rpc_pubsub_impl.rs (limited to 'jsonrpc/tests') diff --git a/jsonrpc/tests/impl_rpc_service.rs b/jsonrpc/tests/impl_rpc_service.rs deleted file mode 100644 index 52c5c31..0000000 --- a/jsonrpc/tests/impl_rpc_service.rs +++ /dev/null @@ -1,30 +0,0 @@ -use karyon_jsonrpc::{impl_rpc_service, RPCError, RPCService}; -use serde_json::Value; - -#[test] -fn service() { - struct Foo {} - - impl Foo { - async fn foo(&self, params: Value) -> Result { - Ok(params) - } - } - - impl_rpc_service!(Foo, foo); - - let f = Foo {}; - - assert!(f.get_method("foo").is_some()); - assert!(f.get_method("bar").is_none()); - - let params = serde_json::json!("params"); - - smol::block_on(async { - let foo_method = f.get_method("foo").expect("Get method foo"); - assert_eq!( - foo_method(params.clone()).await.expect("Call foo method"), - params - ); - }); -} diff --git a/jsonrpc/tests/rpc_pubsub_impl.rs b/jsonrpc/tests/rpc_pubsub_impl.rs new file mode 100644 index 0000000..9d2eb57 --- /dev/null +++ b/jsonrpc/tests/rpc_pubsub_impl.rs @@ -0,0 +1,30 @@ +use std::sync::Arc; + +use karyon_jsonrpc::{rpc_pubsub_impl, Channel, PubSubRPCService, RPCError}; +use serde_json::Value; + +#[test] +fn rpc_pubsub_impl_service() { + struct Foo {} + + #[rpc_pubsub_impl] + impl Foo { + async fn foo( + &self, + _channel: Arc, + _method: String, + params: Value, + ) -> Result { + Ok(params) + } + } + + let f = Arc::new(Foo {}); + + assert!(f.get_pubsub_method("foo").is_some()); + assert!(f.get_pubsub_method("bar").is_none()); + + let _params = serde_json::json!("params"); + + // TODO add more tests here +} -- cgit v1.2.3