Some checks failed
CI / test-unit (push) Has been cancelled
CI / test-integration (push) Has been cancelled
CI / test-container (push) Has been cancelled
CI / test-e2e (push) Has been cancelled
CI / test-virgin-user (push) Has been cancelled
CI / test-virgin-root (push) Has been cancelled
- Switch MIRRORS to SSH-based URLs including custom ports/domains
(GitHub, git.veen.world, code.cymais.cloud)
- Extend mirror IO:
- load_config_mirrors filters empty values
- read_mirrors_file now supports:
* "name url" lines
* "url" lines with auto-generated names from URL host (host[:port])
- write_mirrors_file prints full preview content
- Enhance git_remote:
- determine_primary_remote_url used for origin bootstrap
- ensure_origin_remote keeps existing origin URL and
adds all mirror URLs as additional push URLs
- add is_remote_reachable() helper based on `git ls-remote --exit-code`
- Implement non-destructive remote mirror checks in setup_cmd:
- `_probe_mirror()` wraps `git ls-remote` and returns (ok, message)
- `pkgmgr mirror setup --remote` now probes each mirror URL and
prints [OK]/[WARN] with details instead of placeholder text
- Add unit tests for mirror actions:
- test_git_remote: default SSH URL building and primary URL selection
- test_io: config + MIRRORS parsing including auto-named URL-only entries
- test_setup_cmd: probe_mirror success/failure handling
https://chatgpt.com/share/693adee0-aa3c-800f-b72a-98473fdaf760
60 lines
1.6 KiB
Python
60 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from __future__ import annotations
|
|
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
from pkgmgr.actions.mirror.setup_cmd import _probe_mirror
|
|
from pkgmgr.core.git import GitError
|
|
|
|
|
|
class TestMirrorSetupCmd(unittest.TestCase):
|
|
"""
|
|
Unit tests for the non-destructive remote probing logic in setup_cmd.
|
|
"""
|
|
|
|
@patch("pkgmgr.actions.mirror.setup_cmd.run_git")
|
|
def test_probe_mirror_success_returns_true_and_empty_message(
|
|
self,
|
|
mock_run_git,
|
|
) -> None:
|
|
"""
|
|
If run_git returns successfully, _probe_mirror must report (True, "").
|
|
"""
|
|
mock_run_git.return_value = "dummy-output"
|
|
|
|
ok, message = _probe_mirror(
|
|
"ssh://git@code.cymais.cloud:2201/kevinveenbirkenbach/pkgmgr.git",
|
|
"/tmp/some-repo",
|
|
)
|
|
|
|
self.assertTrue(ok)
|
|
self.assertEqual(message, "")
|
|
mock_run_git.assert_called_once()
|
|
|
|
@patch("pkgmgr.actions.mirror.setup_cmd.run_git")
|
|
def test_probe_mirror_failure_returns_false_and_error_message(
|
|
self,
|
|
mock_run_git,
|
|
) -> None:
|
|
"""
|
|
If run_git raises GitError, _probe_mirror must report (False, <message>),
|
|
and not re-raise the exception.
|
|
"""
|
|
mock_run_git.side_effect = GitError("Git command failed (simulated)")
|
|
|
|
ok, message = _probe_mirror(
|
|
"ssh://git@code.cymais.cloud:2201/kevinveenbirkenbach/pkgmgr.git",
|
|
"/tmp/some-repo",
|
|
)
|
|
|
|
self.assertFalse(ok)
|
|
self.assertIn("Git command failed", message)
|
|
mock_run_git.assert_called_once()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|