mithril_common/test/double/mod.rs
1//! Test doubles
2//!
3//! Enable unit testing with controlled inputs and predictable behavior.
4
5mod api_version;
6mod certificate_retriever;
7mod dummies;
8pub mod fake_data;
9pub mod fake_keys;
10pub(super) mod precomputed_kes_key;
11
12pub use api_version::DummyApiVersionDiscriminantSource;
13pub use certificate_retriever::FakeCertificaterRetriever;
14
15/// A trait for giving a type a dummy value.
16///
17/// Sometimes in tests you need to provide a value for a type, but the actual value doesn't matter.
18/// This trait allows defining a "dummy" value for a type, separated from an eventual default
19/// value, that can be reused across multiple tests.
20///
21/// Note: should not be confused with "fake" values, fake values aim to be believable and contain
22/// valid cryptography (if they have some), dummies don't aim for those characteristics.
23///
24/// # Example
25/// ```
26/// use mithril_common::test::double::Dummy;
27///
28/// struct MyType(String);
29///
30/// impl Dummy for MyType {
31/// fn dummy() -> Self {
32/// MyType("whatever".to_string())
33/// }
34/// }
35///
36/// let instance = MyType::dummy();
37/// ```
38pub trait Dummy: Sized {
39 /// Return a dummy value for the type
40 ///
41 /// Useful for test contexts when the actual value doesn't matter.
42 fn dummy() -> Self;
43}