use std::path::Path; use std::io::BufRead; pub struct ExampleRequest { pub method: String, pub path_and_query: String, pub body: Option, } pub fn load_request_by_name(name: &str) -> ExampleRequest { let path = format!("tests/files/{}.txt", name); let path = Path::new(&path); load_request(&path) } pub fn load_request(path: &Path) -> ExampleRequest { let file = std::fs::File::open(path).unwrap(); let mut lines = std::io::BufReader::new(file).lines(); let first_line: Vec = lines.next().unwrap().unwrap().split(" ").map(|v| v.into()).collect(); let body: Vec = lines.map(|v| v.into()).collect::, _>>().unwrap(); let body: Option = if body.len() <= 1 { None } else { Some(body.join("\n")) }; ExampleRequest { method: first_line[0].clone(), path_and_query: first_line[1].clone(), body: body, } }