2024-07-12 15:09:39 +09:00
|
|
|
mod integrated_test {
|
2024-07-21 20:29:42 +09:00
|
|
|
use std::{
|
|
|
|
fs::File,
|
|
|
|
io::{BufRead, BufReader},
|
|
|
|
path::PathBuf,
|
|
|
|
};
|
2024-07-12 15:09:39 +09:00
|
|
|
|
|
|
|
use anyhow::Result;
|
|
|
|
use assert_cmd::{assert::OutputAssertExt, Command};
|
|
|
|
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
|
2024-07-21 21:04:46 +09:00
|
|
|
let mut cmd = Command::cargo_bin("psb-qaqc")?;
|
2024-07-12 15:09:39 +09:00
|
|
|
cmd.current_dir("tests")
|
2024-07-21 21:04:46 +09:00
|
|
|
.arg("add-master-log")
|
2024-07-21 19:53:51 +09:00
|
|
|
.arg("./example_logs/valid/20240720_171418.log")
|
2024-07-12 15:09:39 +09:00
|
|
|
.arg(test_out.as_path())
|
|
|
|
.assert()
|
2024-07-14 11:12:01 +09:00
|
|
|
.success()
|
|
|
|
.stdout(predicate::str::contains("Creating new file"));
|
2024-07-12 15:09:39 +09:00
|
|
|
|
2024-07-21 20:29:42 +09:00
|
|
|
// check output
|
|
|
|
{
|
|
|
|
let f = File::open(test_out.clone())?;
|
|
|
|
let r = BufReader::new(f);
|
|
|
|
assert!(r
|
|
|
|
.lines()
|
|
|
|
.any(|line| { line.unwrap().contains("8868,,A-0-1,0,1,1,0,1,8,1,") }));
|
|
|
|
}
|
|
|
|
|
2024-07-21 19:53:51 +09:00
|
|
|
// 2nd file
|
2024-07-21 21:04:46 +09:00
|
|
|
let mut cmd = Command::cargo_bin("psb-qaqc")?;
|
2024-07-21 19:53:51 +09:00
|
|
|
cmd.current_dir("tests")
|
2024-07-21 21:04:46 +09:00
|
|
|
.arg("add-master-log")
|
2024-07-21 19:53:51 +09:00
|
|
|
.arg("./example_logs/valid/20240720_171418.log")
|
|
|
|
.arg(test_out.as_path())
|
|
|
|
.assert()
|
|
|
|
.success();
|
|
|
|
|
2024-07-12 15:09:39 +09:00
|
|
|
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");
|
|
|
|
|
2024-07-21 21:04:46 +09:00
|
|
|
let mut cmd = Command::cargo_bin("psb-qaqc")?;
|
2024-07-12 15:09:39 +09:00
|
|
|
cmd.current_dir("tests")
|
2024-07-21 21:04:46 +09:00
|
|
|
.arg("add-master-log")
|
2024-07-21 19:53:51 +09:00
|
|
|
.arg("./example_logs/valid/20240720_171419.log")
|
2024-07-12 15:09:39 +09:00
|
|
|
.arg(test_out.as_path())
|
|
|
|
.assert()
|
2024-07-14 11:12:01 +09:00
|
|
|
.success()
|
|
|
|
.stdout(predicate::str::contains("Creating new file"));
|
2024-07-12 15:09:39 +09:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|