mirror of
https://gitlab.cern.ch/wotsubo/psboard-qaqc-postprocess.git
synced 2024-11-24 16:11:11 +09:00
Wataru Otsubo
2dc790f9a8
- old add-master-log is now convert-master-log - add-master-log is now interactive - add-master-log is not well tested
96 lines
2.7 KiB
Rust
96 lines
2.7 KiB
Rust
mod integrated_test {
|
|
use std::{
|
|
env::current_dir,
|
|
ffi::OsString,
|
|
fs::{self, read_dir, File},
|
|
io::{BufRead, BufReader},
|
|
path::PathBuf,
|
|
};
|
|
|
|
use anyhow::{Context, 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("convert-master-log")
|
|
.arg("./example_logs/valid/44.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(
|
|
"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);
|
|
}
|
|
|
|
// 2nd file
|
|
let mut cmd = Command::cargo_bin("psb-qaqc")?;
|
|
cmd.current_dir("tests")
|
|
.arg("convert-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()?;
|
|
fs::copy(
|
|
"./tests/example_logs/valid/84.log",
|
|
test_out_dir.join("84.log"),
|
|
)
|
|
.context("Error preparing source file")?;
|
|
|
|
let mut cmd = Command::cargo_bin("psb-qaqc")?;
|
|
cmd.current_dir(&test_out_dir)
|
|
.arg("convert-master-log")
|
|
.arg("84.log")
|
|
.assert()
|
|
.success()
|
|
.stdout(predicate::str::contains("Creating new file"));
|
|
|
|
assert!(read_dir(&test_out_dir)
|
|
.context("Failed to read dir")?
|
|
.any(|entry| {
|
|
entry
|
|
.map_or(OsString::from(""), |entry| entry.file_name())
|
|
.eq("out_84.csv")
|
|
}));
|
|
|
|
Ok(())
|
|
}
|
|
}
|