pub use crate::params::Params;
use crate::{UUID4, UnixNanos};
#[derive(Debug, Clone)]
pub enum Message {
Command {
id: UUID4,
ts_init: UnixNanos,
},
Document {
id: UUID4,
ts_init: UnixNanos,
},
Event {
id: UUID4,
ts_init: UnixNanos,
ts_event: UnixNanos,
},
Request {
id: UUID4,
ts_init: UnixNanos,
},
Response {
id: UUID4,
ts_init: UnixNanos,
correlation_id: UUID4,
},
}
#[cfg(test)]
mod tests {
use rstest::rstest;
use super::*;
#[rstest]
fn test_message_command_construction() {
let msg = Message::Command {
id: UUID4::new(),
ts_init: UnixNanos::from(1_000),
};
assert!(matches!(msg, Message::Command { .. }));
}
#[rstest]
fn test_message_document_construction() {
let msg = Message::Document {
id: UUID4::new(),
ts_init: UnixNanos::from(2_000),
};
assert!(matches!(msg, Message::Document { .. }));
}
#[rstest]
fn test_message_event_construction() {
let msg = Message::Event {
id: UUID4::new(),
ts_init: UnixNanos::from(3_000),
ts_event: UnixNanos::from(2_500),
};
assert!(matches!(msg, Message::Event { .. }));
}
#[rstest]
fn test_message_request_construction() {
let msg = Message::Request {
id: UUID4::new(),
ts_init: UnixNanos::from(4_000),
};
assert!(matches!(msg, Message::Request { .. }));
}
#[rstest]
fn test_message_response_construction() {
let id = UUID4::new();
let correlation_id = UUID4::new();
let msg = Message::Response {
id,
ts_init: UnixNanos::from(5_000),
correlation_id,
};
assert!(matches!(msg, Message::Response { .. }));
}
#[rstest]
#[expect(clippy::redundant_clone, reason = "Clone is the behavior under test")]
fn test_message_clone() {
let msg = Message::Command {
id: UUID4::new(),
ts_init: UnixNanos::from(1_000),
};
let cloned = msg.clone();
assert!(matches!(cloned, Message::Command { .. }));
}
}