use super::{ConfigError, Result};
pub(super) fn optional_text(field: &'static str, value: Option<&str>) -> Result<()> {
if value.is_some_and(|value| value.trim().is_empty()) {
return Err(ConfigError::validation(
field,
"must not be blank when provided",
));
}
Ok(())
}
pub(super) fn redacted(value: &str) -> &'static str {
if value.is_empty() { "" } else { "[REDACTED]" }
}
#[cfg(test)]
mod tests {
use super::optional_text;
#[test]
fn optional_text_accepts_absent_and_non_blank_values() {
assert!(optional_text("field", None).is_ok());
assert!(optional_text("field", Some("value")).is_ok());
}
#[test]
fn optional_text_rejects_blank_values() {
assert!(optional_text("field", Some(" \t")).is_err());
}
}