Macro aws_smithy_mocks_experimental::mock
source · macro_rules! mock { ($operation: expr) => { ... }; }
Expand description
mock!
macro that produces a RuleBuilder
from a client invocation
See the examples
folder of this crate for fully worked examples.
§Examples
Mock and return a success response:
ⓘ
use aws_sdk_s3::operation::get_object::GetObjectOutput;
use aws_sdk_s3::Client;
use aws_smithy_types::byte_stream::ByteStream;
use aws_smithy_mocks_experimental::mock;
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());
Mock and return an error:
ⓘ
use aws_sdk_s3::operation::get_object::GetObjectError;
use aws_sdk_s3::types::error::NoSuchKey;
use aws_sdk_s3::Client;
use aws_smithy_mocks_experimental::mock;
let get_object_error_path = mock!(Client::get_object)
.then_error(||GetObjectError::NoSuchKey(NoSuchKey::builder().build()));