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

Function test_find_files_for_databases

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

Source from the content-addressed store, hash-verified

420 fs::{OpenOptions, create_dir},
421 };
422
423 use rstest::rstest;
424 use testresult::TestResult;
425
426 use super::*;
427
428 const PKG_NAMES: &[&str] = &[
429 "pipewire-alsa-1:1.0.7-1-x86_64",
430 "xorg-xvinfo-1.1.5-1-x86_64",
431 "acl-2.3.2-1-x86_64",
432 "archlinux-keyring-20240520-1-any",
433 ];
434
435 /// Ensure that files can be found in case they're nested inside
436 /// sub-subdirectories if the directory structure is:
437 /// `target-dir/packages/${pacman-repo}/${package-name}`
438 #[rstest]
439 #[case(TestFileFormat::Buildinfo)]
440 #[case(TestFileFormat::Pkginfo)]
441 #[case(TestFileFormat::MTree)]
442 fn test_find_files_for_packages(#[case] file_type: TestFileFormat) -> TestResult {
443 // Create a temporary directory for testing.
444 let tmp_dir = tempfile::tempdir()?;
445 let packages_dir = tmp_dir.path().join(PACKAGES_DIR);
446 create_dir(&packages_dir)?;
447
448 // The list of files we're expecting to find.
449 let mut expected_files = HashSet::new();
450
451 // Create a test file for each repo.
452 for (index, repo) in PackageRepositories::iter().enumerate() {
453 // Create the repository folder
454 let repo_dir = packages_dir.join(repo.to_string());
455 create_dir(&repo_dir)?;
456
457 // Create a package subfolder inside that repository folder.
458 let pkg = PKG_NAMES[index];
459 let pkg_dir = repo_dir.join(pkg);
460 create_dir(&pkg_dir)?;
461
462 // Touch the file inside the package folder.
463 let file_path = pkg_dir.join(file_type.to_string());
464 OpenOptions::new()
465 .create(true)
466 .write(true)
467 .truncate(true)
468 .open(&file_path)?;
469 expected_files.insert(file_path);

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