#[cfg(test)]
mod tests {
use catalyst::models::test::JsonAssertion;
use catalyst::parser::{list_tests, parse_tests};
#[test]
fn test_parse_tests_with_custom_file() {
let file_path = "tests/syntax/toml_syntax_validation.toml";
let result = parse_tests(Some(file_path));
assert!(result.is_ok(), "Failed to parse test file");
let test_suite = result.unwrap();
assert_eq!(test_suite.config.base_url, "https://httpbin.org");
assert_eq!(test_suite.tests.len(), 7);
let first_test = &test_suite.tests[0];
assert_eq!(first_test.name, "Basic Test");
assert_eq!(first_test.method, "GET");
assert_eq!(first_test.endpoint, "/get");
assert_eq!(first_test.expected_status, 200);
assert!(first_test.assertions.is_some());
assert_eq!(first_test.assertions.as_ref().unwrap().len(), 1);
}
#[test]
fn test_parse_tests_with_complex_toml_syntax() {
let file_path = "tests/syntax/toml_syntax_validation.toml";
let result = parse_tests(Some(file_path));
assert!(
result.is_ok(),
"Failed to parse test file with complex TOML syntax"
);
let test_suite = result.unwrap();
let complex_test = test_suite
.tests
.iter()
.find(|t| t.name == "Complex Test")
.unwrap();
assert!(complex_test.body.is_some());
let body = complex_test.body.as_ref().unwrap();
assert!(body.to_string().contains("Test User"));
assert!(complex_test.assertions.is_some());
let assertions = complex_test.assertions.as_ref().unwrap();
assert_eq!(assertions.len(), 2);
match &assertions[0] {
JsonAssertion::Contains(_) => {} _ => panic!("First assertion should be Contains"),
}
match &assertions[1] {
JsonAssertion::PathRegex(_, _) => {} _ => panic!("Second assertion should be PathRegex"),
}
}
#[test]
fn test_parse_tests_invalid_file() {
let result = parse_tests(Some("/path/to/nonexistent/file.toml"));
assert!(result.is_err());
assert_eq!(result.unwrap_err(), "Failed to read tests file");
}
#[test]
fn test_list_tests_with_custom_file() {
let file_path = "tests/syntax/toml_syntax_validation.toml";
list_tests(false, Some(file_path));
list_tests(true, Some(file_path));
}
}