Skip to content

Commit

Permalink
meta data serde test
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-k-cameron committed Apr 21, 2023
1 parent 10d9c9a commit 31780e7
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
6 changes: 4 additions & 2 deletions aws/rust-runtime/aws-credential-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
48 changes: 48 additions & 0 deletions rust-runtime/aws-smithy-types/src/error/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down Expand Up @@ -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()
);
}
}
7 changes: 7 additions & 0 deletions rust-runtime/aws-smithy-types/test_data/error_meta_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"code": "code",
"message": "message",
"extras": {
"hello": "world"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"code": null,
"message": null,
"extras": null
}

0 comments on commit 31780e7

Please sign in to comment.