Stop hardcoding port

This commit is contained in:
2026-08-04 16:06:20 -03:00
parent 2cdd8c11a3
commit 6f7da8908b
6 changed files with 200 additions and 141 deletions
+31 -32
View File
@@ -24,47 +24,46 @@ class GiteaRemoteUrlTests(unittest.TestCase):
def setUp(self) -> None:
self.app = git_tui.GitTuiApp.__new__(git_tui.GitTuiApp)
def test_resolves_ssh_url_from_https_base_url(self) -> None:
remote_url = self.app.resolve_gitea_remote_url(
"owner/project", "https://git.example.com", transport="ssh"
)
def test_exact_custom_ssh_clone_url_is_preserved(self) -> None:
expected_url = "ssh://forge@git.example.com:2222/owner/project.git"
self.app.prompt_input = lambda *_args: expected_url
self.assertEqual(remote_url, "git@git.example.com:owner/project.git")
remote_url = self.app.prompt_gitea_existing_remote_url()
def test_resolves_custom_ssh_user_and_port(self) -> None:
remote_url = self.app.resolve_gitea_remote_url(
"owner/project",
"https://git.example.com/gitea",
transport="ssh",
ssh_user="forge",
ssh_port="2222",
)
self.assertEqual(remote_url, expected_url)
def test_api_resolution_uses_giteas_advertised_ssh_url(self) -> None:
self.app.prompt_secret = lambda *_args: "token"
self.app.select_gitea_transport = lambda: "ssh"
requested_urls = []
def fake_get(url: str, token: str):
requested_urls.append((url, token))
return 200, "", {
"ssh_url": "ssh://forge@ssh.example.com:2222/owner/project.git",
"clone_url": "https://git.example.com/owner/project.git",
}
self.app.gitea_get_json = fake_get
with mock.patch.dict(
os.environ,
{"GITEA_TOKEN": "", "GITEA_ACCESS_TOKEN": ""},
clear=False,
):
remote_url = self.app.resolve_existing_gitea_url_via_api(
"owner/project", "https://git.example.com"
)
self.assertEqual(
remote_url,
"ssh://forge@git.example.com:2222/owner/project.git",
"ssh://forge@ssh.example.com:2222/owner/project.git",
)
def test_still_supports_https(self) -> None:
remote_url = self.app.resolve_gitea_remote_url(
"owner/project", "https://git.example.com", transport="https"
)
self.assertEqual(
remote_url,
"https://git.example.com/owner/project.git",
requested_urls,
[("https://git.example.com/api/v1/repos/owner/project", "token")],
)
def test_rejects_invalid_ssh_port(self) -> None:
remote_url = self.app.resolve_gitea_remote_url(
"owner/project",
"https://git.example.com",
transport="ssh",
ssh_port="not-a-port",
)
self.assertEqual(remote_url, "")
class RepositorySyncTests(unittest.TestCase):
def setUp(self) -> None: