generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 237
Expand file tree
/
Copy pathevent_stream.rs
More file actions
75 lines (64 loc) · 2.48 KB
/
event_stream.rs
File metadata and controls
75 lines (64 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
use aws_credential_types::Credentials;
use aws_sdk_cloudwatchlogs::{
config::Region, operation::start_live_tail::StartLiveTailOutput,
types::LiveTailSessionMetadata, Client, Config,
};
use aws_smithy_eventstream::test_util::validate_body;
use aws_smithy_runtime::client::http::test_util::dvr::ReplayingClient;
#[ignore] // TODO(re-enable this after success.json has been updated)
#[tokio::test]
async fn operation_with_rpc_bound_protocol() {
let (replayer, mut output) = start_request("us-west-2", "tests/success.json").await;
let mut session_metadata: Option<LiveTailSessionMetadata> = None;
while let Some(event) = output.response_stream.recv().await.unwrap() {
match event {
aws_sdk_cloudwatchlogs::types::StartLiveTailResponseStream::SessionStart(_) => {
// `SessionStart` event has been removed from `success.json` for security reason
}
aws_sdk_cloudwatchlogs::types::StartLiveTailResponseStream::SessionUpdate(
live_tail_session_update,
) => {
session_metadata = live_tail_session_update.session_metadata;
}
otherwise => panic!("received unexpected event type: {:?}", otherwise),
}
}
replayer
.validate(&["content-type", "content-length"], validate_success_body)
.await
.unwrap();
assert_eq!(
Some(LiveTailSessionMetadata::builder().sampled(false).build()),
session_metadata
);
}
async fn start_request(
region: &'static str,
events_json: &str,
) -> (ReplayingClient, StartLiveTailOutput) {
let replayer = ReplayingClient::from_file(events_json).unwrap();
let config = Config::builder()
.region(Region::from_static(region))
.http_client(replayer.clone())
.with_test_defaults()
.credentials_provider(Credentials::for_tests())
.build();
let client = Client::from_conf(config);
let output = client
.start_live_tail()
.set_log_group_identifiers(Some(vec![format!("arn:aws:logs:{region}:123456789123:log-group:/aws/codebuild/CodeBuildS3PublisherProject-aBCdEfGHIjkO")]))
.send()
.await
.unwrap();
(replayer, output)
}
fn validate_success_body(
expected_body: &[u8],
actual_body: &[u8],
) -> Result<(), Box<dyn std::error::Error>> {
validate_body(expected_body, actual_body, true)
}