#![allow(unused_crate_dependencies)]
#![cfg(feature = "threadsafe")]
mod fixture;
use output_tracker::threadsafe::{Error, OutputSubject, OutputTracker};
#[derive(Debug, Clone, PartialEq)]
struct Message {
topic: String,
content: String,
}
struct Adapter {
output_subject: OutputSubject<Message>,
}
impl Adapter {
fn new() -> Self {
Self {
output_subject: OutputSubject::new(),
}
}
fn track_messages(&self) -> Result<OutputTracker<Message>, Error> {
self.output_subject.create_tracker()
}
fn send_message(&self, message: Message) {
_ = self.output_subject.emit(message);
}
}
use asserting::prelude::*;
#[test]
fn send_message_via_adapter() {
let adapter = Adapter::new();
let tracker = adapter
.track_messages()
.unwrap_or_else(|err| panic!("failed to create message tracker {err}"));
adapter.send_message(Message {
topic: "weather report".to_string(),
content: "it will be snowing tomorrow".to_string(),
});
adapter.send_message(Message {
topic: "no shadow".to_string(),
content: "keep your face to the sunshine and you cannot see a shadow".to_string(),
});
let tracker_output = tracker
.output()
.unwrap_or_else(|err| panic!("failed to get output from tracker: {err}"));
assert_that!(tracker_output).contains_exactly([
Message {
topic: "weather report".to_string(),
content: "it will be snowing tomorrow".to_string(),
},
Message {
topic: "no shadow".to_string(),
content: "keep your face to the sunshine and you cannot see a shadow".to_string(),
},
]);
}