test: Assert log warnings and errors (#8457)

Adds `assert_warn`, `assert_error` and `assert_warns_or_errors`
methods to `TestContext`, that let us assert that
a certain warning or error is logged during the test.
Also asserts test logs should not contain any other
errors or warnings.

Adjusts tests accordingly.

Signed-off-by: Jagoda Ślązak <jslazak@jslazak.com>
This commit is contained in:
Jagoda Estera Ślązak
2026-08-10 13:36:09 +00:00
committed by GitHub
parent 97932fda07
commit fd8c56894a
36 changed files with 554 additions and 219 deletions
+7 -1
View File
@@ -176,7 +176,7 @@ async fn test_search_contacts_from_group() -> Result<()> {
let bob = &tcm.bob().await;
let fiona = &tcm.fiona().await;
let alice_chat_id = chat::create_group(alice, "").await?;
let alice_chat_id = chat::create_group(alice, "group").await?;
let qr = get_securejoin_qr(alice, Some(alice_chat_id)).await?;
let bob_chat_id = tcm.exec_securejoin_qr(bob, alice, &qr).await;
tcm.exec_securejoin_qr(fiona, alice, &qr).await;
@@ -238,6 +238,7 @@ async fn test_add_or_lookup() {
"\nWonderland, Alice <alice@w.de>\n",
);
assert_eq!(Contact::add_address_book(&t, book).await.unwrap(), 4);
t.assert_warn(r#"invalid address "+1234567890""#).await;
// check first added contact, this modifies authname because it is empty
let (contact_id, sth_modified) = Contact::add_or_lookup(
@@ -1095,6 +1096,11 @@ async fn test_was_seen_recently_event() -> Result<()> {
.get_matching(|evt| matches!(evt, EventType::ContactsChanged { .. }))
.await;
}
// this warning is only printed when `RecentlySeenLoop` is dropped,
// so we can't assert it otherwise.
drop(recently_seen_loop);
bob.assert_warn("receiving from an empty and closed channel")
.await;
Ok(())
}