Skip to main content

fakecloud_ec2/
lib.rs

1//! Amazon EC2 implementation for FakeCloud.
2//!
3//! EC2 speaks the `ec2Query` protocol (form-encoded requests, flattened-XML
4//! responses — see [`fakecloud_aws::ec2query`]). This crate is built out across
5//! many batches toward full operation parity; the foundation here provides the
6//! service scaffold, shared `Filter`/pagination infrastructure, the resource
7//! tagging subsystem, and the region/AZ/account-attribute describe primitives
8//! that almost every SDK client calls implicitly.
9
10pub mod cfn_provision;
11pub mod defaults;
12pub mod runtime;
13pub mod service;
14pub mod service_helpers;
15pub mod state;
16
17pub use runtime::Ec2Runtime;
18pub use service::Ec2Service;
19pub use state::{Ec2Snapshot, Ec2State, SharedEc2State, EC2_SNAPSHOT_SCHEMA_VERSION};
20
21/// Shared test helpers for the in-crate handler unit tests.
22#[cfg(test)]
23pub(crate) mod test_support {
24    use fakecloud_core::service::{AwsRequest, AwsResponse, AwsServiceError};
25
26    /// Extract the error from a handler result (AwsResponse is not `Debug`, so
27    /// `unwrap_err` cannot be used directly).
28    pub(crate) fn err_of(r: Result<AwsResponse, AwsServiceError>) -> AwsServiceError {
29        match r {
30            Ok(_) => panic!("expected an error, got Ok"),
31            Err(e) => e,
32        }
33    }
34
35    /// Build a minimal query-protocol [`AwsRequest`] for handler unit tests.
36    pub(crate) fn ec2_request(action: &str, query: &[(&str, &str)]) -> AwsRequest {
37        AwsRequest {
38            service: "ec2".into(),
39            action: action.into(),
40            region: "us-east-1".into(),
41            account_id: "000000000000".into(),
42            request_id: "rid".into(),
43            headers: http::HeaderMap::new(),
44            query_params: query
45                .iter()
46                .map(|(k, v)| (k.to_string(), v.to_string()))
47                .collect(),
48            body: bytes::Bytes::new(),
49            body_stream: parking_lot::Mutex::new(None),
50            path_segments: Vec::new(),
51            raw_path: "/".into(),
52            raw_query: String::new(),
53            method: http::Method::POST,
54            is_query_protocol: true,
55            access_key_id: None,
56            principal: None,
57        }
58    }
59}