prox 0.1.1

Rusty development process manager like foreman, but better!
Documentation
use prox::Prox;
use std::path::Path;

#[test]
fn test_load_toml_config_file() {
    let config_path = Path::new(env!("CARGO_MANIFEST_DIR"))
        .join("tests")
        .join("fixtures")
        .join("config.toml");

    let prox = Prox::load_toml(&config_path).unwrap();
    let config = prox.config();

    // Test config values
    assert_eq!(config.readiness_fallback_timeout.as_secs(), 15);
    assert_eq!(config.prefix_width, 6);
    assert_eq!(config.colors.len(), 4);

    // Test processes
    assert_eq!(prox.procs().len(), 2);

    let api_proc = &prox.procs()[0];
    assert_eq!(api_proc.name, "api");
    assert_eq!(api_proc.command.to_string_lossy(), "cargo");
    assert_eq!(api_proc.args.len(), 3);
    assert_eq!(
        api_proc.readiness_pattern,
        Some("Server listening".to_string())
    );
    assert_eq!(api_proc.watch.len(), 1);
    assert_eq!(api_proc.watch_rel.len(), 1);
    let watch_abs = api_proc.watch_abs(&config);
    println!("{watch_abs:?}");
    assert_eq!(watch_abs.unwrap().len(), 2);
    assert!(api_proc.color.is_some());
    assert_eq!(api_proc.env.len(), 2);

    let worker_proc = &prox.procs()[1];
    assert_eq!(worker_proc.name, "worker");
    assert!(worker_proc.env_clear);
}

#[test]
fn test_load_yaml_config_file() {
    let config_path = Path::new(env!("CARGO_MANIFEST_DIR"))
        .join("tests")
        .join("fixtures")
        .join("config.yaml");

    let prox = Prox::load_yaml(&config_path).unwrap();
    let config = prox.config();

    // Test config values
    assert_eq!(config.readiness_fallback_timeout.as_secs(), 20);
    assert_eq!(config.prefix_width, 8);
    assert_eq!(config.colors.len(), 3);

    // Test processes
    assert_eq!(prox.procs().len(), 2);

    let api_proc = &prox.procs()[0];
    assert_eq!(api_proc.name, "api");
    assert_eq!(api_proc.env.len(), 2);
    assert!(!api_proc.env_clear);

    let db_proc = &prox.procs()[1];
    assert_eq!(db_proc.name, "database");
    assert!(db_proc.env_clear);
}

#[test]
fn test_invalid_color_in_config() {
    let config_path = Path::new(env!("CARGO_MANIFEST_DIR"))
        .join("tests")
        .join("fixtures")
        .join("bad_config.toml");

    let result = Prox::load_toml(&config_path);
    assert!(result.is_err());

    let error = result.unwrap_err();
    let full_error_chain = format!("{error:?}");
    // Check if either the main error or any source error contains the invalid color
    assert!(
        full_error_chain.contains("Invalid color name: invalid_color_name"),
        "Expected error to contain 'Invalid color name: invalid_color_name', got: {full_error_chain}"
    );
}