From e9ba8f5e02436d05c1cf20f05a356b521a4027df Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Wed, 12 Jan 2022 08:25:33 +0100 Subject: [PATCH] Add unit test for XML serialization and discover an issue --- src/api/s3_copy.rs | 27 +++++++++++++++++++++++++-- src/api/s3_xml.rs | 10 ++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/api/s3_copy.rs b/src/api/s3_copy.rs index b539424c..aef536ce 100644 --- a/src/api/s3_copy.rs +++ b/src/api/s3_copy.rs @@ -540,8 +540,31 @@ impl CopyPreconditionHeaders { pub struct CopyPartResult { #[serde(serialize_with = "xmlns_tag")] pub xmlns: (), - #[serde(rename = "ETag")] - pub etag: s3_xml::Value, #[serde(rename = "LastModified")] pub last_modified: s3_xml::Value, + #[serde(rename = "ETag")] + pub etag: s3_xml::Value, +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::s3_xml::to_xml_with_header; + + #[test] + fn serialize_copy_part_result() -> Result<(), Error> { + // @FIXME: ETag should be quoted, but we can't add quotes + // because XML serializer replaces them by `"` + let expected_retval = r#"2011-04-11T20:34:56.000Z9b2cf535f27731c974343645a3985328"#; + let v = CopyPartResult { + xmlns: (), + last_modified: s3_xml::Value("2011-04-11T20:34:56.000Z".into()), + etag: s3_xml::Value("9b2cf535f27731c974343645a3985328".into()), + }; + println!("{}", to_xml_with_header(&v)?); + + assert_eq!(to_xml_with_header(&v)?, expected_retval); + + Ok(()) + } } diff --git a/src/api/s3_xml.rs b/src/api/s3_xml.rs index 9b5a0202..0747648e 100644 --- a/src/api/s3_xml.rs +++ b/src/api/s3_xml.rs @@ -374,6 +374,8 @@ mod tests { #[test] fn copy_object_result() -> Result<(), ApiError> { + // @FIXME: ETag should be quoted, but we can't add quotes + // because XML serializer replaces them by `"` let copy_result = CopyObjectResult { last_modified: Value(msec_to_rfc3339(0)), etag: Value("9b2cf535f27731c974343645a3985328".to_string()), @@ -412,6 +414,8 @@ mod tests { #[test] fn complete_multipart_upload_result() -> Result<(), ApiError> { + // @FIXME: ETag should be quoted, but we can't add quotes + // because XML serializer replaces them by `"` let result = CompleteMultipartUploadResult { xmlns: (), location: Some(Value("https://garage.tld/mybucket/a/plop".to_string())), @@ -434,6 +438,8 @@ mod tests { #[test] fn list_objects_v1_1() -> Result<(), ApiError> { + // @FIXME: ETag should be quoted, but we can't add quotes + // because XML serializer replaces them by `"` let result = ListBucketResult { xmlns: (), name: Value("example-bucket".to_string()), @@ -533,6 +539,8 @@ mod tests { #[test] fn list_objects_v2_1() -> Result<(), ApiError> { + // @FIXME: ETag should be quoted, but we can't add quotes + // because XML serializer replaces them by `"` let result = ListBucketResult { xmlns: (), name: Value("quotes".to_string()), @@ -579,6 +587,8 @@ mod tests { #[test] fn list_objects_v2_2() -> Result<(), ApiError> { + // @FIXME: ETag should be quoted, but we can't add quotes + // because XML serializer replaces them by `"` let result = ListBucketResult { xmlns: (), name: Value("bucket".to_string()),