|
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( |
| 21 | + url, is_explicit=True |
| 22 | + ) # Should not be valid in explicit mode |
| 23 | + |
| 24 | + # Now enable the detection |
| 25 | + enable_ssh_style_url_detection() |
| 26 | + |
| 27 | + # With the patch, SSH-style URLs should be detected as explicit |
| 28 | + assert GitURL.is_valid(url) # Should still be valid in non-explicit mode |
| 29 | + assert GitURL.is_valid( |
| 30 | + url, is_explicit=True |
| 31 | + ) # Should now be valid in explicit mode |
| 32 | + |
| 33 | + # Verify the rule used |
| 34 | + git_url = GitURL(url) |
| 35 | + assert git_url.rule == "core-git-scp" |
| 36 | + |
| 37 | + # Re-enable for other tests |
| 38 | + enable_ssh_style_url_detection() |
| 39 | + |
8 | 40 |
|
9 | 41 | @pytest.mark.parametrize(
|
10 | 42 | "url",
|
|
17 | 49 | )
|
18 | 50 | def test_ssh_style_url_detection(url: str) -> None:
|
19 | 51 | """Test that SSH-style URLs are correctly detected."""
|
| 52 | + # Ensure detection is enabled |
| 53 | + enable_ssh_style_url_detection() |
| 54 | + |
20 | 55 | assert GitURL.is_valid(url)
|
| 56 | + assert GitURL.is_valid(url, is_explicit=True) # Should be valid in explicit mode |
21 | 57 | git_url = GitURL(url)
|
22 | 58 | assert git_url.rule == "core-git-scp"
|
23 | 59 |
|
@@ -55,6 +91,9 @@ def test_ssh_style_url_parsing(
|
55 | 91 | url: str, expected_user: str, expected_hostname: str, expected_path: str
|
56 | 92 | ) -> None:
|
57 | 93 | """Test that SSH-style URLs are correctly parsed."""
|
| 94 | + # Ensure detection is enabled |
| 95 | + enable_ssh_style_url_detection() |
| 96 | + |
58 | 97 | git_url = GitURL(url)
|
59 | 98 | assert git_url.user == expected_user
|
60 | 99 | assert git_url.hostname == expected_hostname
|
|
0 commit comments