catalyst/checker/
parser.rs

1use crate::models::suite::TestSuite;
2use std::fs;
3use toml;
4
5pub fn parse_tests(file_path: Option<&str>) -> Result<TestSuite, &'static str> {
6    let path = file_path.unwrap_or(".catalyst/tests.toml");
7    let content = fs::read_to_string(path).map_err(|_| "Failed to read tests file")?;
8    toml::from_str(&content).map_err(|_| "Invalid TOML format")
9}
10
11pub fn list_tests(verbose: bool, file_path: Option<&str>) {
12    match parse_tests(file_path) {
13        Ok(test_suite) => {
14            if test_suite.tests.is_empty() {
15                println!("No tests found in `tests.toml`.");
16                return;
17            }
18
19            println!("Available tests:");
20            for test in &test_suite.tests {
21                println!("- {}", test.name);
22                if verbose {
23                    println!("  Method: {}", test.method);
24                    println!("  Endpoint: {}", test.endpoint);
25                    if let Some(query_params) = &test.query_params {
26                        println!("  Query Params: {:?}", query_params);
27                    }
28                    if let Some(headers) = &test.headers {
29                        println!("  Headers: {:?}", headers);
30                    }
31                    if let Some(body) = &test.body {
32                        println!("  Body: {}", body);
33                    }
34                    println!("  Expected Status: {}", test.expected_status);
35                }
36            }
37        }
38        Err(err) => println!("Failed to list tests: {}", err),
39    }
40}