apollo-configuration 0.4.0

A typed, friendly configuration system for Apollo products.
Documentation
use apollo_configuration::configuration;
use apollo_configuration::parse_yaml;
use apollo_configuration::types::Url;

#[configuration]
struct VecConfig {
    #[config(required)]
    urls: Vec<Url>,
}

#[test]
fn vec_parses() {
    let config: VecConfig = parse_yaml(
        r#"
        urls:
          - "https://example.com"
          - "https://api.example.com"
        "#,
        &Default::default(),
    )
    .unwrap();

    assert_eq!(config.urls.len(), 2);
    assert_eq!(config.urls[0].as_str(), "https://example.com/");
    assert_eq!(config.urls[1].as_str(), "https://api.example.com/");
}

#[test]
fn vec_empty_parses() {
    let config: VecConfig = parse_yaml("urls: []", &Default::default()).unwrap();
    assert!(config.urls.is_empty());
}

#[test]
fn vec_element_error_message() {
    let result = parse_yaml::<VecConfig>(
        r#"
        urls:
          - "https://example.com"
          - "://invalid"
        "#,
        &Default::default(),
    );
    let err = result.expect_err("should fail to parse invalid URL");
    assert_eq!(
        format!("{err}"),
        "failed to parse value: relative URL without a base"
    );
}