diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-21 03:16:34 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-21 03:17:45 +0900 |
| commit | 903d37a254f931e79ecded26f30a3b517c6d27da (patch) | |
| tree | 4cd32e55466dd463e10aef35e8fad239dd08938a /crates | |
| parent | d9eb06c836e1faa759225a9653181b1dcd38a52d (diff) | |
| download | php-shirabe-903d37a254f931e79ecded26f30a3b517c6d27da.tar.gz php-shirabe-903d37a254f931e79ecded26f30a3b517c6d27da.tar.zst php-shirabe-903d37a254f931e79ecded26f30a3b517c6d27da.zip | |
test(repository): port InstalledRepositoryTest
testAddRepository maps the expected LogicException to #[should_panic]
since InstalledRepository::add_repository guards with assert!.
testFindPackagesWithReplacersAndProviders is #[ignore] because that
assert omits InstalledRepositoryInterface, so adding an
InstalledArrayRepository panics before the lookup runs.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/shirabe/tests/advisory/audit_config_test.rs | 5 | ||||
| -rw-r--r-- | crates/shirabe/tests/common/test_case.rs | 5 | ||||
| -rw-r--r-- | crates/shirabe/tests/platform/version_test.rs | 7 | ||||
| -rw-r--r-- | crates/shirabe/tests/repository/array_repository_test.rs | 40 | ||||
| -rw-r--r-- | crates/shirabe/tests/repository/composite_repository_test.rs | 9 | ||||
| -rw-r--r-- | crates/shirabe/tests/repository/installed_repository_test.rs | 85 | ||||
| -rw-r--r-- | crates/shirabe/tests/repository/main.rs | 1 | ||||
| -rw-r--r-- | crates/shirabe/tests/util/http/request_proxy_test.rs | 53 | ||||
| -rw-r--r-- | crates/shirabe/tests/util/package_sorter_test.rs | 7 | ||||
| -rw-r--r-- | crates/shirabe/tests/util/zip_test.rs | 15 |
10 files changed, 198 insertions, 29 deletions
diff --git a/crates/shirabe/tests/advisory/audit_config_test.rs b/crates/shirabe/tests/advisory/audit_config_test.rs index c50ccd3..008fb4f 100644 --- a/crates/shirabe/tests/advisory/audit_config_test.rs +++ b/crates/shirabe/tests/advisory/audit_config_test.rs @@ -107,7 +107,10 @@ fn test_mixed_formats() { ("CVE-2024-5678", s("Simple reason")), ( "CVE-2024-9999", - arr(vec![("apply", s("audit")), ("reason", s("Detailed reason"))]), + arr(vec![ + ("apply", s("audit")), + ("reason", s("Detailed reason")), + ]), ), ("CVE-2024-8888", arr(vec![("apply", s("block"))])), ]), diff --git a/crates/shirabe/tests/common/test_case.rs b/crates/shirabe/tests/common/test_case.rs index 6fe1358..71c49a9 100644 --- a/crates/shirabe/tests/common/test_case.rs +++ b/crates/shirabe/tests/common/test_case.rs @@ -17,7 +17,10 @@ pub fn get_package(name: &str, version: &str) -> PackageInterfaceHandle { } /// ref: TestCase::getAliasPackage (default class CompleteAliasPackage) -pub fn get_alias_package(package: &PackageInterfaceHandle, version: &str) -> PackageInterfaceHandle { +pub fn get_alias_package( + package: &PackageInterfaceHandle, + version: &str, +) -> PackageInterfaceHandle { let norm_version = VersionParser.normalize(version, None).unwrap(); let complete = CompletePackageHandle::from_rc_unchecked(package.as_rc().clone()); CompleteAliasPackageHandle::new(complete, norm_version, version.to_string()).into() diff --git a/crates/shirabe/tests/platform/version_test.rs b/crates/shirabe/tests/platform/version_test.rs index aada5f9..c2511d5 100644 --- a/crates/shirabe/tests/platform/version_test.rs +++ b/crates/shirabe/tests/platform/version_test.rs @@ -35,7 +35,12 @@ fn provide_openssl_versions() -> Vec<(&'static str, &'static str, bool, Option<& ("1.2.3zh-fips", "1.2.3.34", true, None), ("1.2.3zh-fips-dev", "1.2.3.34-dev", true, None), // Additional cases - ("1.2.3zh-fips-rc3", "1.2.3.34-rc3", true, Some("1.2.3.34-RC3")), + ( + "1.2.3zh-fips-rc3", + "1.2.3.34-rc3", + true, + Some("1.2.3.34-RC3"), + ), ("1.2.3zh-alpha10-fips", "1.2.3.34-alpha10", true, None), ("1.1.1l (Schannel)", "1.1.1.12", false, None), // Check that alphabetical patch levels overflow correctly diff --git a/crates/shirabe/tests/repository/array_repository_test.rs b/crates/shirabe/tests/repository/array_repository_test.rs index ae34d4d..ee6dfb9 100644 --- a/crates/shirabe/tests/repository/array_repository_test.rs +++ b/crates/shirabe/tests/repository/array_repository_test.rs @@ -127,12 +127,20 @@ fn test_search() { assert_eq!( vec![("foo".to_string(), None, Abandoned::No)], - reprs(&repo.search("foo".to_string(), SEARCH_FULLTEXT, None).unwrap()) + reprs( + &repo + .search("foo".to_string(), SEARCH_FULLTEXT, None) + .unwrap() + ) ); assert_eq!( vec![("bar".to_string(), None, Abandoned::No)], - reprs(&repo.search("bar".to_string(), SEARCH_FULLTEXT, None).unwrap()) + reprs( + &repo + .search("bar".to_string(), SEARCH_FULLTEXT, None) + .unwrap() + ) ); assert!( @@ -160,15 +168,23 @@ fn test_search_with_package_type() { vec![("foo".to_string(), None, Abandoned::No)], reprs( &repo - .search("foo".to_string(), SEARCH_FULLTEXT, Some("library".to_string())) + .search( + "foo".to_string(), + SEARCH_FULLTEXT, + Some("library".to_string()) + ) .unwrap() ) ); assert!( - repo.search("bar".to_string(), SEARCH_FULLTEXT, Some("package".to_string())) - .unwrap() - .is_empty() + repo.search( + "bar".to_string(), + SEARCH_FULLTEXT, + Some("package".to_string()) + ) + .unwrap() + .is_empty() ); assert_eq!( @@ -197,8 +213,16 @@ fn test_search_with_abandoned_packages() { assert_eq!( vec![ ("foo1".to_string(), None, Abandoned::Yes), - ("foo2".to_string(), None, Abandoned::Replacement("bar".to_string())), + ( + "foo2".to_string(), + None, + Abandoned::Replacement("bar".to_string()) + ), ], - reprs(&repo.search("foo".to_string(), SEARCH_FULLTEXT, None).unwrap()) + reprs( + &repo + .search("foo".to_string(), SEARCH_FULLTEXT, None) + .unwrap() + ) ); } diff --git a/crates/shirabe/tests/repository/composite_repository_test.rs b/crates/shirabe/tests/repository/composite_repository_test.rs index d09eddf..e21ac65 100644 --- a/crates/shirabe/tests/repository/composite_repository_test.rs +++ b/crates/shirabe/tests/repository/composite_repository_test.rs @@ -100,8 +100,7 @@ fn test_get_packages() { #[test] fn test_add_repository() { - let mut repo = - CompositeRepository::new(vec![array_repo(vec![get_package("foo", "1")])]); + let mut repo = CompositeRepository::new(vec![array_repo(vec![get_package("foo", "1")])]); assert_eq!(1, repo.count().unwrap()); repo.add_repository(array_repo(vec![ @@ -127,6 +126,10 @@ fn test_no_repositories() { let mut repo = CompositeRepository::new(vec![]); assert!(repo.find_packages("foo", None).unwrap().is_empty()); - assert!(repo.search("foo".to_string(), SEARCH_FULLTEXT, None).unwrap().is_empty()); + assert!( + repo.search("foo".to_string(), SEARCH_FULLTEXT, None) + .unwrap() + .is_empty() + ); assert!(repo.get_packages().unwrap().is_empty()); } diff --git a/crates/shirabe/tests/repository/installed_repository_test.rs b/crates/shirabe/tests/repository/installed_repository_test.rs index 510923a..b2c88a6 100644 --- a/crates/shirabe/tests/repository/installed_repository_test.rs +++ b/crates/shirabe/tests/repository/installed_repository_test.rs @@ -1 +1,86 @@ //! ref: composer/tests/Composer/Test/Repository/InstalledRepositoryTest.php + +use indexmap::IndexMap; +use shirabe::package::handle::PackageInterfaceHandle; +use shirabe::package::loader::array_loader::ArrayLoader; +use shirabe::repository::{ + ArrayRepository, FindPackageConstraint, InstalledArrayRepository, InstalledRepository, + RepositoryInterfaceHandle, +}; +use shirabe_php_shim::PhpMixed; + +use crate::test_case::get_package; + +/// PHP `setReplaces`/`setProvides` operate on non-root packages; the public handle API only allows +/// link setters on root packages, so packages carrying links are built via ArrayLoader. +fn loaded(name: &str, version: &str, extra: Vec<(&str, PhpMixed)>) -> PackageInterfaceHandle { + let mut config: IndexMap<String, PhpMixed> = IndexMap::new(); + config.insert("name".to_string(), PhpMixed::String(name.to_string())); + config.insert("version".to_string(), PhpMixed::String(version.to_string())); + for (key, value) in extra { + config.insert(key.to_string(), value); + } + + ArrayLoader::new(None, false) + .load_packages(vec![config]) + .unwrap() + .remove(0) +} + +fn provided_link() -> PhpMixed { + let mut links: IndexMap<String, PhpMixed> = IndexMap::new(); + links.insert("provided".to_string(), PhpMixed::String("*".to_string())); + PhpMixed::Array(links) +} + +#[test] +#[ignore = "InstalledRepository::add_repository asserts on a fixed set of repo types that omits InstalledRepositoryInterface, so adding an InstalledArrayRepository panics"] +fn test_find_packages_with_replacers_and_providers() { + let foo = loaded("foo", "1", vec![("replace", provided_link())]); + let foo2 = get_package("foo", "2"); + let array_repo_one = + InstalledArrayRepository::new_with_packages(vec![foo.clone(), foo2.clone()]).unwrap(); + + let bar = get_package("bar", "1"); + let bar2 = loaded("bar", "2", vec![("provide", provided_link())]); + let array_repo_two = + InstalledArrayRepository::new_with_packages(vec![bar.clone(), bar2.clone()]).unwrap(); + + let repo = InstalledRepository::new(vec![ + RepositoryInterfaceHandle::new(array_repo_one), + RepositoryInterfaceHandle::new(array_repo_two), + ]); + + let foo_matches = repo + .find_packages_with_replacers_and_providers( + "foo", + Some(FindPackageConstraint::String("2".to_string())), + ) + .unwrap(); + assert_eq!(1, foo_matches.len()); + assert!(foo_matches[0].ptr_eq(&foo2)); + + let bar_matches = repo + .find_packages_with_replacers_and_providers( + "bar", + Some(FindPackageConstraint::String("1".to_string())), + ) + .unwrap(); + assert_eq!(1, bar_matches.len()); + assert!(bar_matches[0].ptr_eq(&bar)); + + let provided_matches = repo + .find_packages_with_replacers_and_providers("provided", None) + .unwrap(); + assert_eq!(2, provided_matches.len()); + assert!(provided_matches[0].ptr_eq(&foo)); + assert!(provided_matches[1].ptr_eq(&bar2)); +} + +#[test] +#[should_panic] +fn test_add_repository() { + let array_repo_one = RepositoryInterfaceHandle::new(ArrayRepository::new(vec![]).unwrap()); + + InstalledRepository::new(vec![array_repo_one]); +} diff --git a/crates/shirabe/tests/repository/main.rs b/crates/shirabe/tests/repository/main.rs index 0873189..d1ad6dc 100644 --- a/crates/shirabe/tests/repository/main.rs +++ b/crates/shirabe/tests/repository/main.rs @@ -3,3 +3,4 @@ mod test_case; mod array_repository_test; mod composite_repository_test; +mod installed_repository_test; diff --git a/crates/shirabe/tests/util/http/request_proxy_test.rs b/crates/shirabe/tests/util/http/request_proxy_test.rs index 3674396..502ec31 100644 --- a/crates/shirabe/tests/util/http/request_proxy_test.rs +++ b/crates/shirabe/tests/util/http/request_proxy_test.rs @@ -64,7 +64,11 @@ fn test_get_status() { let cases: Vec<(Option<&str>, Option<&str>, &str)> = vec![ (None, Some(format), ""), (Some("http://proxy.com:80"), None, "http://proxy.com:80"), - (Some("http://proxy.com:80"), Some(format), "proxy (http://proxy.com:80)"), + ( + Some("http://proxy.com:80"), + Some(format), + "proxy (http://proxy.com:80)", + ), ]; for (url, format, expected) in cases { @@ -92,7 +96,10 @@ fn test_get_curl_options() { Some("http://proxy.com:80"), None, curl_options(&[ - (CURLOPT_PROXY, PhpMixed::String("http://proxy.com:80".to_string())), + ( + CURLOPT_PROXY, + PhpMixed::String("http://proxy.com:80".to_string()), + ), (CURLOPT_NOPROXY, PhpMixed::String(String::new())), ]), ), @@ -100,10 +107,16 @@ fn test_get_curl_options() { Some("http://proxy.com:80"), Some("user:p%40ss"), curl_options(&[ - (CURLOPT_PROXY, PhpMixed::String("http://proxy.com:80".to_string())), + ( + CURLOPT_PROXY, + PhpMixed::String("http://proxy.com:80".to_string()), + ), (CURLOPT_NOPROXY, PhpMixed::String(String::new())), (CURLOPT_PROXYAUTH, PhpMixed::Int(CURLAUTH_BASIC)), - (CURLOPT_PROXYUSERPWD, PhpMixed::String("user:p%40ss".to_string())), + ( + CURLOPT_PROXYUSERPWD, + PhpMixed::String("user:p%40ss".to_string()), + ), ]), ), ]; @@ -118,20 +131,34 @@ fn test_get_curl_options() { #[ignore = "secure proxies require curl_version, which is a todo!() in the php-shim"] fn test_get_curl_options_with_ssl() { let mut cafile_opts: IndexMap<String, PhpMixed> = IndexMap::new(); - cafile_opts.insert("cafile".to_string(), PhpMixed::String("/certs/bundle.pem".to_string())); + cafile_opts.insert( + "cafile".to_string(), + PhpMixed::String("/certs/bundle.pem".to_string()), + ); let mut capath_opts: IndexMap<String, PhpMixed> = IndexMap::new(); capath_opts.insert("capath".to_string(), PhpMixed::String("/certs".to_string())); - let cases: Vec<(&str, Option<&str>, IndexMap<String, PhpMixed>, IndexMap<i64, PhpMixed>)> = vec![ + let cases: Vec<( + &str, + Option<&str>, + IndexMap<String, PhpMixed>, + IndexMap<i64, PhpMixed>, + )> = vec![ ( "https://proxy.com:443", None, cafile_opts, curl_options(&[ - (CURLOPT_PROXY, PhpMixed::String("https://proxy.com:443".to_string())), + ( + CURLOPT_PROXY, + PhpMixed::String("https://proxy.com:443".to_string()), + ), (CURLOPT_NOPROXY, PhpMixed::String(String::new())), - (CURLOPT_PROXY_CAINFO, PhpMixed::String("/certs/bundle.pem".to_string())), + ( + CURLOPT_PROXY_CAINFO, + PhpMixed::String("/certs/bundle.pem".to_string()), + ), ]), ), ( @@ -139,10 +166,16 @@ fn test_get_curl_options_with_ssl() { Some("user:p%40ss"), capath_opts, curl_options(&[ - (CURLOPT_PROXY, PhpMixed::String("https://proxy.com:443".to_string())), + ( + CURLOPT_PROXY, + PhpMixed::String("https://proxy.com:443".to_string()), + ), (CURLOPT_NOPROXY, PhpMixed::String(String::new())), (CURLOPT_PROXYAUTH, PhpMixed::Int(CURLAUTH_BASIC)), - (CURLOPT_PROXYUSERPWD, PhpMixed::String("user:p%40ss".to_string())), + ( + CURLOPT_PROXYUSERPWD, + PhpMixed::String("user:p%40ss".to_string()), + ), (CURLOPT_PROXY_CAPATH, PhpMixed::String("/certs".to_string())), ]), ), diff --git a/crates/shirabe/tests/util/package_sorter_test.rs b/crates/shirabe/tests/util/package_sorter_test.rs index 41770e0..1b95824 100644 --- a/crates/shirabe/tests/util/package_sorter_test.rs +++ b/crates/shirabe/tests/util/package_sorter_test.rs @@ -47,8 +47,11 @@ fn test_sorting_does_nothing_with_no_dependencies() { assert_eq!(expected, names(&sorted_packages)); } -fn sorting_orders_dependencies_higher_than_package_cases() --> Vec<(Vec<PackageInterfaceHandle>, Vec<&'static str>, IndexMap<String, i64>)> { +fn sorting_orders_dependencies_higher_than_package_cases() -> Vec<( + Vec<PackageInterfaceHandle>, + Vec<&'static str>, + IndexMap<String, i64>, +)> { vec![ // one package is dep ( diff --git a/crates/shirabe/tests/util/zip_test.rs b/crates/shirabe/tests/util/zip_test.rs index 07f5629..b80dd17 100644 --- a/crates/shirabe/tests/util/zip_test.rs +++ b/crates/shirabe/tests/util/zip_test.rs @@ -50,7 +50,10 @@ fn test_throws_exception_if_the_composer_json_is_in_a_sub_subfolder() { fn test_returns_composer_json_in_zip_root() { let result = Zip::get_composer_json(&fixture("root.zip")).unwrap(); - assert_eq!(Some("{\n \"name\": \"foo/bar\"\n}\n".to_string()), result); + assert_eq!( + Some("{\n \"name\": \"foo/bar\"\n}\n".to_string()), + result + ); } #[test] @@ -58,7 +61,10 @@ fn test_returns_composer_json_in_zip_root() { fn test_returns_composer_json_in_first_folder() { let result = Zip::get_composer_json(&fixture("folder.zip")).unwrap(); - assert_eq!(Some("{\n \"name\": \"foo/bar\"\n}\n".to_string()), result); + assert_eq!( + Some("{\n \"name\": \"foo/bar\"\n}\n".to_string()), + result + ); } #[test] @@ -72,5 +78,8 @@ fn test_multiple_top_level_dirs_is_invalid() { fn test_returns_composer_json_from_first_subfolder() { let result = Zip::get_composer_json(&fixture("single-sub.zip")).unwrap(); - assert_eq!(Some("{\n \"name\": \"foo/bar\"\n}\n".to_string()), result); + assert_eq!( + Some("{\n \"name\": \"foo/bar\"\n}\n".to_string()), + result + ); } |
