test: add vcs.git URL parsing unit tests
This commit is contained in:
parent
f6283456bb
commit
297b7c49d0
1 changed files with 56 additions and 0 deletions
56
tests/unit/byteb4rb1e/utils/vcs/test_git.py
Normal file
56
tests/unit/byteb4rb1e/utils/vcs/test_git.py
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
"""Tests for the git subprocess wrapper's URL parsing helpers."""
|
||||
|
||||
import pytest
|
||||
|
||||
from byteb4rb1e.utils.vcs.git import parse_base_url, parse_repo_name
|
||||
|
||||
|
||||
class TestParseBaseUrl:
|
||||
|
||||
def test_bitbucket(self) -> None:
|
||||
result = parse_base_url("git@bitbucket.org:byteb4rb1e/foo.git")
|
||||
assert str(result) == "byteb4rb1e"
|
||||
|
||||
def test_forgejo_host(self) -> None:
|
||||
result = parse_base_url(
|
||||
"git@git.code.tiararodney.com:h5p-mirror/foo.git"
|
||||
)
|
||||
assert str(result) == "h5p-mirror"
|
||||
|
||||
def test_github_host(self) -> None:
|
||||
result = parse_base_url("git@github.com:h5p/h5p-multi-choice.git")
|
||||
assert str(result) == "h5p"
|
||||
|
||||
def test_rejects_https_url(self) -> None:
|
||||
with pytest.raises(ValueError):
|
||||
parse_base_url("https://bitbucket.org/byteb4rb1e/foo.git")
|
||||
|
||||
def test_rejects_url_without_colon(self) -> None:
|
||||
with pytest.raises(ValueError):
|
||||
parse_base_url("bitbucket.org/byteb4rb1e/foo.git")
|
||||
|
||||
|
||||
class TestParseRepoName:
|
||||
|
||||
def test_bitbucket(self) -> None:
|
||||
assert parse_repo_name(
|
||||
"git@bitbucket.org:byteb4rb1e/foo.git"
|
||||
) == "foo"
|
||||
|
||||
def test_forgejo_host(self) -> None:
|
||||
assert parse_repo_name(
|
||||
"git@git.code.tiararodney.com:h5p-mirror/foo.git"
|
||||
) == "foo"
|
||||
|
||||
def test_without_git_suffix(self) -> None:
|
||||
assert parse_repo_name(
|
||||
"git@git.code.tiararodney.com:h5p-mirror/foo"
|
||||
) == "foo"
|
||||
|
||||
def test_rejects_https_url(self) -> None:
|
||||
with pytest.raises(ValueError):
|
||||
parse_repo_name("https://git.code.tiararodney.com/x/foo.git")
|
||||
|
||||
def test_rejects_url_without_colon(self) -> None:
|
||||
with pytest.raises(ValueError):
|
||||
parse_repo_name("git.code.tiararodney.com/x/foo.git")
|
||||
Loading…
Add table
Add a link
Reference in a new issue