diff options
| author | Arnaud Bailly <arnaud.bailly@iohk.io> | 2024-09-29 12:54:38 +0200 |
|---|---|---|
| committer | Arnaud Bailly <arnaud.bailly@iohk.io> | 2024-09-29 12:54:38 +0200 |
| commit | 04261b4798a73118f5266801fca9bf3d7ca95bdf (patch) | |
| tree | 1992e6813411dfc88b568e481291e577b5786493 | |
| parent | 3ac809d7f8c4f29bfcd0a52c7e168e783abc88df (diff) | |
| download | lambda-nantes-04261b4798a73118f5266801fca9bf3d7ca95bdf.tar.gz | |
[wip] Draft tester program
The goal is to have a simple CLI that will repeatedly run sequence of
tests against a known (Rest-ish) API, until all tests are "green".
| -rw-r--r-- | rust/Cargo.toml | 4 | ||||
| -rw-r--r-- | rust/src/tester.rs | 57 |
2 files changed, 61 insertions, 0 deletions
diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 442a9ac..8cece05 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -16,3 +16,7 @@ path = "src/lib.rs" [[bin]] name = "lambda" path = "src/main.rs" + +[[bin]] +name = "tester" +path = "src/tester.rs" diff --git a/rust/src/tester.rs b/rust/src/tester.rs new file mode 100644 index 0000000..15ca468 --- /dev/null +++ b/rust/src/tester.rs @@ -0,0 +1,57 @@ +use std::{ + fs, + path::{Path, PathBuf}, +}; + +pub fn main() { + let args: Vec<String> = std::env::args().collect(); + if args.len() > 1 { + let run = traverse(&args) + .and_then(|paths| run_test(&paths)) + .expect("Failed to traverse directory"); + println!("{:?}", run) + } +} + +fn traverse(args: &[String]) -> Result<Vec<PathBuf>, String> { + let mut files: Vec<PathBuf> = Vec::new(); + for arg in args.iter().skip(1) { + let entries = fs::read_dir(arg).map_err(|e| e.to_string())?; + for entry in entries { + let dir = entry.map_err(|e| e.to_string())?; + let f = dir.metadata().map_err(|e| e.to_string())?; + if f.is_dir() { + files.push(dir.path()); + } + } + } + Ok(files) +} + +#[derive(Debug)] +struct TestRun { + file: String, + test_result: bool, + duration: u64, +} + +fn run_test(files: &Vec<PathBuf>) -> Result<Vec<TestRun>, String> { + let mut result = Vec::new(); + for file in files { + let mut inp = file.clone(); + let mut outp = file.clone(); + inp.push("input"); + outp.push("output"); + let (test_result, duration) = run_test_case(&inp, &outp); + result.push(TestRun { + file: inp.as_path().to_str().unwrap().to_string(), + test_result, + duration, + }); + } + Ok(result) +} + +fn run_test_case(inp: &std::path::PathBuf, outp: &std::path::PathBuf) -> (bool, u64) { + (true, 1) +} |
