psboard-qaqc-postprocess/tests/cli.rs
Wataru Otsubo 46487320b0 update: accept abnormal resistance as valid row in check-db
- this commits includes 2 other implementations
  - 1st one with custom type with `impl Read` for Lazy evaluation
    - this somehow ended up in infinite loop
  - 2nd one which collects lines without skipped lines first
    - this works
- the current implementations has another File and catches invalid row
  and check the line later
2024-07-25 13:36:20 +09:00

83 lines
2.4 KiB
Rust

mod integrated_test {
use std::{
fs::File,
io::{BufRead, BufReader},
path::PathBuf,
};
use anyhow::Result;
use assert_cmd::Command;
use itertools::Itertools;
use predicates::prelude::*;
#[test]
fn full_log() -> Result<()> {
let test_out_dir = assert_fs::TempDir::new()?;
let test_out = PathBuf::new().join(&test_out_dir).join("out.csv");
// 1st file
let mut cmd = Command::cargo_bin("psb-qaqc")?;
cmd.current_dir("tests")
.arg("add-master-log")
.arg("./example_logs/valid/7.log")
.arg(test_out.as_path())
.assert()
.success()
.stdout(predicate::str::contains("Creating new file"));
// check output
{
// check output content
let f = File::open(test_out.clone())?;
let r = BufReader::new(f);
assert!(r.lines().any(|line| {
line.unwrap().eq(
"8866,,B-0-1,0,1,1,0,1,8,1,,7,2024-07-20T17:15:46Z,7.log,0.1.0,alice,,,,false,",
)
}));
}
{
// Check output lines count
let f = File::open(test_out.clone())?;
let r = BufReader::new(f);
let lc = r.lines().collect_vec().len();
assert_eq!(lc, 19);
}
// 2nd file
let mut cmd = Command::cargo_bin("psb-qaqc")?;
cmd.current_dir("tests")
.arg("add-master-log")
.arg("./example_logs/valid/20.log")
.arg(test_out.as_path())
.assert()
.success();
// check
let mut cmd = Command::cargo_bin("psb-qaqc")?;
cmd.current_dir("tests")
.arg("check-db")
.arg(test_out.as_path())
.assert()
.success();
Ok(())
}
#[test]
fn partial_log() -> Result<()> {
let test_out_dir = assert_fs::TempDir::new()?;
let test_out = PathBuf::new().join(&test_out_dir).join("out.csv");
let mut cmd = Command::cargo_bin("psb-qaqc")?;
cmd.current_dir("tests")
.arg("add-master-log")
.arg("./example_logs/valid/84.log")
.arg(test_out.as_path())
.assert()
.success()
.stdout(predicate::str::contains("Creating new file"));
Ok(())
}
}