diff --git a/rust_dev_preview/examples/testing/src/replay.rs b/rust_dev_preview/examples/testing/src/replay.rs index f6ba900c85d..af78f6b6a89 100644 --- a/rust_dev_preview/examples/testing/src/replay.rs +++ b/rust_dev_preview/examples/testing/src/replay.rs @@ -3,7 +3,9 @@ * SPDX-License-Identifier: Apache-2.0. */ +// snippet-start:[testing.rust.replay-uses] use aws_sdk_s3 as s3; +// snippet-end:[testing.rust.replay-uses] #[allow(dead_code)] // snippet-start:[testing.rust.replay] @@ -42,6 +44,7 @@ pub async fn determine_prefix_file_size( #[allow(dead_code)] // snippet-start:[testing.rust.replay-tests] +// snippet-start:[testing.rust.replay-make-credentials] fn make_s3_test_credentials() -> s3::config::Credentials { s3::config::Credentials::new( "ATESTCLIENT", @@ -51,9 +54,12 @@ fn make_s3_test_credentials() -> s3::config::Credentials { "", ) } +// snippet-end:[testing.rust.replay-make-credentials] +// snippet-start:[testing.rust.replay-test-module] #[cfg(test)] mod test { + // snippet-start:[testing.rust.replay-test-single] use super::*; use aws_sdk_s3 as s3; use aws_smithy_runtime::client::http::test_util::{ReplayEvent, StaticReplayClient}; @@ -90,9 +96,12 @@ mod test { assert_eq!(7, size); replay_client.assert_requests_match(&[]); } + // snippet-end:[testing.rust.replay-test-single] + // snippet-start:[testing.rust.replay-test-multiple] #[tokio::test] async fn test_multiple_pages() { + // snippet-start:[testing.rust.replay-create-replay] let page_1 = ReplayEvent::new( http::Request::builder() .method("GET") @@ -116,6 +125,8 @@ mod test { .unwrap(), ); let replay_client = StaticReplayClient::new(vec![page_1, page_2]); + // snippet-end:[testing.rust.replay-create-replay] + // snippet-start:[testing.rust.replay-create-client] let client: s3::Client = s3::Client::from_conf( s3::Config::builder() .credentials_provider(make_s3_test_credentials()) @@ -123,8 +134,10 @@ mod test { .http_client(replay_client.clone()) .build(), ); + // snippet-end:[testing.rust.replay-create-client] // Run the code we want to test with it + // snippet-start:[testing.rust.replay-test-and-verify] let size = determine_prefix_file_size(client, "test-bucket", "test-prefix") .await .unwrap(); @@ -132,6 +145,9 @@ mod test { assert_eq!(19, size); replay_client.assert_requests_match(&[]); + // snippet-end:[testing.rust.replay-test-and-verify] } - // snippet-end:[testing.rust.replay-tests] + // snippet-end:[testing.rust.replay-test-multiple] } +// snippet-end:[testing.rust.replay-tests] +// snippet-end:[testing.rust.replay-test-module] diff --git a/rust_dev_preview/examples/testing/src/wrapper.rs b/rust_dev_preview/examples/testing/src/wrapper.rs index bfba83a212f..6dae10e9f6f 100644 --- a/rust_dev_preview/examples/testing/src/wrapper.rs +++ b/rust_dev_preview/examples/testing/src/wrapper.rs @@ -3,18 +3,23 @@ * SPDX-License-Identifier: Apache-2.0. */ +// snippet-start:[testing.rust.wrapper] +// snippet-start:[testing.rust.wrapper-uses] use aws_sdk_s3 as s3; #[allow(unused_imports)] use mockall::automock; use s3::operation::list_objects_v2::{ListObjectsV2Error, ListObjectsV2Output}; +// snippet-end:[testing.rust.wrapper-uses] -// snippet-start:[testing.rust.wrapper] +// snippet-start:[testing.rust.wrapper-which-impl] #[cfg(test)] pub use MockS3Impl as S3; #[cfg(not(test))] pub use S3Impl as S3; +// snippet-end:[testing.rust.wrapper-which-impl] +// snippet-start:[testing.rust.wrapper-impl] #[allow(dead_code)] pub struct S3Impl { inner: s3::Client, @@ -43,7 +48,9 @@ impl S3Impl { .await } } +// snippet-end:[testing.rust.wrapper-impl] +// snippet-start:[testing.rust.wrapper-func] #[allow(dead_code)] pub async fn determine_prefix_file_size( // Now we take a reference to our trait object instead of the S3 client @@ -72,14 +79,17 @@ pub async fn determine_prefix_file_size( } Ok(total_size_bytes) } +// snippet-end:[testing.rust.wrapper-func] // snippet-end:[testing.rust.wrapper] +// snippet-start:[testing.rust.wrapper-test-mod] #[cfg(test)] mod test { + // snippet-start:[testing.rust.wrapper-tests] use super::*; use mockall::predicate::eq; - // snippet-start:[testing.rust.wrapper-tests] + // snippet-start:[testing.rust.wrapper-test-single] #[tokio::test] async fn test_single_page() { let mut mock = MockS3Impl::default(); @@ -103,7 +113,9 @@ mod test { // Verify we got the correct total size back assert_eq!(7, size); } + // snippet-end:[testing.rust.wrapper-test-single] + // snippet-start:[testing.rust.wrapper-test-multiple] #[tokio::test] async fn test_multiple_pages() { // Create the Mock instance with two pages of objects now @@ -143,5 +155,7 @@ mod test { assert_eq!(19, size); } + // snippet-end:[testing.rust.wrapper-test-multiple] // snippet-end:[testing.rust.wrapper-tests] } +// snippet-end:[testing.rust.wrapper-test-mod]