2024-07-12 15:09:39 +09:00
|
|
|
mod integrated_test {
|
2024-07-21 20:29:42 +09:00
|
|
|
use std::{
|
2024-07-25 23:34:27 +09:00
|
|
|
env::current_dir,
|
|
|
|
ffi::OsString,
|
|
|
|
fs::{self, read_dir, File},
|
2024-07-21 20:29:42 +09:00
|
|
|
io::{BufRead, BufReader},
|
|
|
|
path::PathBuf,
|
|
|
|
};
|
2024-07-12 15:09:39 +09:00
|
|
|
|
2024-07-25 23:34:27 +09:00
|
|
|
use anyhow::{Context, Result};
|
2024-07-21 21:23:32 +09:00
|
|
|
use assert_cmd::Command;
|
2024-07-23 22:38:22 +09:00
|
|
|
use itertools::Itertools;
|
2024-07-12 15:09:39 +09:00
|
|
|
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-09-10 23:01:20 +09:00
|
|
|
.arg("convert-master-log")
|
2024-07-25 20:07:28 +09:00
|
|
|
.arg("./example_logs/valid/44.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
|
|
|
|
{
|
2024-07-23 22:38:22 +09:00
|
|
|
// check output content
|
2024-07-21 20:29:42 +09:00
|
|
|
let f = File::open(test_out.clone())?;
|
|
|
|
let r = BufReader::new(f);
|
2024-07-23 22:38:22 +09:00
|
|
|
assert!(r.lines().any(|line| {
|
2024-07-25 13:36:20 +09:00
|
|
|
line.unwrap().eq(
|
2024-07-25 20:07:28 +09:00
|
|
|
"214,,B-0-1,1,1,1,1,1,0,1,,44,2024-07-25T08:41:27Z,44.log,1.0.1,Bob,,,,false,",
|
2024-07-23 22:38:22 +09:00
|
|
|
)
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
// 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 20:29:42 +09:00
|
|
|
}
|
|
|
|
|
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-09-10 23:01:20 +09:00
|
|
|
.arg("convert-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();
|
|
|
|
|
2024-07-21 21:23:32 +09:00
|
|
|
// check
|
|
|
|
let mut cmd = Command::cargo_bin("psb-qaqc")?;
|
|
|
|
cmd.current_dir("tests")
|
|
|
|
.arg("check-db")
|
|
|
|
.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()?;
|
2024-07-25 23:34:27 +09:00
|
|
|
fs::copy(
|
|
|
|
"./tests/example_logs/valid/84.log",
|
|
|
|
test_out_dir.join("84.log"),
|
|
|
|
)
|
|
|
|
.context("Error preparing source file")?;
|
2024-07-12 15:09:39 +09:00
|
|
|
|
2024-07-21 21:04:46 +09:00
|
|
|
let mut cmd = Command::cargo_bin("psb-qaqc")?;
|
2024-07-25 23:34:27 +09:00
|
|
|
cmd.current_dir(&test_out_dir)
|
2024-09-10 23:01:20 +09:00
|
|
|
.arg("convert-master-log")
|
2024-07-25 23:34:27 +09:00
|
|
|
.arg("84.log")
|
2024-07-12 15:09:39 +09:00
|
|
|
.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-25 23:34:27 +09:00
|
|
|
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")
|
|
|
|
}));
|
|
|
|
|
2024-07-12 15:09:39 +09:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|