use std::{fs::read_to_string, path::PathBuf};
use alpm_srcinfo::{MergedPackage, SourceInfoV1};
use alpm_types::SystemArchitecture;
use insta::assert_snapshot;
use rstest::rstest;
use testresult::TestResult;
#[rstest]
fn correct_files(#[files("tests/correct/*.srcinfo")] case: PathBuf) -> TestResult {
let input = read_to_string(&case)?;
let source_info_result = SourceInfoV1::from_string(input.as_str());
let source_info_result = match source_info_result {
Ok(result) => result,
Err(err) => {
panic!(
"The parser errored even though it should've succeeded the parsing step:\n{err}"
);
}
};
let source_info = source_info_result;
let source_info_json = serde_json::to_string_pretty(&source_info)?;
let test_name = case.file_stem().unwrap().to_str().unwrap().to_string();
insta::with_settings!({
description => format!("{test_name} SourceInfo representation."),
snapshot_path => "correct_snapshots",
prepend_module_to_snapshot => false,
}, {
assert_snapshot!(format!("{test_name}_source_info"), source_info_json );
});
let packages = source_info
.packages_for_architecture(SystemArchitecture::X86_64)
.collect::<Vec<MergedPackage>>();
let package_json = serde_json::to_string_pretty(&packages)?;
if package_json.contains("unexpected") {
panic!(
"Found 'unexpected' keyword in json output. {}:\n{package_json}",
"This indicates that data was included that shouldn't be in there"
);
}
if package_json.contains("beefc0ffee") {
panic!(
"Found 'beefc0ffee' keyword in json output. {}:\n{package_json}",
"This indicates that an checksum was included that shouldn't be in there"
);
}
insta::with_settings!({
description => format!("{test_name} merged representation."),
snapshot_path => "correct_snapshots",
prepend_module_to_snapshot => false,
}, {
assert_snapshot!(format!("{test_name}_merged"), package_json);
});
Ok(())
}