-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
50dac94
commit ad85f14
Showing
2 changed files
with
73 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters