Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 additions & 17 deletions src-tauri/tests/cmtlog_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,24 @@ mod common;

use std::fs;
use std::path::PathBuf;
use std::time::{SystemTime, UNIX_EPOCH};

use tempfile::TempDir;

struct TempLogFixture {
dir: PathBuf,
/// Held so the directory outlives the fixture; `TempDir` removes it on drop.
_dir: TempDir,
path: PathBuf,
}

impl TempLogFixture {
fn new(file_name: &str, content: &str) -> Self {
let unique = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("system time before unix epoch")
.as_nanos();
let dir = std::env::temp_dir().join(format!("cmtrace-open-cmtlog-test-{unique}"));
fs::create_dir_all(&dir).expect("create temp fixture dir");

let path = dir.join(file_name);
let dir =
TempDir::with_prefix("cmtrace-open-cmtlog-test-").expect("create temp fixture dir");

let path = dir.path().join(file_name);
fs::write(&path, content).expect("write temp fixture");

Self { dir, path }
Self { _dir: dir, path }
}

fn detect(&self) -> app_lib::parser::ResolvedParser {
Expand All @@ -30,12 +28,6 @@ impl TempLogFixture {
}
}

impl Drop for TempLogFixture {
fn drop(&mut self) {
let _ = fs::remove_dir_all(&self.dir);
}
}

fn fixture_content() -> &'static str {
concat!(
"<![LOG[Script started: Detect-WDAC.ps1 v2.1.0]LOG]!><time=\"10:30:00.000+000\" date=\"04-13-2026\" component=\"__HEADER__\" context=\"\" type=\"1\" thread=\"0\" file=\"\" script=\"Detect-WDAC.ps1\" version=\"2.1.0\" runid=\"a3f8c9e1\" mode=\"Normal\" ps_version=\"7.4.2\">\n",
Expand Down
25 changes: 8 additions & 17 deletions src-tauri/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,23 @@
use std::fmt::Write;
use std::fs;
use std::path::{Path, PathBuf};
use std::time::{SystemTime, UNIX_EPOCH};

use tempfile::TempDir;

pub struct TempBenchFile {
dir: PathBuf,
/// Held so the directory outlives the fixture; `TempDir` removes it on drop.
_dir: TempDir,
path: PathBuf,
}

impl TempBenchFile {
pub fn new(file_name: &str, content: String) -> Self {
let unique = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("system time before unix epoch")
.as_nanos();
let dir = std::env::temp_dir().join(format!("cmtrace-open-bench-{unique}"));
fs::create_dir_all(&dir).expect("create temp benchmark dir");

let path = dir.join(file_name);
let dir = TempDir::with_prefix("cmtrace-open-bench-").expect("create temp benchmark dir");

let path = dir.path().join(file_name);
fs::write(&path, content).expect("write benchmark fixture");

Self { dir, path }
Self { _dir: dir, path }
}

pub fn path(&self) -> &Path {
Expand All @@ -34,12 +31,6 @@ impl TempBenchFile {
}
}

impl Drop for TempBenchFile {
fn drop(&mut self) {
let _ = fs::remove_dir_all(&self.dir);
}
}

pub struct IntuneBenchFixture {
file: TempBenchFile,
pub logical_record_count: usize,
Expand Down
23 changes: 7 additions & 16 deletions src-tauri/tests/parser_expanded_corpus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,25 @@ mod common;
use common::{detect_fixture, parse_fixture};
use std::fs;
use std::path::PathBuf;
use std::time::{SystemTime, UNIX_EPOCH};

use tempfile::TempDir;

// ---------------------------------------------------------------------------
// Helper: create a temp file for detection/parsing tests
// ---------------------------------------------------------------------------

struct TempLogFixture {
dir: PathBuf,
/// Held so the directory outlives the fixture; `TempDir` removes it on drop.
_dir: TempDir,
path: PathBuf,
}

impl TempLogFixture {
fn new(file_name: &str, content: &str) -> Self {
let unique = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("system time")
.as_nanos();
let dir = std::env::temp_dir().join(format!("cmtrace-open-expanded-{unique}"));
fs::create_dir_all(&dir).expect("create temp dir");
let path = dir.join(file_name);
let dir = TempDir::with_prefix("cmtrace-open-expanded-").expect("create temp dir");
let path = dir.path().join(file_name);
fs::write(&path, content).expect("write fixture");
Self { dir, path }
Self { _dir: dir, path }
}

fn detect(&self) -> common::SelectionSnapshot {
Expand Down Expand Up @@ -63,12 +60,6 @@ impl TempLogFixture {
}
}

impl Drop for TempLogFixture {
fn drop(&mut self) {
let _ = fs::remove_dir_all(&self.dir);
}
}

fn snapshot(s: &app_lib::parser::ResolvedParser) -> common::SelectionSnapshot {
common::SelectionSnapshot {
parser: format!("{:?}", s.parser),
Expand Down
26 changes: 9 additions & 17 deletions src-tauri/tests/parser_regression_corpus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,26 @@ mod common;

use std::fs;
use std::path::PathBuf;
use std::time::{SystemTime, UNIX_EPOCH};

use tempfile::TempDir;

use common::{detect_fixture, parse_fixture, ParsedFixture, SelectionSnapshot};

struct TempLogFixture {
dir: PathBuf,
/// Held so the directory outlives the fixture; `TempDir` removes it on drop.
_dir: TempDir,
path: PathBuf,
}

impl TempLogFixture {
fn new(file_name: &str, content: &str) -> Self {
let unique = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("system time before unix epoch")
.as_nanos();
let dir = std::env::temp_dir().join(format!("cmtrace-open-parser-regression-{unique}"));
fs::create_dir_all(&dir).expect("create temp fixture dir");

let path = dir.join(file_name);
let dir = TempDir::with_prefix("cmtrace-open-parser-regression-")
.expect("create temp fixture dir");

let path = dir.path().join(file_name);
fs::write(&path, content).expect("write temp fixture");

Self { dir, path }
Self { _dir: dir, path }
}

fn detect(&self) -> SelectionSnapshot {
Expand Down Expand Up @@ -65,12 +63,6 @@ impl TempLogFixture {
}
}

impl Drop for TempLogFixture {
fn drop(&mut self) {
let _ = fs::remove_dir_all(&self.dir);
}
}

fn selection_snapshot(selection: &app_lib::parser::ResolvedParser) -> SelectionSnapshot {
SelectionSnapshot {
parser: format!("{:?}", selection.parser),
Expand Down
Loading