#[cfg(test)] mod test_main { use envkit::*; #[test] /// Tests that `get` successfully retrieves an existing environment variable. fn test_get() { let env = EnvLoader; unsafe { std::env::set_var("TEST_VAR", "test_value"); } assert_eq!(env.get::("TEST_VAR"), Ok("test_value".to_string())); } #[test] /// Tests that `get_or` returns the default value when the environment variable is missing. fn test_get_or() { let env = EnvLoader; unsafe { std::env::remove_var("MISSING_VAR"); std::env::set_var("TEST_VAR", "test_value"); } assert_eq!(env.get_or::("MISSING_VAR", "default".to_string()), "default".to_string()); assert_eq!(env.get_or::("TEST_VAR", "default".to_string()), "test_value".to_string()); } #[test] /// Tests that `get_opt` returns `Some` when the environment variable exists. fn test_get_opt() { let env = EnvLoader; unsafe { std::env::set_var("OPTIONAL_VAR", "optional_value"); } assert_eq!(env.get_opt::("OPTIONAL_VAR"), Some("optional_value".to_string())); assert_eq!(env.get_opt::("DEV"), None); } }