From 3c13b3edd471a5cd48a1fd582e916a70947eda21 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Mon, 16 Feb 2026 11:37:54 +0000 Subject: [PATCH] test(qr-login): assert expect error codes in grant test cases --- .../src/authentication/oauth/qrcode/grant.rs | 41 +++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/crates/matrix-sdk/src/authentication/oauth/qrcode/grant.rs b/crates/matrix-sdk/src/authentication/oauth/qrcode/grant.rs index fde6b0d66..9feacda5d 100644 --- a/crates/matrix-sdk/src/authentication/oauth/qrcode/grant.rs +++ b/crates/matrix-sdk/src/authentication/oauth/qrcode/grant.rs @@ -1175,7 +1175,11 @@ mod test { }); // Wait for all tasks to finish / fail. - grant.await.expect_err("Alice should abort the login"); + assert_matches!( + grant.await, + Err(QRCodeGrantLoginError::Unknown(_)), + "Alice should abort the login with expected error" + ); updates_task.await.expect("Alice should run through all progress states"); bob_task.await.expect("Bob's task should finish"); } @@ -1276,9 +1280,12 @@ mod test { .await; }); - grant.await.expect_err("Alice should abort the login"); - // Wait for all tasks to finish / fail. + assert_matches!( + grant.await, + Err(QRCodeGrantLoginError::Unknown(_)), + "Alice should abort the login with expected error" + ); updates_task.await.expect("Alice should run through all progress states"); bob_task.await.expect("Bob's task should finish"); } @@ -1404,7 +1411,11 @@ mod test { }); // Wait for all tasks to finish. - grant.await.expect_err("Alice should abort the login"); + assert_matches!( + grant.await, + Err(QRCodeGrantLoginError::DeviceIDAlreadyInUse), + "Alice should abort the login with expected error" + ); updates_task.await.expect("Alice should run through all progress states"); bob_task.await.expect("Bob's task should finish"); } @@ -1515,7 +1526,11 @@ mod test { }); // Wait for all tasks to finish. - grant.await.expect_err("Alice should abort the login"); + assert_matches!( + grant.await, + Err(QRCodeGrantLoginError::DeviceIDAlreadyInUse), + "Alice should abort the login with expected error" + ); updates_task.await.expect("Alice should run through all progress states"); bob_task.await.expect("Bob's task should finish"); } @@ -1651,7 +1666,13 @@ mod test { .await; }); - grant.await.expect_err("Alice should abort the login"); + // TODO: the DeviceIDAlreadyInUse error here doesn't make much sense, instead + // something like UnableToCreateDevice? + assert_matches!( + grant.await, + Err(QRCodeGrantLoginError::DeviceIDAlreadyInUse), + "Alice should abort the login with expected error" + ); updates_task.await.expect("Alice should run through all progress states"); bob_task.await.expect("Bob's task should finish"); } @@ -1770,7 +1791,13 @@ mod test { .await; }); - grant.await.expect_err("Alice should abort the login"); + // TODO: the DeviceIDAlreadyInUse error here doesn't make much sense, instead + // something like UnableToCreateDevice? + assert_matches!( + grant.await, + Err(QRCodeGrantLoginError::DeviceIDAlreadyInUse), + "Alice should abort the login with expected error" + ); updates_task.await.expect("Alice should run through all progress states"); bob_task.await.expect("Bob's task should finish"); }