MCPcopy Create free account
hub / github.com/chatmail/core / new_internal

Method new_internal

src/test_utils.rs:572–609  ·  view source on GitHub ↗

Internal constructor. `name` is used to identify this context in e.g. log output. This is useful mostly when you have multiple [`TestContext`]s in a test. `log_sender` is assumed to be the sender for a [`LogSink`]. If not supplied a new [`LogSink`] will be created so that events are logged to this test when the [`TestContext`] is dropped.

(name: Option<String>, log_sink: Option<LogSink>)

Source from the content-addressed store, hash-verified

570 /// [`LogSink`] will be created so that events are logged to this test when the
571 /// [`TestContext`] is dropped.
572 async fn new_internal(name: Option<String>, log_sink: Option<LogSink>) -> Self {
573 let dir = tempdir().unwrap();
574 let dbfile = dir.path().join("db.sqlite");
575 let id = rand::random();
576 if let Some(name) = name {
577 let mut context_names = CONTEXT_NAMES.write().unwrap();
578 context_names.insert(id, name);
579 }
580 let events = Events::new();
581 let evtracker_receiver = events.get_emitter();
582 let ctx = Context::new(&dbfile, id, events, StockStrings::new())
583 .await
584 .expect("failed to create context");
585
586 let _log_sink = if let Some(log_sink) = log_sink {
587 // Subscribe existing LogSink and don't store reference to it.
588 log_sink.subscribe(ctx.get_event_emitter());
589 None
590 } else {
591 // Create new LogSink and store it inside the `TestContext`.
592 let log_sink = LogSink::new();
593 log_sink.subscribe(ctx.get_event_emitter());
594 Some(log_sink)
595 };
596
597 ctx.set_config(Config::SkipStartMessages, Some("1"))
598 .await
599 .unwrap();
600 ctx.set_config(Config::BccSelf, Some("1")).await.unwrap();
601 ctx.set_config(Config::SyncMsgs, Some("0")).await.unwrap();
602
603 Self {
604 ctx,
605 dir,
606 evtracker: EventTracker::new(evtracker_receiver),
607 _log_sink,
608 }
609 }
610
611 /// Sets a name for this [`TestContext`] if one isn't yet set.
612 ///

Callers

nothing calls this directly

Calls 5

insertMethod · 0.80
get_emitterMethod · 0.80
subscribeMethod · 0.45
get_event_emitterMethod · 0.45
set_configMethod · 0.45

Tested by

no test coverage detected