mirror of https://github.com/Trivernis/vented.git
Move event_tests to event submodule
Signed-off-by: trivernis <trivernis@protonmail.com>pull/1/head
parent
ae39bc50bd
commit
d5d8875e79
@ -0,0 +1,39 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use crate::event::Event;
|
||||
|
||||
#[derive(PartialEq, Serialize, Deserialize, Clone, Debug)]
|
||||
struct SimplePayload {
|
||||
string: String,
|
||||
number: u32,
|
||||
float: f32
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_serializes_events() {
|
||||
let payload = SimplePayload {
|
||||
string: "test".to_string(),
|
||||
number: 7,
|
||||
float: 2.1
|
||||
};
|
||||
let payload_raw = rmp_serde::to_vec(&payload).unwrap();
|
||||
let event = Event::with_payload("test".to_string(), payload);
|
||||
let event_bytes = event.to_bytes().unwrap();
|
||||
|
||||
assert_eq!(event_bytes[0..2], [0x00, 0x04]);
|
||||
assert_eq!(event_bytes[6..14], payload_raw.len().to_be_bytes());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_deserializes_events() {
|
||||
let payload = SimplePayload {
|
||||
string: "test".to_string(),
|
||||
number: 7,
|
||||
float: 2.1
|
||||
};
|
||||
let event = Event::with_payload("test".to_string(), payload.clone());
|
||||
let event_bytes = event.to_bytes().unwrap();
|
||||
|
||||
let deserialized_event = Event::<SimplePayload>::from_bytes(&mut event_bytes.as_slice()).unwrap();
|
||||
assert_eq!(deserialized_event.name, "test".to_string());
|
||||
assert_eq!(deserialized_event.payload, payload);
|
||||
}
|
Loading…
Reference in New Issue