|
| 1 | +"""Tests for URL handling in vcspull.""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +import pytest |
| 6 | +from libvcs.url.git import GitURL |
| 7 | + |
| 8 | + |
| 9 | +@pytest.mark.parametrize( |
| 10 | + "url", |
| 11 | + [ |
| 12 | + |
| 13 | + "[email protected]:vcs-python/vcspull.git", |
| 14 | + "[email protected]:vcs-python/vcspull.git", |
| 15 | + "[email protected]:path/to/repo.git", |
| 16 | + ], |
| 17 | +) |
| 18 | +def test_ssh_style_url_detection(url: str) -> None: |
| 19 | + """Test that SSH-style URLs are correctly detected.""" |
| 20 | + assert GitURL.is_valid(url) |
| 21 | + git_url = GitURL(url) |
| 22 | + assert git_url.rule == "core-git-scp" |
| 23 | + |
| 24 | + |
| 25 | +@pytest.mark.parametrize( |
| 26 | + "url,expected_user,expected_hostname,expected_path", |
| 27 | + [ |
| 28 | + ( |
| 29 | + |
| 30 | + "user", |
| 31 | + "myhostname.de", |
| 32 | + "org/repo", |
| 33 | + ), |
| 34 | + ( |
| 35 | + "[email protected]:vcs-python/vcspull.git", |
| 36 | + "git", |
| 37 | + "github.com", |
| 38 | + "vcs-python/vcspull", |
| 39 | + ), |
| 40 | + ( |
| 41 | + "[email protected]:vcs-python/vcspull.git", |
| 42 | + "git", |
| 43 | + "gitlab.com", |
| 44 | + "vcs-python/vcspull", |
| 45 | + ), |
| 46 | + ( |
| 47 | + "[email protected]:path/to/repo.git", |
| 48 | + "user", |
| 49 | + "custom-host.com", |
| 50 | + "path/to/repo", |
| 51 | + ), |
| 52 | + ], |
| 53 | +) |
| 54 | +def test_ssh_style_url_parsing( |
| 55 | + url: str, expected_user: str, expected_hostname: str, expected_path: str |
| 56 | +) -> None: |
| 57 | + """Test that SSH-style URLs are correctly parsed.""" |
| 58 | + git_url = GitURL(url) |
| 59 | + assert git_url.user == expected_user |
| 60 | + assert git_url.hostname == expected_hostname |
| 61 | + assert git_url.path == expected_path |
| 62 | + assert git_url.suffix == ".git" |
0 commit comments