mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 09:26:29 +03:00
Improve test_migration_flags, add EvTracker to test_utils
This commit is contained in:
18
src/sql.rs
18
src/sql.rs
@@ -198,7 +198,7 @@ impl Sql {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
info!(context, "Opened {:?}.", dbfile);
|
info!(context, "Opened database {:?}.", dbfile);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -806,6 +806,8 @@ mod test {
|
|||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
async fn test_migration_flags() -> Result<()> {
|
async fn test_migration_flags() -> Result<()> {
|
||||||
let t = TestContext::new().await;
|
let t = TestContext::new().await;
|
||||||
|
let events = t.new_evtracker().await;
|
||||||
|
events.get_info_contains("Opened database").await;
|
||||||
|
|
||||||
// as migrations::run() was already executed on context creation,
|
// as migrations::run() was already executed on context creation,
|
||||||
// another call should not result in any action needed.
|
// another call should not result in any action needed.
|
||||||
@@ -817,6 +819,20 @@ mod test {
|
|||||||
assert!(!disable_server_delete);
|
assert!(!disable_server_delete);
|
||||||
assert!(!recode_avatar);
|
assert!(!recode_avatar);
|
||||||
|
|
||||||
|
info!(&t, "test_migration_flags: XXX");
|
||||||
|
|
||||||
|
loop {
|
||||||
|
if let EventType::Info(info) = events.recv().await.unwrap() {
|
||||||
|
assert!(
|
||||||
|
!info.contains("[migration]"),
|
||||||
|
"Migrations were run twice, you probably forgot to update the db version"
|
||||||
|
);
|
||||||
|
if info.contains("test_migration_flags: XXX") {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use std::{collections::BTreeMap, panic};
|
|||||||
use std::{fmt, thread};
|
use std::{fmt, thread};
|
||||||
|
|
||||||
use ansi_term::Color;
|
use ansi_term::Color;
|
||||||
|
use async_std::channel::Receiver;
|
||||||
use async_std::path::PathBuf;
|
use async_std::path::PathBuf;
|
||||||
use async_std::sync::{Arc, RwLock};
|
use async_std::sync::{Arc, RwLock};
|
||||||
use async_std::{channel, pin::Pin};
|
use async_std::{channel, pin::Pin};
|
||||||
@@ -183,6 +184,21 @@ impl TestContext {
|
|||||||
sinks.push(Box::new(move |evt| Box::pin(sink(evt))));
|
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.
|
/// Configure with alice@example.com.
|
||||||
///
|
///
|
||||||
/// The context will be fake-configured as the alice user, with a pre-generated secret
|
/// 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.
|
/// 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.
|
/// 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