use super::*;
#[test]
fn test_python_payment_service_enrichment() {
let source_content =
std::fs::read_to_string(get_test_data_path("python", "payment_service.py"))
.expect("Failed to read Python source file");
let telemetry_file = get_test_data_path("python", "payment_traces.json");
let source_files = vec![(PathBuf::from("payment_service.py"), source_content)];
let temp_dir = setup_test_directory(&source_files).expect("Failed to setup test directory");
let output = run_telemetry_command(temp_dir.path(), &telemetry_file, Some("payment-service"))
.expect("Failed to run telemetry command");
let expected = vec![
ExpectedEnrichment {
function_name: "process_payment".to_string(),
min_calls: 2,
latency_p50_range: Some((20.0, 70.0)), has_errors: false, error_message: None,
},
ExpectedEnrichment {
function_name: "validate_card".to_string(),
min_calls: 1,
latency_p50_range: Some((1.0, 3.0)), has_errors: false,
error_message: None,
},
ExpectedEnrichment {
function_name: "check_fraud".to_string(),
min_calls: 1,
latency_p50_range: Some((9.0, 11.0)), has_errors: false,
error_message: None,
},
ExpectedEnrichment {
function_name: "charge_card".to_string(),
min_calls: 1,
latency_p50_range: Some((49.0, 51.0)), has_errors: false,
error_message: None,
},
ExpectedEnrichment {
function_name: "refund_payment".to_string(),
min_calls: 1,
latency_p50_range: Some((29.0, 31.0)), has_errors: false,
error_message: None,
},
];
assert_enrichments(&output, &expected);
assert!(
output.contains("Total spans: 6"),
"Incorrect total span count"
);
assert!(
output.contains("Functions with metrics: 5"),
"Incorrect function count"
);
}
#[test]
fn test_python_class_method_correlation() {
let source_content =
std::fs::read_to_string(get_test_data_path("python", "payment_service.py"))
.expect("Failed to read Python source file");
let telemetry_file = get_test_data_path("python", "payment_traces.json");
let source_files = vec![(PathBuf::from("payment_service.py"), source_content)];
let temp_dir = setup_test_directory(&source_files).expect("Failed to setup test directory");
let output = run_telemetry_command(temp_dir.path(), &telemetry_file, None)
.expect("Failed to run telemetry command");
let class_methods = vec![
"process_payment",
"validate_card",
"check_fraud",
"charge_card",
"refund_payment",
];
for method in class_methods {
assert!(
output.contains(method),
"Class method {method} not found in correlation"
);
}
assert!(output.contains("Correlated spans: 6"));
assert!(output.contains("Functions with metrics: 5"));
}