use std::collections::HashMap;
pub struct Env(HashMap<String, String>);
impl Env {
pub fn current() -> Self {
Self(std::env::vars().collect())
}
pub fn from_map(map: HashMap<String, String>) -> Self {
Self(map)
}
pub fn contains(&self, key: &str) -> bool {
self.0.get(key).map(|v| !v.is_empty()).unwrap_or(false)
}
pub fn equals(&self, key: &str, expected: &str) -> bool {
self.0.get(key).map(|v| v == expected).unwrap_or(false)
}
#[allow(dead_code)]
pub fn get(&self, key: &str) -> Option<&str> {
self.0.get(key).map(|s| s.as_str())
}
}
#[cfg(test)]
pub struct EnvBuilder(HashMap<String, String>);
#[cfg(test)]
impl EnvBuilder {
pub fn new() -> Self {
Self(HashMap::new())
}
pub fn set(mut self, key: &str, value: &str) -> Self {
self.0.insert(key.to_owned(), value.to_owned());
self
}
pub fn build(self) -> Env {
Env::from_map(self.0)
}
}