use apollo_configuration::configuration;
use apollo_configuration::parse_yaml;
use apollo_configuration::types::Url;
use apollo_redaction::Redacted;
#[configuration]
struct RedactedStringConfig {
#[config(required)]
secret: Redacted<String>,
}
#[test]
fn redacted_string_parses() {
let config: RedactedStringConfig =
parse_yaml("secret: my-secret-value", &Default::default()).unwrap();
assert_eq!(config.secret.unredact(), "my-secret-value");
assert_eq!(config.secret.to_string(), "[REDACTED]");
}
#[configuration]
struct RedactedUrlConfig {
#[config(required)]
endpoint: Redacted<Url>,
}
#[test]
fn redacted_url_parses() {
let config: RedactedUrlConfig =
parse_yaml("endpoint: https://secret.example.com", &Default::default()).unwrap();
assert_eq!(
config.endpoint.unredact().as_str(),
"https://secret.example.com/"
);
assert_eq!(config.endpoint.to_string(), "[REDACTED]");
}
#[test]
fn redacted_url_error_propagates() {
let result = parse_yaml::<RedactedUrlConfig>("endpoint: '://invalid'", &Default::default());
let err = result.expect_err("should fail to parse invalid URL");
assert_eq!(
format!("{err}"),
"failed to parse value: failed to parse 'Url'"
);
}