-
Notifications
You must be signed in to change notification settings - Fork 0
/
mock.rs
36 lines (32 loc) · 945 Bytes
/
mock.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use mockable::{DefaultEnv, Env};
fn main() {
let env = DefaultEnv;
let val_1 = env.string("SECRET_1");
let val_2 = env.string("SECRET_2");
println!("{val_1:?} {val_2:?}");
}
#[cfg(test)]
mod test {
use mockable::{Mock, MockEnv};
use super::*;
#[test]
fn test() {
let mock = Mock::with(vec![
Box::new(|key: String| {
assert_eq!(key, "SECRET_1");
Some("val_1".into())
}),
Box::new(|key: String| {
assert_eq!(key, "SECRET_2");
Some("val_2".into())
}),
]);
let mut env = MockEnv::new();
env.expect_string()
.returning(move |key| mock.call_with_args(key.into()));
let val_1 = env.string("SECRET_1");
let val_2 = env.string("SECRET_2");
assert_eq!(val_1, Some("val_1".into()));
assert_eq!(val_2, Some("val_2".into()));
}
}