pub struct MockClient { /* private fields */ }Expand description
A mock implementation of DaemonClient for testing.
This client allows you to configure predefined responses for RPC methods, and tracks all calls made to it for assertion purposes.
§Example
ⓘ
use crate::ipc::{MockClient, DaemonClient};
use serde_json::json;
let mut mock = MockClient::new();
mock.set_response("health", json!({ "status": "ok" }));
let result = mock.call("health", None).unwrap();
assert_eq!(result, json!({ "status": "ok" }));
// Verify the call was made
assert_eq!(mock.call_count("health"), 1);Implementations§
Source§impl MockClient
impl MockClient
Sourcepub fn new_strict() -> Self
pub fn new_strict() -> Self
Creates a new MockClient that returns an error for unconfigured methods.
Sourcepub fn set_response(&mut self, method: &str, response: Value)
pub fn set_response(&mut self, method: &str, response: Value)
Sets the response for a specific method.
Sourcepub fn set_default_response(&mut self, response: Value)
pub fn set_default_response(&mut self, response: Value)
Sets the default response for methods without configured responses.
Sourcepub fn call_count(&self, method: &str) -> usize
pub fn call_count(&self, method: &str) -> usize
Returns the number of times a specific method was called.
Sourcepub fn last_call(&self, method: &str) -> Option<(String, Option<Value>)>
pub fn last_call(&self, method: &str) -> Option<(String, Option<Value>)>
Returns the last call made to a specific method.
Sourcepub fn params_for(&self, method: &str) -> Vec<Option<Value>>
pub fn params_for(&self, method: &str) -> Vec<Option<Value>>
Returns all parameters passed to calls of a specific method.
Sourcepub fn clear_calls(&mut self)
pub fn clear_calls(&mut self)
Clears all recorded calls.
Sourcepub fn clear_responses(&mut self)
pub fn clear_responses(&mut self)
Clears all configured responses.
Trait Implementations§
Source§impl Clone for MockClient
impl Clone for MockClient
Source§fn clone(&self) -> MockClient
fn clone(&self) -> MockClient
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl DaemonClient for MockClient
impl DaemonClient for MockClient
Source§fn call(
&mut self,
method: &str,
params: Option<Value>,
) -> Result<Value, ClientError>
fn call( &mut self, method: &str, params: Option<Value>, ) -> Result<Value, ClientError>
Make an RPC call to the daemon.
Source§fn call_with_config(
&mut self,
method: &str,
params: Option<Value>,
_config: &DaemonClientConfig,
) -> Result<Value, ClientError>
fn call_with_config( &mut self, method: &str, params: Option<Value>, _config: &DaemonClientConfig, ) -> Result<Value, ClientError>
Make an RPC call with custom configuration.
Source§fn call_with_retry(
&mut self,
method: &str,
params: Option<Value>,
_max_retries: u32,
) -> Result<Value, ClientError>
fn call_with_retry( &mut self, method: &str, params: Option<Value>, _max_retries: u32, ) -> Result<Value, ClientError>
Make an RPC call with retry logic.
Auto Trait Implementations§
impl Freeze for MockClient
impl RefUnwindSafe for MockClient
impl Send for MockClient
impl Sync for MockClient
impl Unpin for MockClient
impl UnwindSafe for MockClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.