mirror of
https://github.com/chatmail/core.git
synced 2026-04-19 06:26:30 +03:00
Improve test_migration_flags, add EvTracker to test_utils
This commit is contained in:
@@ -9,6 +9,7 @@ use std::{collections::BTreeMap, panic};
|
||||
use std::{fmt, thread};
|
||||
|
||||
use ansi_term::Color;
|
||||
use async_std::channel::Receiver;
|
||||
use async_std::path::PathBuf;
|
||||
use async_std::sync::{Arc, RwLock};
|
||||
use async_std::{channel, pin::Pin};
|
||||
@@ -183,6 +184,21 @@ impl TestContext {
|
||||
sinks.push(Box::new(move |evt| Box::pin(sink(evt))));
|
||||
}
|
||||
|
||||
pub async fn new_evtracker(&self) -> EvTracker {
|
||||
let (sender, receiver) = channel::unbounded();
|
||||
let sender = Arc::new(sender);
|
||||
self.add_event_sink(move |event| {
|
||||
let sender = sender.clone();
|
||||
async move {
|
||||
sender.send(event.typ).await.ok();
|
||||
// If sending fails, probably the EvTracker was simply dropped,
|
||||
// so we call ok() to ignore the error
|
||||
}
|
||||
})
|
||||
.await;
|
||||
EvTracker(receiver)
|
||||
}
|
||||
|
||||
/// Configure with alice@example.com.
|
||||
///
|
||||
/// The context will be fake-configured as the alice user, with a pre-generated secret
|
||||
@@ -568,6 +584,28 @@ pub fn bob_keypair() -> key::KeyPair {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct EvTracker(Receiver<EventType>);
|
||||
|
||||
impl EvTracker {
|
||||
pub async fn get_info_contains(&self, s: &str) -> EventType {
|
||||
loop {
|
||||
let event = self.0.recv().await.unwrap();
|
||||
if let EventType::Info(i) = &event {
|
||||
if i.contains(s) {
|
||||
return event;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for EvTracker {
|
||||
type Target = Receiver<EventType>;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets a specific message from a chat and asserts that the chat has a specific length.
|
||||
///
|
||||
/// Panics if the length of the chat is not `asserted_msgs_count` or if the chat item at `index` is not a Message.
|
||||
|
||||
Reference in New Issue
Block a user