Skip to content

Commit 8d51b94

Browse files
authored
[Rust]: Add more SoS tags to test samples (#5624)
Add further SoS tags for rust testing samples
1 parent 20ed184 commit 8d51b94

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

rust_dev_preview/examples/testing/src/replay.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
* SPDX-License-Identifier: Apache-2.0.
44
*/
55

6+
// snippet-start:[testing.rust.replay-uses]
67
use aws_sdk_s3 as s3;
8+
// snippet-end:[testing.rust.replay-uses]
79

810
#[allow(dead_code)]
911
// snippet-start:[testing.rust.replay]
@@ -42,6 +44,7 @@ pub async fn determine_prefix_file_size(
4244

4345
#[allow(dead_code)]
4446
// snippet-start:[testing.rust.replay-tests]
47+
// snippet-start:[testing.rust.replay-make-credentials]
4548
fn make_s3_test_credentials() -> s3::config::Credentials {
4649
s3::config::Credentials::new(
4750
"ATESTCLIENT",
@@ -51,9 +54,12 @@ fn make_s3_test_credentials() -> s3::config::Credentials {
5154
"",
5255
)
5356
}
57+
// snippet-end:[testing.rust.replay-make-credentials]
5458

59+
// snippet-start:[testing.rust.replay-test-module]
5560
#[cfg(test)]
5661
mod test {
62+
// snippet-start:[testing.rust.replay-test-single]
5763
use super::*;
5864
use aws_sdk_s3 as s3;
5965
use aws_smithy_runtime::client::http::test_util::{ReplayEvent, StaticReplayClient};
@@ -90,9 +96,12 @@ mod test {
9096
assert_eq!(7, size);
9197
replay_client.assert_requests_match(&[]);
9298
}
99+
// snippet-end:[testing.rust.replay-test-single]
93100

101+
// snippet-start:[testing.rust.replay-test-multiple]
94102
#[tokio::test]
95103
async fn test_multiple_pages() {
104+
// snippet-start:[testing.rust.replay-create-replay]
96105
let page_1 = ReplayEvent::new(
97106
http::Request::builder()
98107
.method("GET")
@@ -116,22 +125,29 @@ mod test {
116125
.unwrap(),
117126
);
118127
let replay_client = StaticReplayClient::new(vec![page_1, page_2]);
128+
// snippet-end:[testing.rust.replay-create-replay]
129+
// snippet-start:[testing.rust.replay-create-client]
119130
let client: s3::Client = s3::Client::from_conf(
120131
s3::Config::builder()
121132
.credentials_provider(make_s3_test_credentials())
122133
.region(s3::config::Region::new("us-east-1"))
123134
.http_client(replay_client.clone())
124135
.build(),
125136
);
137+
// snippet-end:[testing.rust.replay-create-client]
126138

127139
// Run the code we want to test with it
140+
// snippet-start:[testing.rust.replay-test-and-verify]
128141
let size = determine_prefix_file_size(client, "test-bucket", "test-prefix")
129142
.await
130143
.unwrap();
131144

132145
assert_eq!(19, size);
133146

134147
replay_client.assert_requests_match(&[]);
148+
// snippet-end:[testing.rust.replay-test-and-verify]
135149
}
136-
// snippet-end:[testing.rust.replay-tests]
150+
// snippet-end:[testing.rust.replay-test-multiple]
137151
}
152+
// snippet-end:[testing.rust.replay-tests]
153+
// snippet-end:[testing.rust.replay-test-module]

rust_dev_preview/examples/testing/src/wrapper.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,23 @@
33
* SPDX-License-Identifier: Apache-2.0.
44
*/
55

6+
// snippet-start:[testing.rust.wrapper]
7+
// snippet-start:[testing.rust.wrapper-uses]
68
use aws_sdk_s3 as s3;
79
#[allow(unused_imports)]
810
use mockall::automock;
911

1012
use s3::operation::list_objects_v2::{ListObjectsV2Error, ListObjectsV2Output};
13+
// snippet-end:[testing.rust.wrapper-uses]
1114

12-
// snippet-start:[testing.rust.wrapper]
15+
// snippet-start:[testing.rust.wrapper-which-impl]
1316
#[cfg(test)]
1417
pub use MockS3Impl as S3;
1518
#[cfg(not(test))]
1619
pub use S3Impl as S3;
20+
// snippet-end:[testing.rust.wrapper-which-impl]
1721

22+
// snippet-start:[testing.rust.wrapper-impl]
1823
#[allow(dead_code)]
1924
pub struct S3Impl {
2025
inner: s3::Client,
@@ -43,7 +48,9 @@ impl S3Impl {
4348
.await
4449
}
4550
}
51+
// snippet-end:[testing.rust.wrapper-impl]
4652

53+
// snippet-start:[testing.rust.wrapper-func]
4754
#[allow(dead_code)]
4855
pub async fn determine_prefix_file_size(
4956
// 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(
7279
}
7380
Ok(total_size_bytes)
7481
}
82+
// snippet-end:[testing.rust.wrapper-func]
7583
// snippet-end:[testing.rust.wrapper]
7684

85+
// snippet-start:[testing.rust.wrapper-test-mod]
7786
#[cfg(test)]
7887
mod test {
88+
// snippet-start:[testing.rust.wrapper-tests]
7989
use super::*;
8090
use mockall::predicate::eq;
8191

82-
// snippet-start:[testing.rust.wrapper-tests]
92+
// snippet-start:[testing.rust.wrapper-test-single]
8393
#[tokio::test]
8494
async fn test_single_page() {
8595
let mut mock = MockS3Impl::default();
@@ -103,7 +113,9 @@ mod test {
103113
// Verify we got the correct total size back
104114
assert_eq!(7, size);
105115
}
116+
// snippet-end:[testing.rust.wrapper-test-single]
106117

118+
// snippet-start:[testing.rust.wrapper-test-multiple]
107119
#[tokio::test]
108120
async fn test_multiple_pages() {
109121
// Create the Mock instance with two pages of objects now
@@ -143,5 +155,7 @@ mod test {
143155

144156
assert_eq!(19, size);
145157
}
158+
// snippet-end:[testing.rust.wrapper-test-multiple]
146159
// snippet-end:[testing.rust.wrapper-tests]
147160
}
161+
// snippet-end:[testing.rust.wrapper-test-mod]

0 commit comments

Comments
 (0)