pipeflow 0.0.4

A lightweight, configuration-driven data pipeline framework
Documentation
//! Tests for configuration validation (Deserialization errors)
//!
//! These tests verify that invalid YAML structures are correctly rejected
//! by the serde parsing logic, complementing the semantic validation
//! tests in `src/config.rs`.

use pipeflow::config::Config;

#[test]
fn test_config_missing_required_source_fields() {
    // Missing 'type' field in source
    let yaml = r#"
pipeline:
  sources:
    - id: src1
      # type: http_client  <-- Missing
      config:
        url: "http://example.com"
"#;
    let result = Config::from_yaml(yaml);
    assert!(result.is_err());
    let err = result.unwrap_err().to_string();
    assert!(err.contains("missing field `type`"));
}

#[test]
fn test_config_invalid_field_type() {
    // 'output_buffer_size' should be a number (usize), but given a string
    let yaml = r#"
pipeline:
  sources:
    - id: src1
      type: http_client
      output_buffer_size: "big"
"#;
    let result = Config::from_yaml(yaml);
    assert!(result.is_err());
    let err = result.unwrap_err().to_string();
    // Serde error message for type mismatch
    assert!(err.contains("invalid type: string"));
}

#[test]
fn test_config_malformed_yaml() {
    let yaml = r#"
pipeline:
  sources:
    - id: src1
      type: http_client
      config:
        url: "http://example.com"
   indentation_error: true
"#;
    let result = Config::from_yaml(yaml);
    assert!(result.is_err());
}

#[test]
fn test_config_transform_step_invalid_type() {
    // missing 'type' in step
    let yaml = r#"
pipeline:
  sources:
    - id: src1
      type: http_client
  transforms:
    - id: t1
      inputs: [src1]
      steps:
        - config: {} # Missing 'type'
"#;
    let result = Config::from_yaml(yaml);
    assert!(result.is_err());
    assert!(
        result
            .unwrap_err()
            .to_string()
            .contains("missing field `type`")
    );
}