diff options
Diffstat (limited to 'crates/shirabe/src')
| -rw-r--r-- | crates/shirabe/src/repository/vcs/github_driver.rs | 12 | ||||
| -rw-r--r-- | crates/shirabe/src/repository/vcs/gitlab_driver.rs | 12 | ||||
| -rw-r--r-- | crates/shirabe/src/util/git.rs | 29 | ||||
| -rw-r--r-- | crates/shirabe/src/util/http/response.rs | 2 | ||||
| -rw-r--r-- | crates/shirabe/src/util/http_downloader.rs | 24 | ||||
| -rw-r--r-- | crates/shirabe/src/util/url.rs | 4 |
6 files changed, 80 insertions, 3 deletions
diff --git a/crates/shirabe/src/repository/vcs/github_driver.rs b/crates/shirabe/src/repository/vcs/github_driver.rs index bea7294..7c50a7e 100644 --- a/crates/shirabe/src/repository/vcs/github_driver.rs +++ b/crates/shirabe/src/repository/vcs/github_driver.rs @@ -1298,6 +1298,18 @@ impl GitHubDriver { None } + + /// For testing only. Mirrors the `setAttribute($driver, 'tags', ...)` reflection + /// helper used by GitHubDriverTest to seed private state. + pub fn __set_tags(&mut self, tags: Option<IndexMap<String, String>>) { + self.tags = tags; + } + + /// For testing only. Mirrors the `setAttribute($driver, 'branches', ...)` reflection + /// helper used by GitHubDriverTest to seed private state. + pub fn __set_branches(&mut self, branches: Option<IndexMap<String, String>>) { + self.branches = branches; + } } impl crate::repository::vcs::VcsDriverInterface for GitHubDriver { diff --git a/crates/shirabe/src/repository/vcs/gitlab_driver.rs b/crates/shirabe/src/repository/vcs/gitlab_driver.rs index f1f361e..7e8073d 100644 --- a/crates/shirabe/src/repository/vcs/gitlab_driver.rs +++ b/crates/shirabe/src/repository/vcs/gitlab_driver.rs @@ -238,6 +238,18 @@ impl GitLabDriver { Ok(()) } + /// For testing only. Mirrors the `setAttribute($driver, 'branches', ...)` reflection + /// helper used by GitLabDriverTest to seed private state. + pub fn __set_branches(&mut self, branches: Option<IndexMap<String, String>>) { + self.branches = branches; + } + + /// For testing only. Mirrors the `setAttribute($driver, 'tags', ...)` reflection + /// helper used by GitLabDriverTest to seed private state. + pub fn __set_tags(&mut self, tags: Option<IndexMap<String, String>>) { + self.tags = tags; + } + /// Updates the HttpDownloader instance. /// Mainly useful for tests. /// diff --git a/crates/shirabe/src/util/git.rs b/crates/shirabe/src/util/git.rs index f031157..142d5e2 100644 --- a/crates/shirabe/src/util/git.rs +++ b/crates/shirabe/src/util/git.rs @@ -132,6 +132,19 @@ impl Git { self.run_command(callables, url, cwd, initial_clone, command_output) } + /// For testing only. Public seam over the (deprecated) private `run_command`, + /// mirroring `Git::runCommand` as exercised by `GitTest`. + pub fn __run_command( + &mut self, + command_callable: Vec<Box<dyn Fn(&str) -> Vec<String>>>, + url: &str, + cwd: Option<&str>, + initial_clone: bool, + command_output: Option<&mut PhpMixed>, + ) -> Result<()> { + self.run_command(command_callable, url, cwd, initial_clone, command_output) + } + /// @param callable|array<callable> $commandCallable /// @param mixed $commandOutput the output will be written into this var if passed by ref /// if a callable is passed it will be used as output handler @@ -1310,6 +1323,22 @@ impl Git { version.clone().unwrap_or(None) } + /// For testing only. Resets the cached git `version` static so the next + /// `get_version` call re-runs `git --version`, mirroring the + /// `ReflectionProperty(GitUtil::class, 'version')->setValue(null, false)` + /// done in VersionGuesserTest's setUp/tearDown. + pub fn __reset_version() { + *VERSION.lock().unwrap() = None; + } + + /// For testing only. Seeds the cached git `version` static, mirroring the + /// `ReflectionProperty(GitUtil::class, 'version')->setValue(null, $version)` + /// done in GitDownloaderTest's `initGitVersion`. `Some(v)` records a detected + /// version; `None` records that git is unavailable, both without shelling out. + pub fn __set_version(version: Option<String>) { + *VERSION.lock().unwrap() = Some(version); + } + /// @param string[] $credentials fn mask_credentials(&self, error: &str, credentials: &[String]) -> String { let mut masked_credentials: Vec<String> = vec![]; diff --git a/crates/shirabe/src/util/http/response.rs b/crates/shirabe/src/util/http/response.rs index e1da15d..8b7bd34 100644 --- a/crates/shirabe/src/util/http/response.rs +++ b/crates/shirabe/src/util/http/response.rs @@ -63,7 +63,7 @@ impl Response { pub fn find_header_value(headers: &[String], name: &str) -> Option<String> { let mut value = None; - let pattern = format!("(?i)^{}:\\s*(.+?)\\s*$", preg_quote(name, None)); + let pattern = format!("{{^{}:\\s*(.+?)\\s*$}}i", preg_quote(name, None)); for header in headers { let mut matches: indexmap::IndexMap< shirabe_external_packages::composer::pcre::CaptureKey, diff --git a/crates/shirabe/src/util/http_downloader.rs b/crates/shirabe/src/util/http_downloader.rs index edc84cc..782f04a 100644 --- a/crates/shirabe/src/util/http_downloader.rs +++ b/crates/shirabe/src/util/http_downloader.rs @@ -883,6 +883,30 @@ impl HttpDownloader { && function_exists("curl_multi_init") } + /// For testing only. Builds an HttpDownloader whose request methods are fully + /// short-circuited by the mock (see [`HttpDownloader::__expects`]), without + /// constructing the real curl/rfs backends. Mirrors HttpDownloaderMock, which + /// extends HttpDownloader but never performs curl I/O. + pub fn __new_mock( + io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, + config: std::rc::Rc<std::cell::RefCell<Config>>, + ) -> Self { + Self { + io, + config, + jobs: IndexMap::new(), + options: IndexMap::new(), + running_jobs: 0, + max_jobs: 12, + curl: None, + rfs: None, + id_gen: 0, + disabled: false, + allow_async: false, + mock: None, + } + } + /// For testing only. Mirrors HttpDownloaderMock::expects: installs the expectation queue, /// strict flag and default handler used by the mock request path. pub fn __expects( diff --git a/crates/shirabe/src/util/url.rs b/crates/shirabe/src/util/url.rs index 534e318..5820539 100644 --- a/crates/shirabe/src/util/url.rs +++ b/crates/shirabe/src/util/url.rs @@ -164,10 +164,10 @@ impl Url { pub fn sanitize(url: String) -> String { // GitHub repository rename result in redirect locations containing the access_token as GET parameter // e.g. https://api.github.com/repositories/9999999999?access_token=github_token - let url = Preg::replace(r"([&?]access_token=)[^&]+", "$1***", &url); + let url = Preg::replace(r"{([&?]access_token=)[^&]+}", "$1***", &url); Preg::replace_callback( - r"(?i)^(?P<prefix>[a-z0-9]+://)?(?P<user>[^:/\s@]+):(?P<password>[^@\s/]+)@", + r"{^(?P<prefix>[a-z0-9]+://)?(?P<user>[^:/\s@]+):(?P<password>[^@\s/]+)@}i", |m| { let user = m .get(&CaptureKey::ByName("user".to_string())) |
