MCPcopy Create free account
hub / github.com/archlinux/alpm / correct_files

Function correct_files

alpm-srcinfo/tests/correct.rs:28–92  ·  view source on GitHub ↗
(#[files("tests/correct/*.srcinfo")] case: PathBuf)

Source from the content-addressed store, hash-verified

26/// the SRCINFO file. The script also takes care of creating those files.
27#[rstest]
28fn correct_files(#[files("tests/correct/*.srcinfo")] case: PathBuf) -> TestResult {
29 // Read the input file and parse it.
30 let input = read_to_string(&case)?;
31 let source_info_result = SourceInfoV1::from_string(input.as_str());
32
33 // Make sure there're no parse errors
34 let source_info_result = match source_info_result {
35 Ok(result) => result,
36 Err(err) => {
37 panic!(
38 "The parser errored even though it should've succeeded the parsing step:\n{err}"
39 );
40 }
41 };
42
43 // Parse the source info
44 let source_info = source_info_result;
45
46 let source_info_json = serde_json::to_string_pretty(&source_info)?;
47
48 let test_name = case.file_stem().unwrap().to_str().unwrap().to_string();
49 // Compare the generated source_info json with the expected snapshot.
50 // Remove the usual module prefix by explicitly setting the snapshot path.
51 // This is necessary, as we're manually sorting snapshots by test scenario.
52 insta::with_settings!({
53 description => format!("{test_name} SourceInfo representation."),
54 snapshot_path => "correct_snapshots",
55 prepend_module_to_snapshot => false,
56 }, {
57 assert_snapshot!(format!("{test_name}_source_info"), source_info_json );
58 });
59
60 let packages = source_info
61 .packages_for_architecture(SystemArchitecture::X86_64)
62 .collect::<Vec<MergedPackage>>();
63
64 let package_json = serde_json::to_string_pretty(&packages)?;
65
66 if package_json.contains("unexpected") {
67 panic!(
68 "Found 'unexpected' keyword in json output. {}:\n{package_json}",
69 "This indicates that data was included that shouldn't be in there"
70 );
71 }
72
73 if package_json.contains("beefc0ffee") {
74 panic!(
75 "Found 'beefc0ffee' keyword in json output. {}:\n{package_json}",
76 "This indicates that an checksum was included that shouldn't be in there"
77 );
78 }
79
80 // Compare the generated merged json with the expected snapshot.
81 // Remove the usual module prefix by explicitly setting the snapshot path.
82 // This is necessary, as we're manually sorting snapshots by test scenario.
83 insta::with_settings!({
84 description => format!("{test_name} merged representation."),
85 snapshot_path => "correct_snapshots",

Callers

nothing calls this directly

Calls 3

containsMethod · 0.80
as_strMethod · 0.45

Tested by

no test coverage detected