Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions configuration/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ stream:
port: 5432
name: "postgres"
username: "postgres"
password: null
tls:
enabled: false
trusted_root_certs: ""
Expand Down
31 changes: 27 additions & 4 deletions src/config/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,11 @@ where

let mut environment_source = config::Environment::with_prefix(ENV_PREFIX)
.prefix_separator(ENV_PREFIX_SEPARATOR)
.separator(ENV_SEPARATOR);
.separator(ENV_SEPARATOR)
.try_parsing(true);

if !T::LIST_PARSE_KEYS.is_empty() {
environment_source = environment_source
.try_parsing(true)
.list_separator(LIST_SEPARATOR);
environment_source = environment_source.list_separator(LIST_SEPARATOR);

for key in <T as Config>::LIST_PARSE_KEYS {
environment_source = environment_source.with_list_parse_key(key);
Expand Down Expand Up @@ -444,4 +443,28 @@ mod tests {
},
);
}

#[test]
fn test_env_vars_parse_numbers() {
let temp_dir = TempDir::new().unwrap();
let config_dir = temp_dir.path().join("configuration");
fs::create_dir(&config_dir).unwrap();

let base_content = "value: \"base\"\nnumber: 1\n";
fs::write(config_dir.join("base.yml"), base_content).unwrap();

with_vars(
vec![
("APP_ENVIRONMENT", Some("prod")),
("APP_CONFIG_DIR", Some(config_dir.to_str().unwrap())),
("APP_VALUE", Some("from_env")),
("APP_NUMBER", Some("5432")), // String that should parse to i32
],
|| {
let config: TestConfig = load_config().unwrap();
assert_eq!(config.value, "from_env");
assert_eq!(config.number, 5432);
},
);
}
}