use faucet_cli::config::{ConnectorSpec, DlqSpec, OnBatchErrorSpec};
use faucet_cli::executor::build_dlq_config;
use serde_json::json;
use tempfile::tempdir;
#[tokio::test]
async fn build_dlq_config_constructs_runtime_config_from_spec() {
let dir = tempdir().unwrap();
let dlq_path = dir.path().join("dlq.jsonl");
let spec = DlqSpec {
sink: ConnectorSpec {
kind: "jsonl".into(),
config: json!({ "path": dlq_path }),
transforms: None,
inherit_transforms: true,
status: None,
tags: Vec::new(),
complete_for: None,
},
on_batch_error: OnBatchErrorSpec::DlqAll,
max_failures_per_page: Some(100),
max_failures_total: Some(10000),
include_original_payload: true,
};
let cfg = build_dlq_config(&spec).await.expect("build_dlq_config");
assert!(cfg.include_original_payload);
assert_eq!(cfg.max_failures_per_page, Some(100));
assert_eq!(cfg.max_failures_total, Some(10000));
assert!(matches!(
cfg.on_batch_error,
faucet_core::OnBatchError::DlqAll
));
}
#[tokio::test]
async fn build_dlq_config_defaults_propagate_policy() {
let dir = tempdir().unwrap();
let dlq_path = dir.path().join("dlq.jsonl");
let spec = DlqSpec {
sink: ConnectorSpec {
kind: "jsonl".into(),
config: json!({ "path": dlq_path }),
transforms: None,
inherit_transforms: true,
status: None,
tags: Vec::new(),
complete_for: None,
},
on_batch_error: OnBatchErrorSpec::Propagate,
max_failures_per_page: None,
max_failures_total: None,
include_original_payload: true,
};
let cfg = build_dlq_config(&spec).await.expect("build_dlq_config");
assert!(matches!(
cfg.on_batch_error,
faucet_core::OnBatchError::Propagate
));
assert!(cfg.max_failures_per_page.is_none());
}