Add fixture expectations and CLI scan test
This commit is contained in:
@@ -23,9 +23,23 @@ fn ruleset_dir() -> PathBuf {
|
||||
.join("rulesets")
|
||||
}
|
||||
|
||||
fn fixture_dir() -> PathBuf {
|
||||
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
manifest_dir
|
||||
.parent()
|
||||
.expect("workspace root")
|
||||
.join("tests")
|
||||
.join("fixtures")
|
||||
.join("generated")
|
||||
}
|
||||
|
||||
fn should_skip() -> bool {
|
||||
!command_available("ffmpeg") || !command_available("ffprobe")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scan_clean_fixture_has_no_issues() {
|
||||
if !command_available("ffmpeg") || !command_available("ffprobe") {
|
||||
if should_skip() {
|
||||
eprintln!("ffmpeg/ffprobe not available; skipping fixture test");
|
||||
return;
|
||||
}
|
||||
@@ -74,3 +88,76 @@ fn scan_clean_fixture_has_no_issues() {
|
||||
|
||||
assert!(scan.issues.is_empty(), "Expected no issues, got {}", scan.issues.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scan_truncated_fixture_has_errors() {
|
||||
if should_skip() {
|
||||
eprintln!("ffmpeg/ffprobe not available; skipping fixture test");
|
||||
return;
|
||||
}
|
||||
|
||||
let path = fixture_dir().join("truncated.mp4");
|
||||
if !path.exists() {
|
||||
eprintln!("fixture not found: {}; skipping", path.display());
|
||||
return;
|
||||
}
|
||||
|
||||
let config = Config::default();
|
||||
let ruleset = RuleSet::load_from_dir(&ruleset_dir()).expect("ruleset load");
|
||||
let scan = scan_file(&path, &config, &ruleset).expect("scan file");
|
||||
|
||||
let allowed = [
|
||||
"FILE_ENDED_PREMATURELY",
|
||||
"INVALID_DATA_FOUND",
|
||||
"ERROR_WHILE_DECODING",
|
||||
];
|
||||
|
||||
let matched = scan
|
||||
.issues
|
||||
.iter()
|
||||
.any(|issue| allowed.contains(&issue.code.as_str()));
|
||||
|
||||
assert!(
|
||||
matched,
|
||||
"Expected truncated fixture to match one of {:?}, got {:?}",
|
||||
allowed,
|
||||
scan.issues.iter().map(|i| i.code.clone()).collect::<Vec<_>>()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scan_corrupt_fixture_has_errors() {
|
||||
if should_skip() {
|
||||
eprintln!("ffmpeg/ffprobe not available; skipping fixture test");
|
||||
return;
|
||||
}
|
||||
|
||||
let path = fixture_dir().join("corrupt_mid.mp4");
|
||||
if !path.exists() {
|
||||
eprintln!("fixture not found: {}; skipping", path.display());
|
||||
return;
|
||||
}
|
||||
|
||||
let config = Config::default();
|
||||
let ruleset = RuleSet::load_from_dir(&ruleset_dir()).expect("ruleset load");
|
||||
let scan = scan_file(&path, &config, &ruleset).expect("scan file");
|
||||
|
||||
let allowed = [
|
||||
"INVALID_NAL_UNIT_SIZE",
|
||||
"MISSING_PICTURE_ACCESS_UNIT",
|
||||
"INVALID_DATA_FOUND",
|
||||
"ERROR_WHILE_DECODING",
|
||||
];
|
||||
|
||||
let matched = scan
|
||||
.issues
|
||||
.iter()
|
||||
.any(|issue| allowed.contains(&issue.code.as_str()));
|
||||
|
||||
assert!(
|
||||
matched,
|
||||
"Expected corrupt fixture to match one of {:?}, got {:?}",
|
||||
allowed,
|
||||
scan.issues.iter().map(|i| i.code.clone()).collect::<Vec<_>>()
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user