psboard-qaqc-postprocess/tests/cli.rs

84 lines
2.4 KiB
Rust
Raw Normal View History

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");
2024-07-21 19:53:51 +09:00
// 1st file
let mut cmd = Command::cargo_bin("psb-qaqc")?;
cmd.current_dir("tests")
.arg("add-master-log")
.arg("./example_logs/valid/44.log")
.arg(test_out.as_path())
.assert()
2024-07-14 11:12:01 +09:00
.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(
"214,,B-0-1,1,1,1,1,1,0,1,,44,2024-07-25T08:41:27Z,44.log,1.0.1,Bob,,,,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);
}
2024-07-21 19:53:51 +09:00
// 2nd file
let mut cmd = Command::cargo_bin("psb-qaqc")?;
2024-07-21 19:53:51 +09:00
cmd.current_dir("tests")
.arg("add-master-log")
2024-07-23 22:51:48 +09:00
.arg("./example_logs/valid/20.log")
2024-07-21 19:53:51 +09:00
.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()
2024-07-14 11:12:01 +09:00
.success()
.stdout(predicate::str::contains("Creating new file"));
Ok(())
}
}