pub struct MockProvider { /* private fields */ }Expand description
A queue-based mock provider for unit and integration tests.
Push responses with queue_response and
errors with queue_error. Each call to
generate or stream pops from the front of the respective queue.
Every call records its ChatParams for later assertion via
recorded_calls.
§Panics
generate panics if the response queue is empty.
stream panics if the stream queue is empty.
Implementations§
Source§impl MockProvider
impl MockProvider
Sourcepub fn new(meta: ProviderMetadata) -> Self
pub fn new(meta: ProviderMetadata) -> Self
Creates a new mock with the given metadata and empty queues.
Sourcepub fn queue_response(&self, response: ChatResponse) -> &Self
pub fn queue_response(&self, response: ChatResponse) -> &Self
Enqueues a successful response for the next generate call.
Sourcepub fn queue_error(&self, error: MockError) -> &Self
pub fn queue_error(&self, error: MockError) -> &Self
Enqueues an error for the next generate call.
Sourcepub fn queue_stream(&self, events: Vec<StreamEvent>) -> &Self
pub fn queue_stream(&self, events: Vec<StreamEvent>) -> &Self
Enqueues stream events for the next stream call.
Sourcepub fn queue_stream_error(&self, error: MockError) -> &Self
pub fn queue_stream_error(&self, error: MockError) -> &Self
Enqueues an error for the next stream call.
The error is returned from stream() itself (before any events
are yielded), simulating failures like authentication errors or
network issues that prevent the stream from starting.
Sourcepub fn recorded_calls(&self) -> Vec<ChatParams>
pub fn recorded_calls(&self) -> Vec<ChatParams>
Returns a clone of all ChatParams passed to generate or
stream, in call order.
Trait Implementations§
Source§impl Debug for MockProvider
impl Debug for MockProvider
Source§impl Provider for MockProvider
impl Provider for MockProvider
Source§async fn generate(&self, params: &ChatParams) -> Result<ChatResponse, LlmError>
async fn generate(&self, params: &ChatParams) -> Result<ChatResponse, LlmError>
Source§async fn stream(&self, params: &ChatParams) -> Result<ChatStream, LlmError>
async fn stream(&self, params: &ChatParams) -> Result<ChatStream, LlmError>
Source§fn metadata(&self) -> ProviderMetadata
fn metadata(&self) -> ProviderMetadata
Auto Trait Implementations§
impl !Freeze for MockProvider
impl RefUnwindSafe for MockProvider
impl Send for MockProvider
impl Sync for MockProvider
impl Unpin for MockProvider
impl UnwindSafe for MockProvider
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
Source§impl<T> DynProvider for Twhere
T: Provider,
impl<T> DynProvider for Twhere
T: Provider,
Source§fn generate_boxed<'a>(
&'a self,
params: &'a ChatParams,
) -> Pin<Box<dyn Future<Output = Result<ChatResponse, LlmError>> + Send + 'a>>
fn generate_boxed<'a>( &'a self, params: &'a ChatParams, ) -> Pin<Box<dyn Future<Output = Result<ChatResponse, LlmError>> + Send + 'a>>
Provider::generate.Source§fn stream_boxed<'a>(
&'a self,
params: &'a ChatParams,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<StreamEvent, LlmError>> + Send>>, LlmError>> + Send + 'a>>
fn stream_boxed<'a>( &'a self, params: &'a ChatParams, ) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<StreamEvent, LlmError>> + Send>>, LlmError>> + Send + 'a>>
Provider::stream.