mirror of
https://github.com/rustfs/rustfs.git
synced 2026-07-27 00:38:16 +00:00
fix(notify): normalize event time precision (#3725)
This commit is contained in:
@@ -133,6 +133,7 @@ pub struct Event {
|
||||
/// The AWS region where the event occurred
|
||||
pub aws_region: String,
|
||||
/// The time when the event occurred
|
||||
#[serde(serialize_with = "serialize_event_time_millis")]
|
||||
pub event_time: DateTime<Utc>,
|
||||
/// The name of the event
|
||||
pub event_name: EventName,
|
||||
@@ -309,6 +310,13 @@ impl Event {
|
||||
}
|
||||
}
|
||||
|
||||
fn serialize_event_time_millis<S>(value: &DateTime<Utc>, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
serializer.serialize_str(&value.to_rfc3339_opts(SecondsFormat::Millis, true))
|
||||
}
|
||||
|
||||
fn initialize_response_elements(elements: &mut HashMap<String, String>, keys: &[&str]) {
|
||||
for key in keys {
|
||||
elements.entry(key.to_string()).or_default();
|
||||
@@ -528,6 +536,15 @@ mod tests {
|
||||
assert_eq!(glacier.restore_event_data.lifecycle_restoration_expiry_time, "2023-11-14T22:13:20.000Z");
|
||||
assert_eq!(glacier.restore_event_data.lifecycle_restore_storage_class, "GLACIER");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn event_time_serializes_with_millisecond_precision() {
|
||||
let mut event = Event::new_test_event("bucket", "key", EventName::ObjectCreatedPut);
|
||||
event.event_time = DateTime::<Utc>::from_timestamp(1_711_423_698, 870_816_000).expect("timestamp should be valid");
|
||||
|
||||
let json = serde_json::to_value(&event).expect("event should serialize");
|
||||
assert_eq!(json.get("eventTime").and_then(|value| value.as_str()), Some("2024-03-26T03:28:18.870Z"));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user