|
5 | 5 | import pytest
|
6 | 6 | from libvcs.url.git import GitURL
|
7 | 7 |
|
| 8 | +from vcspull.url import disable_ssh_style_url_detection, enable_ssh_style_url_detection |
| 9 | + |
| 10 | + |
| 11 | +def test_ssh_style_url_detection_toggle() -> None: |
| 12 | + """Test that SSH-style URL detection can be toggled on and off.""" |
| 13 | + url = "[email protected]:org/repo.git" |
| 14 | + |
| 15 | + # First, disable the detection |
| 16 | + disable_ssh_style_url_detection() |
| 17 | + |
| 18 | + # Without the patch, SSH-style URLs should not be detected as explicit |
| 19 | + assert GitURL.is_valid(url) # Should be valid in non-explicit mode |
| 20 | + assert not GitURL.is_valid(url, is_explicit=True) # Should not be valid in explicit mode |
| 21 | + |
| 22 | + # Now enable the detection |
| 23 | + enable_ssh_style_url_detection() |
| 24 | + |
| 25 | + # With the patch, SSH-style URLs should be detected as explicit |
| 26 | + assert GitURL.is_valid(url) # Should still be valid in non-explicit mode |
| 27 | + assert GitURL.is_valid(url, is_explicit=True) # Should now be valid in explicit mode |
| 28 | + |
| 29 | + # Verify the rule used |
| 30 | + git_url = GitURL(url) |
| 31 | + assert git_url.rule == "core-git-scp" |
| 32 | + |
| 33 | + # Re-enable for other tests |
| 34 | + enable_ssh_style_url_detection() |
| 35 | + |
8 | 36 |
|
9 | 37 | @pytest.mark.parametrize(
|
10 | 38 | "url",
|
|
17 | 45 | )
|
18 | 46 | def test_ssh_style_url_detection(url: str) -> None:
|
19 | 47 | """Test that SSH-style URLs are correctly detected."""
|
| 48 | + # Ensure detection is enabled |
| 49 | + enable_ssh_style_url_detection() |
| 50 | + |
20 | 51 | assert GitURL.is_valid(url)
|
| 52 | + assert GitURL.is_valid(url, is_explicit=True) # Should be valid in explicit mode |
21 | 53 | git_url = GitURL(url)
|
22 | 54 | assert git_url.rule == "core-git-scp"
|
23 | 55 |
|
@@ -55,6 +87,9 @@ def test_ssh_style_url_parsing(
|
55 | 87 | url: str, expected_user: str, expected_hostname: str, expected_path: str
|
56 | 88 | ) -> None:
|
57 | 89 | """Test that SSH-style URLs are correctly parsed."""
|
| 90 | + # Ensure detection is enabled |
| 91 | + enable_ssh_style_url_detection() |
| 92 | + |
58 | 93 | git_url = GitURL(url)
|
59 | 94 | assert git_url.user == expected_user
|
60 | 95 | assert git_url.hostname == expected_hostname
|
|
0 commit comments