[pbs-devel] [PATCH proxmox 2/2] s3-client: add regression tests for http date header parsing
Christian Ebner
c.ebner at proxmox.com
Fri Aug 8 13:41:17 CEST 2025
Basic tests to check that the header is parsed as expected if present
and ignored if not.
Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
proxmox-s3-client/src/response_reader.rs | 24 ++++++++++++++++++++++++
proxmox-s3-client/src/timestamps.rs | 2 +-
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/proxmox-s3-client/src/response_reader.rs b/proxmox-s3-client/src/response_reader.rs
index f200e15a..c00c7bd4 100644
--- a/proxmox-s3-client/src/response_reader.rs
+++ b/proxmox-s3-client/src/response_reader.rs
@@ -632,3 +632,27 @@ fn parse_list_buckets_response_test() {
]
);
}
+
+#[test]
+fn test_optional_date_header_parsing() {
+ let mut header_map = HeaderMap::new();
+
+ let expected_date = "Wed, 12 Oct 2009 17:50:00 GMT";
+ header_map.insert(header::DATE, expected_date.parse().unwrap());
+ let parsed_date = ResponseReader::parse_optional_date_header(&header_map).unwrap();
+ assert!(parsed_date.is_some());
+ assert_eq!(
+ parsed_date.unwrap(),
+ HttpDate::from_str(expected_date).unwrap(),
+ );
+
+ header_map.clear();
+ let invalid_date_format = "2019-11-10";
+ header_map.insert(header::DATE, invalid_date_format.parse().unwrap());
+ assert!(ResponseReader::parse_optional_date_header(&header_map).is_err());
+
+ header_map.clear();
+ assert!(ResponseReader::parse_optional_date_header(&header_map)
+ .unwrap()
+ .is_none());
+}
diff --git a/proxmox-s3-client/src/timestamps.rs b/proxmox-s3-client/src/timestamps.rs
index 661e1fdf..74397593 100644
--- a/proxmox-s3-client/src/timestamps.rs
+++ b/proxmox-s3-client/src/timestamps.rs
@@ -28,7 +28,7 @@ serde_plain::derive_deserialize_from_fromstr!(LastModifiedTimestamp, "last modif
/// https://datatracker.ietf.org/doc/html/rfc2616#section-3.3
/// https://datatracker.ietf.org/doc/html/rfc1123#section-5.2.14
/// https://datatracker.ietf.org/doc/html/rfc822#section-5
-#[derive(Debug)]
+#[derive(Debug, PartialEq)]
pub struct HttpDate {
_epoch: i64,
}
--
2.47.2
More information about the pbs-devel
mailing list