diff --git a/tests/int_gitea_clone_url_base.rs b/tests/int_gitea_clone_url_base.rs index 80e959e..6ae968e 100644 --- a/tests/int_gitea_clone_url_base.rs +++ b/tests/int_gitea_clone_url_base.rs @@ -2,19 +2,21 @@ // // Integration test: verify that --clone-url-base rewrites clone URLs // returned by the Gitea API during repository enumeration. +// +// Uses wiremock to mock the Gitea API and assert_cmd to exercise the full +// CLI path: argument parsing → API enumeration → URL rewriting → output. -use anyhow::Result; -use kingfisher::gitea::{self, RepoSpecifiers, RepoType}; -use url::Url; +use assert_cmd::Command; +use predicates::str::contains; use wiremock::{ matchers::{method, path, query_param}, Mock, MockServer, ResponseTemplate, }; -/// Mock a Gitea API that returns repos with clone URLs on one host, -/// then verify that enumerate_repo_urls rewrites them to a different host. +/// Run `kingfisher scan gitea --list-only` against a mock Gitea API with and +/// without --clone-url-base, verifying that clone URLs are rewritten. #[tokio::test] -async fn clone_url_base_rewrites_enumerated_urls() -> Result<()> { +async fn clone_url_base_rewrites_listed_urls() { let mock_server = MockServer::start().await; let public_host = "https://forge.public.example.com"; @@ -40,42 +42,43 @@ async fn clone_url_base_rewrites_enumerated_urls() -> Result<()> { .mount(&mock_server) .await; - let api_url = Url::parse(&format!("{}/api/v1/", mock_server.uri()))?; - let clone_base = Url::parse("https://forge.internal.example.com/")?; + let api_url = format!("{}/api/v1/", mock_server.uri()); - let specifiers = RepoSpecifiers { - user: vec!["eblume".into()], - organization: vec![], - all_organizations: false, - repo_filter: RepoType::All, - exclude_repos: vec![], - }; + // WITH --clone-url-base: URLs should be rewritten. + Command::new(assert_cmd::cargo::cargo_bin!("kingfisher")) + .args([ + "scan", + "gitea", + "--api-url", + &api_url, + "--clone-url-base", + "https://forge.internal.example.com/", + "--user", + "eblume", + "--list-only", + "--no-update-check", + "--quiet", + ]) + .assert() + .success() + .stdout(contains("https://forge.internal.example.com/eblume/kingfisher.git")); - // Call WITH clone_url_base — URLs should be rewritten. - let urls = gitea::enumerate_repo_urls( - &specifiers, - api_url.clone(), - Some(&clone_base), - false, - None, - ) - .await?; - - assert_eq!(urls.len(), 1); - assert_eq!( - urls[0], - "https://forge.internal.example.com/eblume/kingfisher.git" - ); - - // Call WITHOUT clone_url_base — URLs should be unchanged. - let urls_no_rewrite = - gitea::enumerate_repo_urls(&specifiers, api_url, None, false, None).await?; - - assert_eq!(urls_no_rewrite.len(), 1); - assert_eq!( - urls_no_rewrite[0], - format!("{public_host}/eblume/kingfisher.git") - ); - - Ok(()) + // WITHOUT --clone-url-base: URLs should be unchanged. + Command::new(assert_cmd::cargo::cargo_bin!("kingfisher")) + .args([ + "scan", + "gitea", + "--api-url", + &api_url, + "--user", + "eblume", + "--list-only", + "--no-update-check", + "--quiet", + ]) + .assert() + .success() + .stdout(contains(&format!( + "{public_host}/eblume/kingfisher.git" + ))); }