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

Function test_find_files_for_packages

dev-scripts/src/testing.rs:370–414  ·  view source on GitHub ↗
(#[case] file_type: TestFileType)

Source from the content-addressed store, hash-verified

368 #[case(TestFileType::PackageInfo)]
369 #[case(TestFileType::MTree)]
370 fn test_find_files_for_packages(#[case] file_type: TestFileType) -> TestResult {
371 // Create a temporary directory for testing.
372 let tmp_dir = tempfile::tempdir()?;
373 let packages_dir = tmp_dir.path().join(PACKAGES_DIR);
374 create_dir(&packages_dir)?;
375
376 // The list of files we're expecting to find.
377 let mut expected_files = HashSet::new();
378
379 // Create a test file for each repo.
380 for (index, repo) in PackageRepositories::iter().enumerate() {
381 // Create the repository folder
382 let repo_dir = packages_dir.join(repo.to_string());
383 create_dir(&repo_dir)?;
384
385 // Create a package subfolder inside that repository folder.
386 let pkg = PKG_NAMES[index];
387 let pkg_dir = repo_dir.join(pkg);
388 create_dir(&pkg_dir)?;
389
390 // Touch the file inside the package folder.
391 let file_path = pkg_dir.join(file_type.to_string());
392 OpenOptions::new()
393 .create(true)
394 .write(true)
395 .truncate(true)
396 .open(&file_path)?;
397 expected_files.insert(file_path);
398 }
399
400 // Run the logic to find the files in question.
401 let runner = TestRunner {
402 cache_dir: CacheDir::from(tmp_dir.path().to_owned()),
403 file_type,
404 repositories: PackageRepositories::iter().collect(),
405 };
406 let found_files = HashSet::from_iter(runner.find_files_of_type()?.into_iter());
407
408 assert_eq!(
409 found_files, expected_files,
410 "Expected that all created package files are also found."
411 );
412
413 Ok(())
414 }
415
416 /// Ensure that files can be found in case they're nested inside
417 /// sub-subdirectories if the directory structure is:

Callers

nothing calls this directly

Calls 5

writeMethod · 0.80
find_files_of_typeMethod · 0.80
joinMethod · 0.45
pathMethod · 0.45
into_iterMethod · 0.45

Tested by

no test coverage detected