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 5096e7f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
34 changes: 34 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,22 @@ 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 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 5096e7f

Please sign in to comment.