auto-generate cache if it does not exist
All checks were successful
CI/CD Pipeline / test (push) Successful in 1m55s
All checks were successful
CI/CD Pipeline / test (push) Successful in 1m55s
This commit is contained in:
parent
a9316ee398
commit
a32b3a66c7
@ -115,28 +115,32 @@ fn fetch_page(overview_id: usize, page: usize) -> Result<String, Error> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::overview::parse;
|
||||
use crate::{config::Config, overview::parse};
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::fs;
|
||||
|
||||
#[test]
|
||||
fn overview() {
|
||||
let paths = fs::read_dir("./data/expected/overview/")
|
||||
.expect("No folder with expected overview files");
|
||||
let configs = fs::read_dir("./data/configs").expect("No folder with config files");
|
||||
|
||||
for path in paths {
|
||||
let path = path.unwrap();
|
||||
let file_path = format!("{}", path.path().display());
|
||||
let law_id = path.file_name().into_string().unwrap().to_string();
|
||||
let law_id: usize = law_id
|
||||
.parse()
|
||||
.expect("Filename needs to be usize (= law_id in RIS)");
|
||||
for config in configs {
|
||||
let path = format!("{}", config.unwrap().path().display());
|
||||
|
||||
let expected = fs::read_to_string(file_path).expect("Could not read file {file_path}.");
|
||||
let expected = expected.trim().split('\n').collect::<Vec<&str>>();
|
||||
let (law_id, _, _) = Config::load(&path).unwrap();
|
||||
|
||||
let actual = parse(law_id).unwrap();
|
||||
assert_eq!(actual, expected);
|
||||
let expected_path = format!("./data/expected/overview/{law_id}");
|
||||
match fs::read_to_string(&expected_path) {
|
||||
Ok(expected) => {
|
||||
let expected = expected.trim().split('\n').collect::<Vec<&str>>();
|
||||
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
Err(_) => {
|
||||
let to_write = actual.join("\n");
|
||||
fs::write(expected_path, to_write).expect("Unable to write file");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user