Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jgcrosta committed Dec 13, 2024
1 parent a64c10e commit 3669264
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
10 changes: 10 additions & 0 deletions apps/cargo-scout-audit/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions apps/cargo-scout-audit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ tracing-log = "=0.2.0"
tracing-subscriber = { version = "=0.3.18", features = ["env-filter", "registry"] }
webbrowser = "=1.0.1"

[dev-dependencies]
uuid = { version = "1.3.1", features = ["v4"] }

[build-dependencies]
regex = "*"
sha2 = "0.10.8"
Expand Down
21 changes: 14 additions & 7 deletions apps/cargo-scout-audit/tests/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#[cfg(test)]
mod tests {
use anyhow::{Context, Result};
use anyhow::Result;
use cargo_scout_audit::{
cli::{OutputFormat, Scout},
startup::run_scout,
};
use lazy_static::lazy_static;
use std::{collections::HashMap, fs, path::PathBuf};
use tempfile::TempDir;
use uuid::Uuid;

lazy_static! {
static ref TEST_DIR: TempDir = TempDir::new().expect("Failed to create temp directory");
}

lazy_static! {
static ref DETECTORS_DIR: PathBuf = {
Expand Down Expand Up @@ -112,13 +118,14 @@ mod tests {
}
}

fn test_output_fn(file: &str, format: OutputFormat) -> Result<()> {
test_output_format(file, &format)
.with_context(|| format!("Failed to test {:?} format", &format))?;
fs::remove_file(file)
.unwrap_or_else(|_| panic!("Should be able to delete the file: {}", file));
fn test_output_fn(base_name: &str, format: OutputFormat) -> Result<()> {
let unique_name = format!("{}_{}", Uuid::new_v4(), base_name);
let file_path = TEST_DIR.path().join(unique_name);

Ok(())
let result = test_output_format(&file_path.to_string_lossy(), &format);
let _ = fs::remove_file(&file_path);

result
}

#[test]
Expand Down

0 comments on commit 3669264

Please sign in to comment.