Server Test

Server Test

rev. 9f5fb9826a6af51ebfb3736d0a778b00ec7b08b3

Files changed:

tmp-codegen-diff/codegen-server-test/simple/rust-server-codegen/src/operation.rs

@@ -1,1 +32,31 @@
    1      1   
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
    2         -
    3      2   
const CONTENT_TYPE_OPERATION: ::mime::Mime = ::mime::APPLICATION_JSON;
    4      3   
::pin_project_lite::pin_project! {
    5      4   
    /// A [`Future`](std::future::Future) aggregating the body bytes of a [`Request`] and constructing the
    6      5   
    /// [`OperationInput`](crate::input::OperationInput) using modelled bindings.
    7      6   
    pub struct OperationInputFuture {
    8      7   
        inner: std::pin::Pin<Box<dyn std::future::Future<Output = Result<crate::input::OperationInput, ::aws_smithy_http_server::protocol::rest_json_1::runtime_error::RuntimeError>> + Send>>
    9      8   
    }
   10      9   
}
   11     10   
   12     11   
impl std::future::Future for OperationInputFuture {

tmp-codegen-diff/codegen-server-test/unique_items/rust-server-codegen/Cargo.toml

@@ -1,1 +51,54 @@
   11     11   
[dependencies.aws-smithy-http]
   12     12   
path = "/home/build/workspace/smithy-rs/rust-runtime/aws-smithy-http"
   13     13   
[dependencies.aws-smithy-http-server]
   14     14   
path = "/home/build/workspace/smithy-rs/rust-runtime/aws-smithy-http-server"
   15     15   
[dependencies.aws-smithy-json]
   16     16   
path = "/home/build/workspace/smithy-rs/rust-runtime/aws-smithy-json"
   17     17   
[dependencies.aws-smithy-runtime-api]
   18     18   
path = "/home/build/workspace/smithy-rs/rust-runtime/aws-smithy-runtime-api"
   19     19   
[dependencies.aws-smithy-types]
   20     20   
path = "/home/build/workspace/smithy-rs/rust-runtime/aws-smithy-types"
   21         -
[dependencies.bytes]
   22         -
version = "1.4.0"
   23     21   
[dependencies.futures-util]
   24     22   
version = "0.3"
   25     23   
[dependencies.http]
   26     24   
version = "0.2.9"
   27     25   
[dependencies.hyper]
   28     26   
version = "0.14.26"
   29     27   
[dependencies.mime]
   30     28   
version = "0.3"
   31     29   
[dependencies.pin-project-lite]
   32     30   
version = "0.2"
   33     31   
[dependencies.tower]
   34     32   
version = "0.4"
   35     33   
[dependencies.tracing]
   36     34   
version = "0.1"
   37     35   
[dev-dependencies.aws-smithy-protocol-test]
   38     36   
path = "/home/build/workspace/smithy-rs/rust-runtime/aws-smithy-protocol-test"
          37  +
[dev-dependencies.bytes]
          38  +
version = "1.4.0"
   39     39   
[dev-dependencies.hyper]
   40     40   
version = "0.14.12"
   41     41   
[dev-dependencies.pretty_assertions]
   42     42   
version = "1.3.0"
   43     43   
[dev-dependencies.tokio]
   44     44   
version = "1.23.1"
   45     45   
features = ["macros", "test-util", "rt-multi-thread"]
          46  +
[dev-dependencies.tracing-test]
          47  +
version = "0.2.5"
          48  +
features = ["no-env-filter"]
   46     49   
[features]
   47     50   
aws-lambda = ["aws-smithy-http-server/aws-lambda"]
   48     51   
rt-tokio = ["aws-smithy-types/rt-tokio"]
   49     52   
default = ["aws-lambda", "rt-tokio"]
   50     53   
   51     54   

tmp-codegen-diff/codegen-server-test/unique_items/rust-server-codegen/src/operation.rs

@@ -1,1 +131,31 @@
    1      1   
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
    2         -
#[cfg(test)]
    3         -
#[allow(unreachable_code, unused_variables)]
    4         -
mod server_malformed_unique_items_test {
    5         -
    /// When the list has duplicated items, the response should be a 400
    6         -
    /// ValidationException.
    7         -
    /// Test ID: RestJsonMalformedUniqueItemsDuplicateItems
    8         -
    #[::tokio::test]
    9         -
    async fn rest_json_malformed_unique_items_duplicate_items_malformed_request() {
   10         -
        {
   11         -
            #[allow(unused_mut)]
   12         -
            let mut http_request = http::Request::builder()
   13         -
                .uri("/MalformedUniqueItems")
   14         -
                .method("POST")
   15         -
                .header("content-type", "application/json")
   16         -
                .body(::aws_smithy_http_server::body::Body::from(
   17         -
                    ::bytes::Bytes::from_static(
   18         -
                        "{ \"set\" : [\"a\", \"a\", \"b\", \"c\"] }".as_bytes(),
   19         -
                    ),
   20         -
                ))
   21         -
                .unwrap();
   22         -
            #[allow(unused_mut)]
   23         -
            let (sender, mut receiver) = ::tokio::sync::mpsc::channel(1);
   24         -
            let config = crate::service::UniqueItemsServiceConfig::builder().build();
   25         -
            let service = crate::service::UniqueItemsService::builder::<::hyper::body::Body, _, _, _>(config)
   26         -
                            .malformed_unique_items(move |input: crate::input::MalformedUniqueItemsInput| {
   27         -
                                let sender = sender.clone();
   28         -
                                async move {
   29         -
                                    let result = { panic!("request should have been rejected, but we accepted it; we parsed operation input `{:?}`", &input) as Result<crate::output::MalformedUniqueItemsOutput, crate::error::MalformedUniqueItemsError> };
   30         -
                                    sender.send(()).await.expect("receiver dropped early");
   31         -
                                    result
   32         -
                                }
   33         -
                            })
   34         -
                            .build_unchecked();
   35         -
            let http_response = ::tower::ServiceExt::oneshot(service, http_request)
   36         -
                .await
   37         -
                .expect("unable to make an HTTP request");
   38         -
            ::pretty_assertions::assert_eq!(
   39         -
                http::StatusCode::from_u16(400).expect("invalid expected HTTP status code"),
   40         -
                http_response.status()
   41         -
            );
   42         -
            let expected_headers = [("x-amzn-errortype", "ValidationException")];
   43         -
            ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_headers(
   44         -
                http_response.headers(),
   45         -
                expected_headers,
   46         -
            ));
   47         -
            let body = ::hyper::body::to_bytes(http_response.into_body())
   48         -
                .await
   49         -
                .expect("unable to extract body to bytes");
   50         -
            ::aws_smithy_protocol_test::assert_ok(
   51         -
            ::aws_smithy_protocol_test::validate_body(&body, "{ \"message\" : \"1 validation error detected. Value with repeated values at indices [0, 1] at '/set' failed to satisfy constraint: Member must have unique values\",\n  \"fieldList\" : [{\"message\": \"Value with repeated values at indices [0, 1] at '/set' failed to satisfy constraint: Member must have unique values\", \"path\": \"/set\"}]}", ::aws_smithy_protocol_test::MediaType::from("application/json"))
   52         -
            );
   53         -
        }
   54         -
    }
   55         -
    /// When the list has duplicated blobs, the response should be a 400
   56         -
    /// ValidationException.
   57         -
    /// Test ID: RestJsonMalformedUniqueItemsDuplicateBlobs
   58         -
    #[::tokio::test]
   59         -
    async fn rest_json_malformed_unique_items_duplicate_blobs_malformed_request() {
   60         -
        {
   61         -
            #[allow(unused_mut)]
   62         -
                        let mut http_request = http::Request::builder()
   63         -
                            .uri("/MalformedUniqueItems")
   64         -
                            .method("POST")
   65         -
            .header("content-type", "application/json")
   66         -
            .body(::aws_smithy_http_server::body::Body::from(::bytes::Bytes::from_static("{ \"complexSet\" : [{\"foo\": true, \"blob\": \"YmxvYg==\"}, {\"foo\": true, \"blob\": \"b3RoZXJibG9i\"}, {\"foo\": true, \"blob\": \"YmxvYg==\"}] }".as_bytes()))).unwrap();
   67         -
            #[allow(unused_mut)]
   68         -
            let (sender, mut receiver) = ::tokio::sync::mpsc::channel(1);
   69         -
            let config = crate::service::UniqueItemsServiceConfig::builder().build();
   70         -
            let service = crate::service::UniqueItemsService::builder::<::hyper::body::Body, _, _, _>(config)
   71         -
                            .malformed_unique_items(move |input: crate::input::MalformedUniqueItemsInput| {
   72         -
                                let sender = sender.clone();
   73         -
                                async move {
   74         -
                                    let result = { panic!("request should have been rejected, but we accepted it; we parsed operation input `{:?}`", &input) as Result<crate::output::MalformedUniqueItemsOutput, crate::error::MalformedUniqueItemsError> };
   75         -
                                    sender.send(()).await.expect("receiver dropped early");
   76         -
                                    result
   77         -
                                }
   78         -
                            })
   79         -
                            .build_unchecked();
   80         -
            let http_response = ::tower::ServiceExt::oneshot(service, http_request)
   81         -
                .await
   82         -
                .expect("unable to make an HTTP request");
   83         -
            ::pretty_assertions::assert_eq!(
   84         -
                http::StatusCode::from_u16(400).expect("invalid expected HTTP status code"),
   85         -
                http_response.status()
   86         -
            );
   87         -
            let expected_headers = [("x-amzn-errortype", "ValidationException")];
   88         -
            ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_headers(
   89         -
                http_response.headers(),
   90         -
                expected_headers,
   91         -
            ));
   92         -
            let body = ::hyper::body::to_bytes(http_response.into_body())
   93         -
                .await
   94         -
                .expect("unable to extract body to bytes");
   95         -
            ::aws_smithy_protocol_test::assert_ok(
   96         -
            ::aws_smithy_protocol_test::validate_body(&body, "{ \"message\" : \"1 validation error detected. Value with repeated values at indices [0, 2] at '/complexSet' failed to satisfy constraint: Member must have unique values\",\n  \"fieldList\" : [{\"message\": \"Value with repeated values at indices [0, 2] at '/complexSet' failed to satisfy constraint: Member must have unique values\", \"path\": \"/complexSet\"}]}", ::aws_smithy_protocol_test::MediaType::from("application/json"))
   97         -
            );
   98         -
        }
   99         -
    }
  100         -
}
  101         -
  102      2   
const CONTENT_TYPE_MALFORMEDUNIQUEITEMS: ::mime::Mime = ::mime::APPLICATION_JSON;
  103      3   
::pin_project_lite::pin_project! {
  104      4   
    /// A [`Future`](std::future::Future) aggregating the body bytes of a [`Request`] and constructing the
  105      5   
    /// [`MalformedUniqueItemsInput`](crate::input::MalformedUniqueItemsInput) using modelled bindings.
  106      6   
    pub struct MalformedUniqueItemsInputFuture {
  107      7   
        inner: std::pin::Pin<Box<dyn std::future::Future<Output = Result<crate::input::MalformedUniqueItemsInput, ::aws_smithy_http_server::protocol::rest_json_1::runtime_error::RuntimeError>> + Send>>
  108      8   
    }
  109      9   
}
  110     10   
  111     11   
impl std::future::Future for MalformedUniqueItemsInputFuture {
@@ -171,71 +0,203 @@
  191     91   
                response.extensions_mut().insert(::aws_smithy_http_server::extension::ModeledErrorExtension::new(self.name()));
  192     92   
                response
  193     93   
            },
  194     94   
            Err(e) => {
  195     95   
                ::tracing::error!(error = %e, "failed to serialize response");
  196     96   
                ::aws_smithy_http_server::response::IntoResponse::<::aws_smithy_http_server::protocol::rest_json_1::RestJson1>::into_response(::aws_smithy_http_server::protocol::rest_json_1::runtime_error::RuntimeError::from(e))
  197     97   
            }
  198     98   
        }
  199     99   
    }
  200    100   
}
         101  +
         102  +
#[allow(unreachable_code, unused_variables)]
         103  +
#[cfg(test)]
         104  +
mod malformed_unique_items_test {
         105  +
         106  +
    /// When the list has duplicated items, the response should be a 400
         107  +
    /// ValidationException.
         108  +
    /// Test ID: RestJsonMalformedUniqueItemsDuplicateItems
         109  +
    #[::tokio::test]
         110  +
    #[::tracing_test::traced_test]
         111  +
    async fn rest_json_malformed_unique_items_duplicate_items_malformed_request() {
         112  +
        {
         113  +
            #[allow(unused_mut)]
         114  +
            let mut http_request = http::Request::builder()
         115  +
                .uri("/MalformedUniqueItems")
         116  +
                .method("POST")
         117  +
                .header("content-type", "application/json")
         118  +
                .body(::aws_smithy_http_server::body::Body::from(
         119  +
                    ::bytes::Bytes::from_static(
         120  +
                        "{ \"set\" : [\"a\", \"a\", \"b\", \"c\"] }".as_bytes(),
         121  +
                    ),
         122  +
                ))
         123  +
                .unwrap();
         124  +
            #[allow(unused_mut)]
         125  +
            let (sender, mut receiver) = ::tokio::sync::mpsc::channel(1);
         126  +
            let config = crate::service::UniqueItemsServiceConfig::builder().build();
         127  +
            let service = crate::service::UniqueItemsService::builder::<::hyper::body::Body, _, _, _>(config)
         128  +
                            .malformed_unique_items(move |input: crate::input::MalformedUniqueItemsInput| {
         129  +
                                let sender = sender.clone();
         130  +
                                async move {
         131  +
                                    let result = { panic!("request should have been rejected, but we accepted it; we parsed operation input `{:?}`", &input) as Result<crate::output::MalformedUniqueItemsOutput, crate::error::MalformedUniqueItemsError> };
         132  +
                                    sender.send(()).await.expect("receiver dropped early");
         133  +
                                    result
         134  +
                                }
         135  +
                            })
         136  +
                            .build_unchecked();
         137  +
            let http_response = ::tower::ServiceExt::oneshot(service, http_request)
         138  +
                .await
         139  +
                .expect("unable to make an HTTP request");
         140  +
            ::pretty_assertions::assert_eq!(
         141  +
                http::StatusCode::from_u16(400).expect("invalid expected HTTP status code"),
         142  +
                http_response.status()
         143  +
            );
         144  +
            let expected_headers = [("x-amzn-errortype", "ValidationException")];
         145  +
            ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_headers(
         146  +
                http_response.headers(),
         147  +
                expected_headers,
         148  +
            ));
         149  +
            let body = ::hyper::body::to_bytes(http_response.into_body())
         150  +
                .await
         151  +
                .expect("unable to extract body to bytes");
         152  +
            ::aws_smithy_protocol_test::assert_ok(
         153  +
            ::aws_smithy_protocol_test::validate_body(&body, "{ \"message\" : \"1 validation error detected. Value with repeated values at indices [0, 1] at '/set' failed to satisfy constraint: Member must have unique values\",\n  \"fieldList\" : [{\"message\": \"Value with repeated values at indices [0, 1] at '/set' failed to satisfy constraint: Member must have unique values\", \"path\": \"/set\"}]}", ::aws_smithy_protocol_test::MediaType::from("application/json"))
         154  +
            );
         155  +
        }
         156  +
    }
         157  +
    /// When the list has duplicated blobs, the response should be a 400
         158  +
    /// ValidationException.
         159  +
    /// Test ID: RestJsonMalformedUniqueItemsDuplicateBlobs
         160  +
    #[::tokio::test]
         161  +
    #[::tracing_test::traced_test]
         162  +
    async fn rest_json_malformed_unique_items_duplicate_blobs_malformed_request() {
         163  +
        {
         164  +
            #[allow(unused_mut)]
         165  +
                        let mut http_request = http::Request::builder()
         166  +
                            .uri("/MalformedUniqueItems")
         167  +
                            .method("POST")
         168  +
            .header("content-type", "application/json")
         169  +
            .body(::aws_smithy_http_server::body::Body::from(::bytes::Bytes::from_static("{ \"complexSet\" : [{\"foo\": true, \"blob\": \"YmxvYg==\"}, {\"foo\": true, \"blob\": \"b3RoZXJibG9i\"}, {\"foo\": true, \"blob\": \"YmxvYg==\"}] }".as_bytes()))).unwrap();
         170  +
            #[allow(unused_mut)]
         171  +
            let (sender, mut receiver) = ::tokio::sync::mpsc::channel(1);
         172  +
            let config = crate::service::UniqueItemsServiceConfig::builder().build();
         173  +
            let service = crate::service::UniqueItemsService::builder::<::hyper::body::Body, _, _, _>(config)
         174  +
                            .malformed_unique_items(move |input: crate::input::MalformedUniqueItemsInput| {
         175  +
                                let sender = sender.clone();
         176  +
                                async move {
         177  +
                                    let result = { panic!("request should have been rejected, but we accepted it; we parsed operation input `{:?}`", &input) as Result<crate::output::MalformedUniqueItemsOutput, crate::error::MalformedUniqueItemsError> };
         178  +
                                    sender.send(()).await.expect("receiver dropped early");
         179  +
                                    result
         180  +
                                }
         181  +
                            })
         182  +
                            .build_unchecked();
         183  +
            let http_response = ::tower::ServiceExt::oneshot(service, http_request)
         184  +
                .await
         185  +
                .expect("unable to make an HTTP request");
         186  +
            ::pretty_assertions::assert_eq!(
         187  +
                http::StatusCode::from_u16(400).expect("invalid expected HTTP status code"),
         188  +
                http_response.status()
         189  +
            );
         190  +
            let expected_headers = [("x-amzn-errortype", "ValidationException")];
         191  +
            ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_headers(
         192  +
                http_response.headers(),
         193  +
                expected_headers,
         194  +
            ));
         195  +
            let body = ::hyper::body::to_bytes(http_response.into_body())
         196  +
                .await
         197  +
                .expect("unable to extract body to bytes");
         198  +
            ::aws_smithy_protocol_test::assert_ok(
         199  +
            ::aws_smithy_protocol_test::validate_body(&body, "{ \"message\" : \"1 validation error detected. Value with repeated values at indices [0, 2] at '/complexSet' failed to satisfy constraint: Member must have unique values\",\n  \"fieldList\" : [{\"message\": \"Value with repeated values at indices [0, 2] at '/complexSet' failed to satisfy constraint: Member must have unique values\", \"path\": \"/complexSet\"}]}", ::aws_smithy_protocol_test::MediaType::from("application/json"))
         200  +
            );
         201  +
        }
         202  +
    }
         203  +
}