Skip to content

Commit e38314b

Browse files
committed
Use the LogSink explicitly in securejoin tests
1 parent 54ed841 commit e38314b

File tree

2 files changed

+46
-10
lines changed

2 files changed

+46
-10
lines changed

src/securejoin.rs

+45-9
Original file line numberDiff line numberDiff line change
@@ -941,12 +941,21 @@ mod tests {
941941
use crate::chatlist::Chatlist;
942942
use crate::constants::Chattype;
943943
use crate::peerstate::Peerstate;
944-
use crate::test_utils::TestContext;
944+
use crate::test_utils::{LogSink, TestContext};
945945

946946
#[async_std::test]
947947
async fn test_setup_contact() -> Result<()> {
948-
let alice = TestContext::new_alice().await;
949-
let bob = TestContext::new_bob().await;
948+
let (log_tx, _log_sink) = LogSink::create();
949+
let alice = TestContext::builder()
950+
.as_alice()
951+
.with_log_sink(log_tx.clone())
952+
.build()
953+
.await;
954+
let bob = TestContext::builder()
955+
.as_bob()
956+
.with_log_sink(log_tx)
957+
.build()
958+
.await;
950959
assert_eq!(Chatlist::try_load(&alice, 0, None, None).await?.len(), 0);
951960
assert_eq!(Chatlist::try_load(&bob, 0, None, None).await?.len(), 0);
952961

@@ -1133,8 +1142,17 @@ mod tests {
11331142

11341143
#[async_std::test]
11351144
async fn test_setup_contact_bob_knows_alice() -> Result<()> {
1136-
let alice = TestContext::new_alice().await;
1137-
let bob = TestContext::new_bob().await;
1145+
let (log_tx, _log_sink) = LogSink::create();
1146+
let alice = TestContext::builder()
1147+
.as_alice()
1148+
.with_log_sink(log_tx.clone())
1149+
.build()
1150+
.await;
1151+
let bob = TestContext::builder()
1152+
.as_bob()
1153+
.with_log_sink(log_tx)
1154+
.build()
1155+
.await;
11381156

11391157
// Ensure Bob knows Alice_FP
11401158
let alice_pubkey = SignedPublicKey::load_self(&alice.ctx).await?;
@@ -1257,8 +1275,17 @@ mod tests {
12571275

12581276
#[async_std::test]
12591277
async fn test_setup_contact_concurrent_calls() -> Result<()> {
1260-
let alice = TestContext::new_alice().await;
1261-
let bob = TestContext::new_bob().await;
1278+
let (log_tx, _log_sink) = LogSink::create();
1279+
let alice = TestContext::builder()
1280+
.as_alice()
1281+
.with_log_sink(log_tx.clone())
1282+
.build()
1283+
.await;
1284+
let bob = TestContext::builder()
1285+
.as_bob()
1286+
.with_log_sink(log_tx)
1287+
.build()
1288+
.await;
12621289

12631290
// do a scan that is not working as claire is never responding
12641291
let qr_stale = "OPENPGP4FPR:1234567890123456789012345678901234567890#a=claire%40foo.de&n=&i=12345678901&s=23456789012";
@@ -1287,8 +1314,17 @@ mod tests {
12871314

12881315
#[async_std::test]
12891316
async fn test_secure_join() -> Result<()> {
1290-
let alice = TestContext::new_alice().await;
1291-
let bob = TestContext::new_bob().await;
1317+
let (log_tx, _log_sink) = LogSink::create();
1318+
let alice = TestContext::builder()
1319+
.as_alice()
1320+
.with_log_sink(log_tx.clone())
1321+
.build()
1322+
.await;
1323+
let bob = TestContext::builder()
1324+
.as_bob()
1325+
.with_log_sink(log_tx)
1326+
.build()
1327+
.await;
12921328
assert_eq!(Chatlist::try_load(&alice, 0, None, None).await?.len(), 0);
12931329
assert_eq!(Chatlist::try_load(&bob, 0, None, None).await?.len(), 0);
12941330

src/test_utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ pub struct LogSink {
567567

568568
impl LogSink {
569569
/// Creates a new [`LogSink`] and returns the attached event sink.
570-
fn create() -> (Sender<Event>, Self) {
570+
pub fn create() -> (Sender<Event>, Self) {
571571
let (tx, rx) = channel::unbounded();
572572
(tx, Self { events: rx })
573573
}

0 commit comments

Comments
 (0)