comtrya_lib/steps/initializers/
env_vars_set.rs1use super::Initializer;
2use std::collections::HashMap;
3
4#[derive(Clone, Debug)]
5pub struct SetEnvVars(pub HashMap<String, String>);
6
7impl Initializer for SetEnvVars {
8 fn initialize(&self) -> anyhow::Result<bool> {
9 for (key, value) in self.0.iter() {
10 std::env::set_var(key, value);
11 }
12
13 Ok(true)
14 }
15}
16
17#[cfg(test)]
18mod tests {
19 use super::*;
20 use std::env;
21
22 #[test]
23 fn test_env_vars() {
24 let map = HashMap::from([("hello".to_string(), "world".to_string())]);
25 let initializer = SetEnvVars(map);
26 let result = initializer.initialize();
27
28 pretty_assertions::assert_eq!(true, result.is_ok());
29 pretty_assertions::assert_eq!(true, result.unwrap());
30 let value = env::var("hello");
31 pretty_assertions::assert_eq!("world", value.unwrap());
32 }
33}