macro_rules! mock_client { ($aws_crate: ident, $rules: expr) => { ... }; ($aws_crate: ident, $rule_mode: expr, $rules: expr) => { ... }; }
Expand description
mock_client!
macro produces a Client configured with a number of Rules and appropriate test default configuration.
§Examples
Create a client that uses a mock failure and then a success:
ⓘ
use aws_sdk_s3::operation::get_object::{GetObjectOutput, GetObjectError};
use aws_sdk_s3::types::error::NoSuchKey;
use aws_sdk_s3::Client;
use aws_smithy_types::byte_stream::ByteStream;
use aws_smithy_mocks_experimental::{mock_client, mock, RuleMode};
let get_object_happy_path = mock!(Client::get_object)
.match_requests(|req|req.bucket() == Some("test-bucket") && req.key() == Some("test-key"))
.then_output(||GetObjectOutput::builder().body(ByteStream::from_static(b"12345-abcde")).build());
let get_object_error_path = mock!(Client::get_object)
.then_error(||GetObjectError::NoSuchKey(NoSuchKey::builder().build()));
let client = mock_client!(aws_sdk_s3, RuleMode::Sequential, &[&get_object_error_path, &get_object_happy_path]);