Skip to content

Commit 0c10011

Browse files
committed
Compare query strings based on set of components
1 parent 4d0b838 commit 0c10011

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

aws/sdk/integration-tests/ec2/tests/paginators.rs

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55

66
use aws_runtime::user_agent::test_util::assert_ua_contains_metric_values;
77
use aws_sdk_ec2::{config::Credentials, config::Region, types::InstanceType, Client, Config};
8-
use aws_smithy_runtime::client::http::test_util::{
9-
capture_request, ReplayEvent, StaticReplayClient,
10-
};
8+
use aws_smithy_runtime::client::http::test_util::capture_request;
119
use aws_smithy_runtime_api::client::http::HttpClient;
1210
use aws_smithy_types::body::SdkBody;
11+
use std::collections::HashSet;
1312

1413
fn stub_config(http_client: impl HttpClient + 'static) -> Config {
1514
Config::builder()
@@ -19,28 +18,28 @@ fn stub_config(http_client: impl HttpClient + 'static) -> Config {
1918
.build()
2019
}
2120

21+
fn validate_query_string(expected: &str, actual: &str) {
22+
let expected = expected.split('&').collect::<HashSet<&str>>();
23+
let actual = actual.split('&').collect::<HashSet<&str>>();
24+
assert_eq!(expected, actual);
25+
}
26+
2227
/// See https://github.com/awslabs/aws-sdk-rust/issues/391
2328
///
2429
/// EC2 replies with `<nextToken></nextToken>` which our XML parser parses as empty string and not "none"
2530
#[tokio::test]
2631
async fn paginators_handle_empty_tokens() {
27-
let request= "Action=DescribeSpotPriceHistory&Version=2016-11-15&AvailabilityZone=eu-north-1a&InstanceType.1=g5.48xlarge&ProductDescription.1=Linux%2FUNIX";
2832
let response = r#"<?xml version="1.0" encoding="UTF-8"?>
2933
<DescribeSpotPriceHistoryResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/">
3034
<requestId>edf3e86c-4baf-47c1-9228-9a5ea09542e8</requestId>
3135
<spotPriceHistorySet/>
3236
<nextToken></nextToken>
3337
</DescribeSpotPriceHistoryResponse>"#;
34-
let http_client = StaticReplayClient::new(vec![ReplayEvent::new(
35-
http::Request::builder()
36-
.uri("https://ec2.us-east-1.amazonaws.com/")
37-
.body(request.into())
38-
.unwrap(),
39-
http::Response::builder()
40-
.status(200)
41-
.body(SdkBody::from(response))
42-
.unwrap(),
43-
)]);
38+
let response = http::Response::builder()
39+
.status(200)
40+
.body(SdkBody::from(response))
41+
.unwrap();
42+
let (http_client, captured_request) = capture_request(Some(response));
4443
let client = Client::from_conf(stub_config(http_client.clone()));
4544
let instance_type = InstanceType::from("g5.48xlarge");
4645
let mut paginator = client
@@ -53,30 +52,27 @@ async fn paginators_handle_empty_tokens() {
5352
.send();
5453
let first_item = paginator.try_next().await.expect("success");
5554
assert_eq!(first_item, None);
56-
http_client.assert_requests_match(&[]);
55+
let req = captured_request.expect_request();
56+
let actual_body = std::str::from_utf8(req.body().bytes().unwrap()).unwrap();
57+
let expected_body = "Action=DescribeSpotPriceHistory&Version=2016-11-15&AvailabilityZone=eu-north-1a&InstanceType.1=g5.48xlarge&ProductDescription.1=Linux%2FUNIX";
58+
validate_query_string(expected_body, actual_body);
5759
}
5860

5961
/// See https://github.com/awslabs/aws-sdk-rust/issues/405
6062
///
6163
/// EC2 can also reply with the token truly unset which will be interpreted as `None`
6264
#[tokio::test]
6365
async fn paginators_handle_unset_tokens() {
64-
let request= "Action=DescribeSpotPriceHistory&Version=2016-11-15&AvailabilityZone=eu-north-1a&InstanceType.1=g5.48xlarge&ProductDescription.1=Linux%2FUNIX";
6566
let response = r#"<?xml version="1.0" encoding="UTF-8"?>
6667
<DescribeSpotPriceHistoryResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/">
6768
<requestId>edf3e86c-4baf-47c1-9228-9a5ea09542e8</requestId>
6869
<spotPriceHistorySet/>
6970
</DescribeSpotPriceHistoryResponse>"#;
70-
let http_client = StaticReplayClient::new(vec![ReplayEvent::new(
71-
http::Request::builder()
72-
.uri("https://ec2.us-east-1.amazonaws.com/")
73-
.body(request.into())
74-
.unwrap(),
75-
http::Response::builder()
76-
.status(200)
77-
.body(SdkBody::from(response))
78-
.unwrap(),
79-
)]);
71+
let response = http::Response::builder()
72+
.status(200)
73+
.body(SdkBody::from(response))
74+
.unwrap();
75+
let (http_client, captured_request) = capture_request(Some(response));
8076
let client = Client::from_conf(stub_config(http_client.clone()));
8177
let instance_type = InstanceType::from("g5.48xlarge");
8278
let mut paginator = client
@@ -89,7 +85,10 @@ async fn paginators_handle_unset_tokens() {
8985
.send();
9086
let first_item = paginator.try_next().await.expect("success");
9187
assert_eq!(first_item, None);
92-
http_client.assert_requests_match(&[]);
88+
let req = captured_request.expect_request();
89+
let actual_body = std::str::from_utf8(req.body().bytes().unwrap()).unwrap();
90+
let expected_body = "Action=DescribeSpotPriceHistory&Version=2016-11-15&AvailabilityZone=eu-north-1a&InstanceType.1=g5.48xlarge&ProductDescription.1=Linux%2FUNIX";
91+
validate_query_string(expected_body, actual_body);
9392
}
9493

9594
#[tokio::test]

0 commit comments

Comments
 (0)