#![allow(dead_code)]
mod testenv;
use std::env::{self, VarError};
pub use testenv::*;
pub const TEST_KEY: &str = "TESTKEY";
pub const TEST_VALUE: &str = "test_val";
pub const TEST_EXISTING_KEY: &str = "TEST_EXISTING_KEY";
pub const TEST_EXISTING_VALUE: &str = "from_env";
pub const TEST_OVERRIDING_VALUE: &str = "from_file";
#[inline(always)]
pub fn create_default_envfile() -> String {
format!(
"{}={}\n{}={}",
TEST_KEY, TEST_VALUE, TEST_EXISTING_KEY, TEST_OVERRIDING_VALUE
)
}
#[inline(always)]
pub fn create_invalid_envfile() -> String {
format!(
"{}{}\n{}{}",
TEST_KEY, TEST_VALUE, TEST_EXISTING_KEY, TEST_OVERRIDING_VALUE
)
}
pub fn assert_env_var(key: &str, expected: &str) {
match env::var(key) {
Ok(actual) => assert_eq!(
expected, actual,
"\n\nFor Environment Variable `{}`:\n EXPECTED: `{}`\n ACTUAL: `{}`\n",
key, expected, actual
),
Err(VarError::NotPresent) => panic!("env var `{}` not found", key),
Err(VarError::NotUnicode(val)) => panic!(
"env var `{}` currently has invalid unicode: `{}`",
key,
val.to_string_lossy()
),
}
}
pub fn assert_env_var_unset(key: &str) {
match env::var(key) {
Ok(actual) => panic!(
"env var `{}` should not be set, currently it is: `{}`",
key, actual
),
Err(VarError::NotUnicode(val)) => panic!(
"env var `{}` should not be set, currently has invalid unicode: `{}`",
key,
val.to_string_lossy()
),
_ => (),
}
}