use captains_log::{parser::LogParser, Builder};
use std::fs::remove_file;
pub const TEST_LOCK_FILE: &str = "/tmp/natualio_test_lock";
#[macro_export]
macro_rules! lock_file {
() => {
let lock_fd = OpenOptions::new().create(true).write(true).open(&TEST_LOCK_FILE).unwrap();
let _guard = fmutex::lock_exclusive(&lock_fd).unwrap();
};
}
#[allow(dead_code)]
pub fn clear_test_files(builder: &Builder) {
for sink in &builder.sinks {
if let Some(file_path) = sink.get_file_path() {
let _ = remove_file(file_path);
}
}
}
#[allow(dead_code)]
pub fn parse_log(file_path: &str, re: &str) -> std::io::Result<Vec<Vec<String>>> {
let parser = LogParser::new(file_path, re, 1024)?;
let mut lines = Vec::with_capacity(1024);
for line in parser.lines() {
let _line = line?;
lines.push(_line);
}
Ok(lines)
}