diff --git a/crates/proto-xmpp/src/lib.rs b/crates/proto-xmpp/src/lib.rs
index 71e8a94..5519c45 100644
--- a/crates/proto-xmpp/src/lib.rs
+++ b/crates/proto-xmpp/src/lib.rs
@@ -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) => {
diff --git a/crates/proto-xmpp/src/muc/mod.rs b/crates/proto-xmpp/src/muc/mod.rs
index 4df427c..a2c77e4 100644
--- a/crates/proto-xmpp/src/muc/mod.rs
+++ b/crates/proto-xmpp/src/muc/mod.rs
@@ -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,13 @@ mod test {
body: "Hello World.".to_string(),
};
let mut events = vec![];
- let expected = r#""#;
+ let expected = r#"Hello World."#;
// 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);
}
}
diff --git a/crates/proto-xmpp/src/testkit.rs b/crates/proto-xmpp/src/testkit.rs
new file mode 100644
index 0000000..a40381f
--- /dev/null
+++ b/crates/proto-xmpp/src/testkit.rs
@@ -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>) -> 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()
+}