v0.5.3-pre.002
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// file: ks-config/src/environment.rs
|
||||
// version: 6
|
||||
// version: 8
|
||||
|
||||
//! Environment-file loading and configuration placeholder resolution.
|
||||
|
||||
@@ -16,7 +16,7 @@ pub struct EnvironmentLoadReport {
|
||||
/// fallback text declared with `${NAME:-fallback}` placeholders.
|
||||
pub fn load_workspace_environment(
|
||||
workspace_root: &std::path::Path,
|
||||
) -> ks_core::Result<EnvironmentLoadReport> {
|
||||
) -> ks_core::Result<crate::EnvironmentLoadReport> {
|
||||
let explicit_path = std::env::var("KS_ENV_FILE").ok();
|
||||
let selected_path = match explicit_path {
|
||||
std::option::Option::Some(path) if !path.trim().is_empty() => {
|
||||
@@ -26,10 +26,10 @@ pub fn load_workspace_environment(
|
||||
_ => workspace_root.join(".env"),
|
||||
};
|
||||
if !selected_path.exists() {
|
||||
return std::result::Result::Ok(EnvironmentLoadReport { loaded_path: None });
|
||||
return std::result::Result::Ok(crate::EnvironmentLoadReport { loaded_path: None });
|
||||
}
|
||||
return match dotenvy::from_path(&selected_path) {
|
||||
std::result::Result::Ok(()) => std::result::Result::Ok(EnvironmentLoadReport {
|
||||
std::result::Result::Ok(()) => std::result::Result::Ok(crate::EnvironmentLoadReport {
|
||||
loaded_path: std::option::Option::Some(selected_path),
|
||||
}),
|
||||
std::result::Result::Err(_) => std::result::Result::Err(ks_core::Error::new(
|
||||
@@ -82,14 +82,14 @@ mod tests {
|
||||
#[test]
|
||||
fn fallback_is_used_when_variable_is_absent() {
|
||||
let resolved =
|
||||
super::resolve_environment_placeholders("${KS_CONFIG_TEST_MISSING:-fallback}");
|
||||
crate::resolve_environment_placeholders("${KS_CONFIG_TEST_MISSING:-fallback}");
|
||||
assert_eq!(resolved, "fallback");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unresolved_required_placeholder_is_preserved() {
|
||||
let resolved =
|
||||
super::resolve_environment_placeholders("prefix-${KS_CONFIG_TEST_MISSING}-suffix");
|
||||
crate::resolve_environment_placeholders("prefix-${KS_CONFIG_TEST_MISSING}-suffix");
|
||||
assert_eq!(resolved, "prefix-${KS_CONFIG_TEST_MISSING}-suffix");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user