Skip to content

Commit e3f90d4

Browse files
committed
tests(dmq): add fake test double for 'UnixTimestampProvider'
1 parent d7ce977 commit e3f90d4

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

internal/mithril-dmq/src/test/double/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
55
mod consumer;
66
mod publisher;
7+
mod timestamp;
78

89
pub use consumer::*;
910
pub use publisher::*;
11+
pub use timestamp::*;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use mithril_common::StdResult;
2+
3+
use crate::model::UnixTimestampProvider;
4+
5+
/// Fake implementation of a Unix current timestamp provider. For testing purposes only.
6+
pub struct FakeUnixTimestampProvider(u64);
7+
8+
impl FakeUnixTimestampProvider {
9+
/// Creates a new `FakeUnixTimestampProvider` with the given timestamp.
10+
pub fn new(timestamp: u64) -> Self {
11+
Self(timestamp)
12+
}
13+
14+
/// Computes the maximum timestamp that can be used with the given TTL and builds a new FakeUnixTimestampProvider.
15+
///
16+
/// This is useful to create messages that are valid for the maximum possible time.
17+
pub fn max_timestamp_for_ttl(ttl: u16) -> Self {
18+
Self(u32::MAX as u64 - ttl as u64 - 1)
19+
}
20+
}
21+
22+
impl UnixTimestampProvider for FakeUnixTimestampProvider {
23+
fn current_timestamp(&self) -> StdResult<u64> {
24+
Ok(self.0)
25+
}
26+
}

0 commit comments

Comments
 (0)