feat: Mock SystemTime::now() for the tests

Add a new crate `deltachat_time` with a fake `struct SystemTimeTools` for mocking
`SystemTime::now()` for test purposes. One still needs to use `std::time::SystemTime` as a struct
representing a system time. I think such a minimalistic approach is ok -- even if somebody uses the
original `SystemTime::now()` instead of the mock by mistake, that could break only tests but not the
program itself. The worst thing that can happen is that tests using `SystemTime::shift()` and
checking messages timestamps f.e. wouldn't catch the corresponding bugs, but now we don't have such
tests at all which is much worse.
This commit is contained in:
iequidoo
2023-12-15 23:19:37 -03:00
committed by iequidoo
parent 3b0e740c17
commit 6e55f0c6e3
13 changed files with 76 additions and 21 deletions

View File

@@ -319,7 +319,7 @@ impl Context {
#[cfg(test)]
mod tests {
use std::time::{Duration, SystemTime};
use std::time::Duration;
use anyhow::bail;
@@ -329,6 +329,7 @@ mod tests {
use crate::contact::{Contact, Origin};
use crate::test_utils::TestContext;
use crate::token::Namespace;
use crate::tools::SystemTime;
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_config_sync_msgs() -> Result<()> {