1 1 | /*
|
2 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
3 3 | * SPDX-License-Identifier: Apache-2.0
|
4 4 | */
|
5 5 |
|
6 6 | use aws_sdk_s3::config::IdentityCache;
|
7 7 |
|
8 8 | use aws_sdk_s3::config::{
|
9 9 | retry::RetryConfig, timeout::TimeoutConfig, BehaviorVersion, Config, Credentials, Region,
|
10 10 | SharedAsyncSleep, Sleep, StalledStreamProtectionConfig,
|
11 11 | };
|
12 12 | use aws_sdk_s3::primitives::SdkBody;
|
13 13 | use aws_smithy_http_client::test_util::infallible_client_fn;
|
14 14 |
|
15 15 | use aws_sdk_s3::error::DisplayErrorContext;
|
16 16 | use aws_smithy_async::rt::sleep::AsyncSleep;
|
17 17 | use aws_smithy_http_client::test_util::capture_request;
|
18 18 | use aws_smithy_runtime::test_util::capture_test_logs::capture_test_logs;
|
19 19 | use std::time::Duration;
|
20 20 |
|
21 21 | // This will fail due to lack of a connector when constructing the SDK Config
|
22 22 | // If this test doesn't panic, you may have accidentally unified features, resulting in
|
23 23 | // the connector being enabled transitively
|
24 24 | #[tokio::test]
|
25 25 | #[should_panic(
|
26 - | expected = "Enable the `default-http-connector` crate feature or configure an HTTP client to fix this."
|
26 + | expected = "Enable the `default-https-client` crate feature or configure an HTTP client to fix this."
|
27 27 | )]
|
28 28 | async fn test_clients_from_sdk_config() {
|
29 29 | aws_config::load_defaults(BehaviorVersion::latest()).await;
|
30 30 | }
|
31 31 |
|
32 32 | // This will fail due to lack of a connector when constructing the service client
|
33 33 | #[tokio::test]
|
34 34 | async fn test_clients_from_service_config() {
|
35 35 | use aws_sdk_s3::config::Region;
|
36 36 |
|
37 37 | #[derive(Clone, Debug)]
|
38 38 | struct StubSleep;
|
39 39 | impl AsyncSleep for StubSleep {
|
40 40 | fn sleep(&self, _duration: Duration) -> Sleep {
|
41 41 | Sleep::new(Box::pin(async { /* no-op */ }))
|
42 42 | }
|
43 43 | }
|
44 44 |
|
45 45 | let config = Config::builder()
|
46 46 | .region(Region::new("us-east-1"))
|
47 47 | .credentials_provider(Credentials::for_tests())
|
48 48 | .sleep_impl(SharedAsyncSleep::new(StubSleep))
|
49 49 | .behavior_version(BehaviorVersion::latest())
|
50 50 | .build();
|
51 51 | // Creating the client shouldn't panic or error since presigning doesn't require a connector
|
52 52 | let client = aws_sdk_s3::Client::from_conf(config);
|
53 53 |
|
54 54 | let err = client
|
55 55 | .list_buckets()
|
56 56 | .send()
|
57 57 | .await
|
58 58 | .expect_err("it should fail to send a request because there is no HTTP client");
|
59 59 | let msg = format!("{}", DisplayErrorContext(err));
|
60 60 | assert!(
|
61 - | msg.contains("No HTTP client was available to send this request. Enable the `default-http-connector` crate feature or configure an HTTP client to fix this."),
|
62 - | "expected '{msg}' to contain 'No HTTP client was available to send this request. Enable the `default-http-connector` crate feature or set an HTTP client to fix this.'"
|
61 + | msg.contains("No HTTP client was available to send this request. Enable the `default-https-client` crate feature or configure an HTTP client to fix this."),
|
62 + | "expected '{msg}' to contain 'No HTTP client was available to send this request. Enable the `default-https-client` crate feature or set an HTTP client to fix this.'"
|
63 63 | );
|
64 64 | }
|
65 65 |
|
66 66 | #[tokio::test]
|
67 67 | #[should_panic(expected = "Invalid client configuration: A behavior major version must be set")]
|
68 68 | async fn test_missing_behavior_version() {
|
69 69 | use aws_sdk_s3::config::Region;
|
70 70 | let http_client =
|
71 71 | infallible_client_fn(|_req| http_1x::Response::builder().body(SdkBody::empty()).unwrap());
|
72 72 |
|
73 73 | let config = Config::builder()
|
74 74 | .region(Region::new("us-east-1"))
|
75 75 | .identity_cache(IdentityCache::no_cache())
|
76 76 | .credentials_provider(Credentials::for_tests())
|
77 77 | .http_client(http_client)
|
78 78 | .build();
|
79 79 | // This line panics
|
80 80 | let _client = aws_sdk_s3::Client::from_conf(config);
|
81 81 | }
|
82 82 |
|
83 83 | #[tokio::test]
|
84 84 | #[should_panic(
|
85 85 | expected = "Invalid client configuration: An async sleep implementation is required for retry to work."
|
86 86 | )]
|
87 87 | async fn test_missing_async_sleep_time_source_retries() {
|
88 88 | let _logs = capture_test_logs();
|
89 89 | let (http_client, _) = capture_request(None);
|
90 90 |
|
91 91 | // Configure retry and timeouts without providing a sleep impl
|
92 92 | let config = Config::builder()
|