Move event_tests to event submodule

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/1/head
trivernis 4 years ago
parent ae39bc50bd
commit d5d8875e79
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -4,6 +4,9 @@ use byteorder::{BigEndian, ByteOrder, ReadBytesExt};
use std::io::Read;
use serde::de::DeserializeOwned;
#[cfg(test)]
mod tests;
#[derive(Clone, Serialize, Deserialize)]
pub struct EmptyPayload {}

@ -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);
}

@ -1,46 +1,2 @@
pub mod event;
pub mod result;
#[cfg(test)]
mod tests {
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…
Cancel
Save