This repository has been archived on 2024-07-25. You can view files and clone it, but cannot push or open issues or pull requests.
enve/itconfig_tests/tests/get_env.rs

24 lines
560 B
Rust
Raw Normal View History

2020-01-16 22:05:35 +03:00
use std::env;
use itconfig::*;
#[test]
#[should_panic(expected = "Environment variable \"TEST_CASE_1\" is missing")]
fn missing_env_variable() {
get_env_or_panic::<String>("TEST_CASE_1");
2020-01-16 22:05:35 +03:00
}
#[test]
#[should_panic(expected = "Failed to parse environment variable \"TEST_CASE_2\"")]
fn cannot_parse_env_variable() {
env::set_var("TEST_CASE_2", "30r");
get_env_or_panic::<u32>("TEST_CASE_2");
2020-01-16 22:05:35 +03:00
}
#[test]
fn get_env_successfully() {
env::set_var("TEST_CASE_3", "30");
let a = get_env::<u32>("TEST_CASE_3").unwrap();
2020-01-16 22:05:35 +03:00
assert_eq!(a, 30);
}