Skip to content

Commit 309520b

Browse files
committed
Add tests for time_to_timestamp
Signed-off-by: Kévin Commaille <[email protected]>
1 parent 763b171 commit 309520b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

crates/matrix-sdk-sqlite/src/utils.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,8 @@ pub(crate) fn time_to_timestamp(time: SystemTime) -> i64 {
396396

397397
#[cfg(test)]
398398
mod unit_tests {
399+
use std::time::Duration;
400+
399401
use super::*;
400402

401403
#[test]
@@ -410,4 +412,13 @@ mod unit_tests {
410412
fn generating_zero_vars_panics() {
411413
repeat_vars(0);
412414
}
415+
416+
#[test]
417+
fn test_time_to_timestamp() {
418+
assert_eq!(time_to_timestamp(SystemTime::UNIX_EPOCH), 0);
419+
assert_eq!(time_to_timestamp(SystemTime::UNIX_EPOCH + Duration::from_secs(60)), 60);
420+
421+
// Fallback value on overflow.
422+
assert_eq!(time_to_timestamp(SystemTime::UNIX_EPOCH - Duration::from_secs(60)), 0);
423+
}
413424
}

0 commit comments

Comments
 (0)