From 31780e79aa567a1cefd924869363e03db785641a Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Fri, 21 Apr 2023 08:39:10 +0000 Subject: [PATCH] meta data serde test --- .../aws-credential-types/Cargo.toml | 6 ++- .../aws-smithy-types/src/error/metadata.rs | 48 +++++++++++++++++++ .../test_data/error_meta_data.json | 7 +++ .../test_data/error_meta_data_empty.json | 5 ++ 4 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 rust-runtime/aws-smithy-types/test_data/error_meta_data.json create mode 100644 rust-runtime/aws-smithy-types/test_data/error_meta_data_empty.json diff --git a/aws/rust-runtime/aws-credential-types/Cargo.toml b/aws/rust-runtime/aws-credential-types/Cargo.toml index 66689bb8b1..2568a59fd1 100644 --- a/aws/rust-runtime/aws-credential-types/Cargo.toml +++ b/aws/rust-runtime/aws-credential-types/Cargo.toml @@ -6,8 +6,10 @@ description = "Types for AWS SDK credentials." edition = "2021" license = "Apache-2.0" repository = "https://github.com/awslabs/smithy-rs" -[package.metadata.cargo-udeps] -ignore = true +[package.metadata.cargo-udeps.ignore] +normal = ["regex"] +development = ["regex"] +build = ["regex"] [features] hardcoded-credentials = [] test-util = [] diff --git a/rust-runtime/aws-smithy-types/src/error/metadata.rs b/rust-runtime/aws-smithy-types/src/error/metadata.rs index 9036dc94ec..004b7ee81a 100644 --- a/rust-runtime/aws-smithy-types/src/error/metadata.rs +++ b/rust-runtime/aws-smithy-types/src/error/metadata.rs @@ -56,8 +56,23 @@ pub struct ErrorMetadata { } /// Builder for [`ErrorMetadata`]. +#[cfg_attr( + all(aws_sdk_unstable, feature = "serde-serialize"), + derive(serde::Serialize) +)] +#[cfg_attr( + all(aws_sdk_unstable, feature = "serde-deserialize"), + derive(serde::Deserialize) +)] #[derive(Debug, Default)] pub struct Builder { + #[cfg_attr( + any( + all(aws_sdk_unstable, feature = "serde-deserialize"), + all(aws_sdk_unstable, feature = "serde-serialize") + ), + serde(flatten) + )] inner: ErrorMetadata, } @@ -173,3 +188,36 @@ impl fmt::Display for ErrorMetadata { } impl std::error::Error for ErrorMetadata {} + +#[cfg(all( + test, + any( + all(aws_sdk_unstable, feature = "serde-deserialize"), + all(aws_sdk_unstable, feature = "serde-serialize") + ) +))] +mod test { + use super::*; + + #[test] + /// tests de/ser on ErrorMetaData. + fn test_error_meta_data() { + let mut data = Builder::default() + .code("code") + .message("message") + .custom("hello", "world"); + let ok = serde_json::to_string_pretty(&EMPTY_ERROR_METADATA).unwrap(); + assert_eq!( + &ok, + include_str!("../../test-data/error_meta_data_empty.json") + ); + assert_eq!( + serde_json::from_str(include_str!("../../test-data/error_meta_data.json")).unwrap(), + &data + ); + assert_eq!( + serde_json::from_str(include_str!("../../test-data/error_meta_data.json")).unwrap(), + data.build() + ); + } +} diff --git a/rust-runtime/aws-smithy-types/test_data/error_meta_data.json b/rust-runtime/aws-smithy-types/test_data/error_meta_data.json new file mode 100644 index 0000000000..db7067d86e --- /dev/null +++ b/rust-runtime/aws-smithy-types/test_data/error_meta_data.json @@ -0,0 +1,7 @@ +{ + "code": "code", + "message": "message", + "extras": { + "hello": "world" + } +} diff --git a/rust-runtime/aws-smithy-types/test_data/error_meta_data_empty.json b/rust-runtime/aws-smithy-types/test_data/error_meta_data_empty.json new file mode 100644 index 0000000000..41165f4a49 --- /dev/null +++ b/rust-runtime/aws-smithy-types/test_data/error_meta_data_empty.json @@ -0,0 +1,5 @@ +{ + "code": null, + "message": null, + "extras": null +}