forked from lavina/lavina
Test serialization
This commit is contained in:
parent
021bde729c
commit
9adc3e1154
|
@ -15,6 +15,8 @@ pub mod streamerror;
|
|||
pub mod tls;
|
||||
pub mod xml;
|
||||
|
||||
pub mod testkit;
|
||||
|
||||
// Implemented as a macro instead of a fn due to borrowck limitations
|
||||
macro_rules! skip_text {
|
||||
($reader: ident, $buf: ident) => {
|
||||
|
|
|
@ -330,6 +330,7 @@ impl ToXml for XmppHistoryMessage {
|
|||
mod test {
|
||||
use super::*;
|
||||
use crate::bind::{Name, Resource, Server};
|
||||
use crate::testkit::assemble_string_from_event_flow;
|
||||
|
||||
#[test]
|
||||
fn test_history_success_empty() {
|
||||
|
@ -439,17 +440,14 @@ mod test {
|
|||
body: "Hello World.".to_string(),
|
||||
};
|
||||
let mut events = vec![];
|
||||
let expected = r#"<message from="duqedadi@conference.oflor.me/misha" xml:lang="en" to="misha@oflor.me/tux" type="groupchat" id="7ca7cb14-b2af-49c9-bd90-05dabb1113a5"><delay xmlns="urn:xmpp:delay" stamp="2024-05-17T16:05:28.440337Z" from="duqedadi@conference.oflor.me"/><body></body></message>"#;
|
||||
let expected = r#"<message id="id" to="sauer@oflor.me@localhost/tester" from="pepe@rooms.localhost/sauer" type="groupchat"><delay xmlns="urn:xmpp:delay" from="pepe@rooms.localhost/tester" stamp="2021-10-10T10:10:10Z"/><body>Hello World.</body></message>"#;
|
||||
|
||||
// Act
|
||||
history_message.serialize(&mut events);
|
||||
|
||||
let flow = assemble_string_from_event_flow(&events);
|
||||
|
||||
// Assert
|
||||
assert_eq!(
|
||||
// events.pop().unwrap().to_vec(),
|
||||
// expected.as_bytes()
|
||||
String::from_utf8(events.pop().unwrap().to_vec()).unwrap(),
|
||||
expected
|
||||
);
|
||||
assert_eq!(flow, expected);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
use quick_xml::events::Event;
|
||||
use quick_xml::Writer;
|
||||
use std::io::Cursor;
|
||||
|
||||
pub fn assemble_string_from_event_flow(events: &Vec<Event<'_>>) -> String {
|
||||
let mut writer = Writer::new(Cursor::new(Vec::new()));
|
||||
for event in events {
|
||||
writer.write_event(event).unwrap();
|
||||
}
|
||||
let result = writer.into_inner().into_inner();
|
||||
String::from_utf8(result).unwrap()
|
||||
}
|
Loading…
Reference in New Issue