diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-25 17:49:35 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-26 00:20:05 +0900 |
| commit | d4ec1dcb6fc04ff029ded35cc2fcc14f3bbc02ad (patch) | |
| tree | 0a85bd085961fcdfd5570cafc3b44ba5eb8cb152 /crates/shirabe/tests/downloader/download_manager_test.rs | |
| parent | 22d0b327368e5f39de6f381046c081d08efdba15 (diff) | |
| download | php-shirabe-d4ec1dcb6fc04ff029ded35cc2fcc14f3bbc02ad.tar.gz php-shirabe-d4ec1dcb6fc04ff029ded35cc2fcc14f3bbc02ad.tar.zst php-shirabe-d4ec1dcb6fc04ff029ded35cc2fcc14f3bbc02ad.zip | |
test: port 32 command/repository/downloader tests
Add create_installed_json/create_composer_lock test helpers. Port command (8),
repository path/forgejo/perforce/vcs (11), and fossil/hg/download_manager (13)
tests. Fix production porting bugs: root_package_loader/forgejo_url/version_bumper
regex delimiters, repository_manager create_repository_by_class, array_loader
isset, licenses_command RefCell borrow; implement disk_free_space and
touch2/touch3 via libc.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/tests/downloader/download_manager_test.rs')
| -rw-r--r-- | crates/shirabe/tests/downloader/download_manager_test.rs | 109 |
1 files changed, 63 insertions, 46 deletions
diff --git a/crates/shirabe/tests/downloader/download_manager_test.rs b/crates/shirabe/tests/downloader/download_manager_test.rs index b7fa976..2405b4b 100644 --- a/crates/shirabe/tests/downloader/download_manager_test.rs +++ b/crates/shirabe/tests/downloader/download_manager_test.rs @@ -1,225 +1,242 @@ //! ref: composer/tests/Composer/Test/Downloader/DownloadManagerTest.php -fn set_up() { - // The Filesystem and IO mocks are not ported. - todo!() +use std::cell::RefCell; +use std::rc::Rc; + +use shirabe::downloader::DownloaderInterface; +use shirabe::downloader::download_manager::DownloadManager; +use shirabe::io::IOInterface; +use shirabe::package::handle::{CompletePackageHandle, PackageInterfaceHandle}; +use shirabe_semver::VersionParser; + +use crate::downloader_stub::DownloaderStub; +use crate::io_stub::IOStub; + +/// ref: DownloadManagerTest::createPackageMock +/// +/// PHPUnit returns a `PackageInterface` mock; a real CompletePackage with the +/// relevant fields left at their defaults is an equivalent stand-in for the +/// installation-source/type dispatch logic exercised by the ported cases. +fn create_package_mock() -> PackageInterfaceHandle { + let norm_version = VersionParser.normalize("1.0.0", None).unwrap(); + CompletePackageHandle::new("dummy/pkg".to_string(), norm_version, "1.0.0".to_string()).into() +} + +/// ref: DownloadManagerTest::createDownloaderMock +fn create_downloader_mock() -> Rc<RefCell<dyn DownloaderInterface>> { + Rc::new(RefCell::new(DownloaderStub::new())) as Rc<RefCell<dyn DownloaderInterface>> +} + +fn create_manager() -> DownloadManager { + let io = Rc::new(RefCell::new(IOStub::new())) as Rc<RefCell<dyn IOInterface>>; + DownloadManager::new(io, false, None) } -// These mock IO and individual downloaders to drive DownloadManager's selection/download/ -// update/remove logic; mocking is not available here. -#[ignore = "requires PHPUnit mock of DownloaderInterface (createDownloaderMock)"] #[test] fn test_set_get_downloader() { - set_up(); - todo!() + let downloader = create_downloader_mock(); + let mut manager = create_manager(); + + manager.set_downloader("test", downloader.clone()); + assert!(Rc::ptr_eq( + &downloader, + &manager.get_downloader("test").unwrap() + )); + + let result = manager.get_downloader("unregistered"); + assert!(result.is_err()); } -#[ignore = "requires PHPUnit mock of PackageInterface (createPackageMock)"] #[test] fn test_get_downloader_for_incorrectly_installed_package() { - set_up(); - todo!() + // getInstallationSource() => null (the default for a fresh package). + let package = create_package_mock(); + + let manager = create_manager(); + + let result = manager.get_downloader_for_package(package); + assert!(result.is_err()); +} + +#[test] +fn test_get_downloader_for_metapackage() { + let package = create_package_mock(); + package.__set_type("metapackage".to_string()); + + let manager = create_manager(); + + assert!( + manager + .get_downloader_for_package(package) + .unwrap() + .is_none() + ); } #[ignore = "requires PHPUnit mocks and partial mock of DownloadManager::getDownloader"] #[test] fn test_get_downloader_for_correctly_installed_dist_package() { - set_up(); todo!() } #[ignore = "requires PHPUnit mocks and partial mock of DownloadManager::getDownloader"] #[test] fn test_get_downloader_for_incorrectly_installed_dist_package() { - set_up(); todo!() } #[ignore = "requires PHPUnit mocks and partial mock of DownloadManager::getDownloader"] #[test] fn test_get_downloader_for_correctly_installed_source_package() { - set_up(); todo!() } #[ignore = "requires PHPUnit mocks and partial mock of DownloadManager::getDownloader"] #[test] fn test_get_downloader_for_incorrectly_installed_source_package() { - set_up(); - todo!() -} - -#[ignore = "requires PHPUnit mock of PackageInterface (createPackageMock)"] -#[test] -fn test_get_downloader_for_metapackage() { - set_up(); todo!() } #[ignore = "requires PHPUnit mocks and partial mock of DownloadManager::getDownloaderForPackage"] #[test] fn test_full_package_download() { - set_up(); todo!() } #[ignore = "requires PHPUnit mocks and partial mock of DownloadManager::getDownloaderForPackage"] #[test] fn test_full_package_download_failover() { - set_up(); todo!() } #[ignore = "requires PHPUnit mock of PackageInterface (createPackageMock)"] #[test] fn test_bad_package_download() { - set_up(); todo!() } #[ignore = "requires PHPUnit mocks and partial mock of DownloadManager::getDownloaderForPackage"] #[test] fn test_dist_only_package_download() { - set_up(); todo!() } #[ignore = "requires PHPUnit mocks and partial mock of DownloadManager::getDownloaderForPackage"] #[test] fn test_source_only_package_download() { - set_up(); todo!() } #[ignore = "requires PHPUnit mocks and partial mock of DownloadManager::getDownloaderForPackage"] #[test] fn test_metapackage_package_download() { - set_up(); todo!() } #[ignore = "requires PHPUnit mocks and partial mock of DownloadManager::getDownloaderForPackage"] #[test] fn test_full_package_download_with_source_preferred() { - set_up(); todo!() } #[ignore = "requires PHPUnit mocks and partial mock of DownloadManager::getDownloaderForPackage"] #[test] fn test_dist_only_package_download_with_source_preferred() { - set_up(); todo!() } #[ignore = "requires PHPUnit mocks and partial mock of DownloadManager::getDownloaderForPackage"] #[test] fn test_source_only_package_download_with_source_preferred() { - set_up(); todo!() } #[ignore = "requires PHPUnit mock of PackageInterface (createPackageMock)"] #[test] fn test_bad_package_download_with_source_preferred() { - set_up(); todo!() } #[ignore = "requires PHPUnit mocks of PackageInterface and DownloaderInterface"] #[test] fn test_update_dist_with_equal_types() { - set_up(); todo!() } #[ignore = "requires PHPUnit mocks of PackageInterface and DownloaderInterface"] #[test] fn test_update_dist_with_not_equal_types() { - set_up(); todo!() } #[ignore = "requires PHPUnit mock of PackageInterface and ReflectionMethod for private getAvailableSources"] #[test] fn test_get_available_sources_update_sticks_to_same_source() { - set_up(); todo!() } #[ignore = "requires PHPUnit mocks and partial mock of DownloadManager::getDownloaderForPackage"] #[test] fn test_update_metapackage() { - set_up(); todo!() } #[ignore = "requires PHPUnit mocks and partial mock of DownloadManager::getDownloaderForPackage"] #[test] fn test_remove() { - set_up(); todo!() } #[ignore = "requires PHPUnit mocks and partial mock of DownloadManager::getDownloaderForPackage"] #[test] fn test_metapackage_remove() { - set_up(); todo!() } #[ignore = "requires PHPUnit mocks and partial mock of DownloadManager::getDownloaderForPackage"] #[test] fn test_install_preference_without_preference_dev() { - set_up(); todo!() } #[ignore = "requires PHPUnit mocks and partial mock of DownloadManager::getDownloaderForPackage"] #[test] fn test_install_preference_without_preference_no_dev() { - set_up(); todo!() } #[ignore = "requires PHPUnit mocks and partial mock of DownloadManager::getDownloaderForPackage"] #[test] fn test_install_preference_without_match_dev() { - set_up(); todo!() } #[ignore = "requires PHPUnit mocks and partial mock of DownloadManager::getDownloaderForPackage"] #[test] fn test_install_preference_without_match_no_dev() { - set_up(); todo!() } #[ignore = "requires PHPUnit mocks and partial mock of DownloadManager::getDownloaderForPackage"] #[test] fn test_install_preference_with_match_auto_dev() { - set_up(); todo!() } #[ignore = "requires PHPUnit mocks and partial mock of DownloadManager::getDownloaderForPackage"] #[test] fn test_install_preference_with_match_auto_no_dev() { - set_up(); todo!() } #[ignore = "requires PHPUnit mocks and partial mock of DownloadManager::getDownloaderForPackage"] #[test] fn test_install_preference_with_match_source() { - set_up(); todo!() } #[ignore = "requires PHPUnit mocks and partial mock of DownloadManager::getDownloaderForPackage"] #[test] fn test_install_preference_with_match_dist() { - set_up(); todo!() } |
